Overview
You need to subscribe an account to a specific plan using the GraphQL API and looking for instructions on how to accomplish that.
Solution
In order to make the requests through the API, the information below is required. For further details on the API refer to Using the CCAB GraphQL API.
- The Provider ID.
- An Access Token using the credentials from an Account Admin.
To subscribe an account to a plan, one should use the subscribeToPlan operation. With this mutation, one can subscribe an account to an available plan version for a specific period time.
This requires passing some of the parameters mentioned in SubscribeToPlanVersionInput.
Below is an example payload using API version 10.1 with some specific details.
- The from/time parameters are not being used so the subscription will start right away and won't have a set end date.
- The payload will handle the different union types that can be returned from this request.
mutation subscribeToPlan{
subscribeToPlan(
input: {
accountId: "<accountId>",
planVersionId: "<planVersionId>",
providerId: "<providerId>"
}
) {
... on SubscribeToPlanVersionPayload {
__typename
account {
id
activePlanVersions {
planVersion {
id
createdAt
deployedAt
refCount
deployedBy
}
from
to
}
archivedPlanVersions {
from
to
planVersion {
id
createdAt
deployedAt
refCount
deployedBy
}
}
inactivePlanVersions {
from
to
planVersion {
id
refCount
deployedAt
deployedBy
createdAt
}
}
}
}
... on PlanVersionNotFound {
planVersionId
errorCode
errorMessage
}
... on PlanVersionIsNotAssignable {
planVersionId
errorCode
errorMessage
}
... on AccountNotFound {
accountId
errorCode
errorMessage
}
... on InvalidField {
fieldName
errorCode
errorMessage
}
... on SubscribeToPlanVersionValidationFailed {
errorCode
errorMessage
}
}
}
If the subscription completes, the response will contain the following account details. Note that the plan version is inside the inactive list as it was just subscribed.
On the other hand, if there are any problems such as trying to subscribe to a plan version that is not deployed/available, the response will contain the error details.