Make your first API call
Let's retrieve details about the customer we just identified. We'll use the customerApiToken we received and stored from the identification step.
Using MantleClient
Using the MantleClient and customerApiToken from our previous steps:
const mantleClient = new MantleClient({
appId: process.env.MANTLE_APP_ID,
customerApiToken: customerApiToken // from the previous identify step
});
// Get details for the customer we just identified
const customer = await mantleClient.getCustomer();
console.log('Customer data:', customer);You should see a response similar to this (note that plans, features, and usage data will only appear if you've configured them in your Mantle account):
{
id: "123",
test: false,
installedAt: "2024-02-26",
trialStartsAt: "2024-02-26",
trialExpiresAt: "2024-03-11",
plans: [{
id: "345",
name: "Pro",
description: null,
features: {
// appears after configuring features in Mantle
}
}],
subscription: {
// appears after customer subscribes to a plan
},
features: {
// appears after configuring features in Mantle
},
usage: {
// appears after sending usage events
},
customFields: {
// appears after setting custom fields
}
}Direct API request
If you prefer, you can also make the request directly to Mantle's API, still using the same customerApiToken:
const response = await fetch('https://appapi.heymantle.com/v1/customer', {
headers: {
'X-Mantle-App-Id': process.env.MANTLE_APP_ID,
'X-Mantle-Customer-Api-Token': customerApiToken // from the previous identify step
}
});
const data = await response.json();
console.log('Customer data:', data.customer);Updated over 1 year ago
Did this page help you?