Subcription API

The Subscription 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}
Consuming the customer API requires that a server token is used to authenticate the request. The server token is expected in the Authorization header

Mutations/Operations

Add Subscription to Customer

This operation assigns a selected plan to the customer, and notifies the customer to complete the checkout process.

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 plan, 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 AddSubscriptionMutation($siteId: String!, $customerId: String!, $planCode: String!, $requesterId: String!) {
    addSubscription(siteId: $siteId, customerId: $customerId, planCode: $planCode, requesterId: $requesterId) {
        isSuccess
        message
        value {
          needCustomization
          needPaymentMethod
          checkoutUrl
        }
    }
}
### variables
{
    "customer": {
        "customerId": "Required customerId"
        "planCode": "Use the planCode which you need to assign",
        "requesterId": "Specify requesterId",
        "siteId": "Use your siteId"
      }
}
  • Returns a result which looks like
{
  "data": {
    "addSubscription": {
      "isSuccess": true,
      "message": "",
      "value": {
        "needCustomization": "false",
        "needPaymentMethod": "true",
        "checkoutUrl": ""
      }
    }
  }
}

Cancel Subscription

This operation either cancels a subscription immediately, or at the end of the current billing cycle. You should have this subscription on an existing customer

To cancel an existing subscription, 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 CancelSubscription($siteId: String!, $planSubscriptionId: String!, $immediateCancellation: Boolean) {
    cancelSubscription(siteId: $siteId, planSubscriptionId: $planSubscriptionId, immediateCancellation: $immediateCancellation) {
        isSuccess
        message
        value
    }
}


### variables
{
    "siteId":"your_siteId",
    "planSubscriptionId":"your_plan_subscription_id",
    "immediateCancellation":""
}

Returns a result with a success message:

{
  "data": {
    "cancelSubscription": {
      "isSuccess": true,
      "message": ""
    }
  }
}

Understanding Subscription variables

VariablesType
siteIdstring
planSubscriptionIdstring (obtain from a previous customer query that includes subscriptions)
immediateCancellationBoolean, (optional) - if true cancels immediately, if false cancels end of billing cycle which is the default behaviour