MantleClient
To get started with the Mantle JS client, first install the @heymantle/mantle-client
package from npm.
@heymantle/mantle-client
should be used in two different ways:
- On the backend: When identifying a customer, you use
MantleClient
to identify your customers using your Mantle API key and the relevant customer data outlined here. - On the frontend: If you are not using
@heymantle/react
and the<MantleProvider>
component, you can useMantleClient
to interact with the Mantle API directly.
Identify your customer
const { MantleClient } = require('@heymantle/client');
/**
* Inititalize the Mantle client with your Mantle API key and App ID
* NOTE: You should never expose your Mantle API key in the frontend
*/
const client = new MantleClient({
appId: process.env.MANTLE_APP_ID,
apiKey: process.env.MANTLE_API_KEY,
});
/**
* Identify the customer using the client - if you want to enrich your customer data
* automatically with the Shopify Admin API, please provide the `accessToken`
*/
const { apiToken: customerApiToken } = await client.identify({
platform: 'shopify',
platformId: shop.id,
myshopifyDomain: shop.myshopifyDomain,
accessToken: shop.accessToken,
name: shop.name,
email: shop.email,
customFields: {
'Custom 1': 1234,
'Custom 2': 'abc',
},
});
Get customer details
const { customer } = await client.getCustomer();
Which will give you a response like this:
{
id: "123",
test: false,
installedAt: "2023-10-25",
trialStartsAt: "2023-10-25",
trialExpiresAt: "2023-11-03",
plans: {
id: "345",
name: "Advanced",
...
},
subscription: {
...
},
features: {
...
},
usage: {
...
},
customFields: {
...
}
}
Check out the @heymantle/mantle-client library to learn more, or head to our API docs to see the full list of available endpoints.