Cutomer API
The Customer API is part of the core
service and thus all requests should go to https://api.subsbase.io/core/graphql
.
The core service expects 2 headers, the X-SITE-ID
and authorization
so the request would be:
POST https://api.subsbase.io/core/graphql
Authorization: Bearer {server token}
X-SITE-ID: {your site id}
Authorization
header
Queries
Customers Query
query GetCustomers($siteId: String!, $pagination: PaginationGQLInputType, $sorting: [SortingGQLInputType], $filter: [FilterGQLInputType])
{
customers(siteId: $siteId, pagination: $pagination, sorting: $sorting, filter: $filter) {
isSuccess
message
pagination {
page
perPage
totalRecords
}
data {
customerId
status
// all customer fields are available...
}
}
}
- Request Variables Sample:
const variables = {
siteId: "Your site ID",
pagination: {
page: 1,
perPage: 10,
},
sorting: [
{
field: "lastName",
direction: "Ascending",
},
],
filter: [
{
field: "firstName",
operator: "Contains",
value: "ahmed",
},
],
};
- Returns an array of customers
- You can specify any of the fields detailed in the Customer Type Definition
- For details about Pagination, Sorting and Filtering Input Types check out PaginationGQLInputType, SortingGQLInputType, FilteringGQLInputType
Customer Query
query GetCustomer($siteId: String!, $customerId: String!) {
customer(siteId: $siteId, customerId: $customerId) {
customerId
status
// all customer fields are available...
}
}
- Returns the specific customer
- You can specify any of the fields detailed in the Customer Type Definition
Mutations/Operations
Create Customer
To create a customer you need to use the following Mutation, it is advisable to use variables
in this case since the input types are more complex than just strings:
mutation CreateCustomer($siteId: String!, $customer: CustomerGQLInputType!) {
createCustomer(siteId: $siteId, customer: $customer) {
isSuccess
message
value
{
customerId
firstName
lastName
emailAddress
// all customer fields are available...
}
}
}
### variables
{
"customer": {
"customerId":null, //If null is used a customerId is auto-generated. Otherwise you can provide the customer Id you use on your side
"emailAddress": "email@email.com",
"firstName":"John",
"lastName": "Doe"
}
},
"siteId":"your_siteId"
}
- Returns a result with the new customer as it's value
{
"data": {
"createCustomer": {
"isSuccess": true,
"message": "",
"value": {
"customerId": "your_siteID_123",
"firstName": "john doe",
"lastName": "Doe",
"fullName": "John",
"emailAddress": "email@email.com"
}
}
}
}
Understanding customer variables
Variables | Type |
---|---|
emailAddress | string |
firstName | string |
lastName | string |
customerId | auto-generated (if not specified) |
Updating Customer InfoFields
This operation updates the infofields of an existing customer.
- Your
Request
would look like:
POST https://api.subsbase.io/core/graphql
Content-Type: application/json
x-site-id: {site-id}
Authorization: Bearer {Customer Token}
To update an existing customer data, you need to use the following Mutation, it is advisable to use variables
in this case since the input types are more complex than just strings:
mutation updateInfoFields(
$siteId: String!
$customerId: String!
$infoFields: [CustomerInfoFieldGQLInputType]!
) {
updateInfoFields(
siteId: $siteId
customerId: $customerId
infoFields: $infoFields
) {
isSuccess
message
}
}
You can use customer infoFields
from CustomerInfoFieldGQLInputType
Returns a result with a success message:
{
"data": {
"updateInfoFields": {
"isSuccess": true,
"message": ""
}
}
}
Request Customer to add payment method
This operation triggers sending an email to the client with a URL to update payment methods.
- Your
Request
would look like:
POST https://api.subsbase.io/checkout/graphql
Content-Type: application/json
x-site-id: {site-id}
Authorization: Bearer {Customer Token}
To update an existing customer data, you need to use the following Mutation:
mutation RequestCustomerPaymentMethodMutation(
$siteId: String!
$customerId: String!
) {
requestCustomerPaymentMethod(siteId: $siteId, customerId: $customerId) {
customerId
siteId
}
}
Returns a result with a success message:
{
"data": {
"requestCustomerPaymentMethod": {
"isSuccess": true,
"message": ""
}
}
}
Updating Customer ID
This operation updates the customer ID on SubsBase.
- Your
Request
would look like:
POST https://api.subsbase.io/core/graphql
Content-Type: application/json
x-site-id: {site-id}
Authorization: Bearer {Customer Token}
To update an existing customer data, you need to use the following Mutation:
mutation UpdateCustomerId(
$siteId: String!
$requesterId: String!
$customerId: String!
$newCustomerId: String!
) {
updateCustomerId(
siteId: $siteId
requesterId: $requesterId
customerId: $customerId
newCustomerId: $newCustomerId
) {
isSuccess
message
value
}
}
Returns a result with a success message:
{
"data": {
"updateCustomerId": {
"isSuccess": true,
"message": "",
"value": "{New_Value}"
}
}
}