Mutations define GraphQL operations which change data on the server. They are the primary way to take actions with your data in Kana. The majority of operations below require you to provide the fields you want returned after the mutation occurs - the same principles that apply to Queries apply here too.At the start of every mutation operation, ensure that you specify mutation before the field(s).
mutation updateFeature($input: UpdateFeatureInput!) { updateFeature(input: $input) { id name type unitLabel unitLabelPlural metadata packages { id name status isAddon updatedAt features { id name type limit unitLabel unitLabelPlural metadata } prices { id provider amount displayAmount currency interval } } }}
Package StatusYour package will always have a status of DRAFT upon being created. If you want to publish this package then you will have to do so through the Dashboard.
mutation createPackage($input: CreatePackageInput!) { createPackage(input: $input) { id name status metadata features { id name limit type unitLabel unitLabelPlural metadata } prices { id provider amount displayAmount currency interval } isAddon updatedAt }}
Only metadata can be updated on the Package object through the API. All other updates will need to be done through the Dashboard. Let us know if you want to see further updatable fields and your use-cases!
mutation updatePackage($input: UpdatePackageInput!) { updatePackage(input: $input) { id name status metadata features { id name limit type unitLabel unitLabelPlural metadata } prices { id provider amount displayAmount currency interval } isAddon updatedAt }}
How can I update the email or billingId of a user?You will need to do this through a CSV Import within our Dashboard. We’ll soon make this possible through the API.
Subscribe a User to a Package - either one or multiple. Returns a PackageSubscription.Users can only be subscribed to a Package with a status of PUBLISHED.
mutation subscribeUserToPlan($packageIds: [String!]!, $userId: String!) { subscribe(packageIds: $packageIds, userId: $userId) { id userId status package { id name status metadata features { id name limit type unitLabel unitLabelPlural metadata } prices { id provider amount displayAmount currency interval } isAddon updatedAt } }}
Subscribe the user to a base (or live) plan before, or during, this call. The isAddon field for the plan object must be false. You can check existing Plans with the plans query.
Ensure there’s only one base plan in the mutation, or check that the user is not already subscribed to a base plan with the subscription query. The isAddon field for the Package object will be false if it’s a base plan. You can check Packages with the packages query.
Records the usage of a Feature by a User, including the amount it was used by.
Revert UsageIf you want to revert usage by a certain amount (ie. subtract rather than add from the usage of a feature), you can do so by providing a negative amount in the delta argument (ie. -1).
Generate a payment link which a user can navigate to in order to pay and subscribe to a Package.
A billing template (which has a price associated to it) must be created
and linked to the package you want a user to subscribe to. You can do so in
the Dashboard. You will need to provide a
valid templateId - otherwise aSubscriptionLinkError error will be
returned.
Upon successful payment, we will automatically receive notification of the
user and the packages they have subscribed to in order to create
PackageSubscriptions.
You do not need to notify Kana (ie. through the
subscribe
mutation) yourself.
The identifier of the user who will be subscribing. This maps to the id field as set on the User object. Your billing provider will otherwise create this user in Kana for you if you don’t have an identifier available.