Using the API
Bunny's GraphQL API lets you create trial subscriptions, track feature usage, update accounts, contacts, quotes and almost all other objects that you can see in the web user interface.
To interact with with Bunny API you will need to follow these steps:
Get an access token
All requests to Bunny require an Access Token to be sent in an Authorization header. To get started quickly you can generate an access token directly in the Bunny admin portal or alternatively you can obtain the client credentials for an API client and generate an access token using an SDK.
In Bunny, go to Settings > API Clients
Select the Default API client
Click the Generate Access Token button and copy the token
Send a GraphQL request
The Bunny SDKs offers convenience methods for some of the common GraphQL requests as well as a raw query method so that you can build your own queries. Learn how to use the Bunny API reference to build your own custom queries.
For example, if a new trial has signed up in your SaaS application then you will track this in Bunny using the convenient subscription creation methods.
const res = bunny.createSubscription('Acme Yachts', 'Jill', 'McGill', '[email protected]', 'free', {
trial: true,
tenantCode: '123456'
})
Alternately you may want to get back a list of Accounts including Contacts. In this case you can build and send your own query using the query
method.
const query = `query accounts ($filter: String, $limit: Int) {
accounts (filter: $filter, limit: $limit) {
id
name
contacts {
firstName
lastName
email
}
}
}`;
const variables = {
filter: "",
limit: 10,
};
const response = await bunny.query(query, variables);
GraphQL is pretty simple in the sense that you're always just sending a HTTP POST request with a specially formatted body. Within that request body you will be asking graphal to perform either a query or a mutation.
Last updated
Was this helpful?