MantleClient setup

For this getting started guide, we'll focus on setting up MantleClient for backend use - this is what you'll need for identifying customers and tracking usage. While MantleClient can also be used in the frontend (with a customer's API token instead of your API key), we'll cover that in the frontend integration guides later.

MantleClient is a helpful wrapper around Mantle's API that:

  • Manages authentication headers automatically
  • Provides type safety for requests and responses
  • Offers a consistent interface for both backend and frontend

While you can make direct API calls instead, using MantleClient will make the next steps in this guide easier to follow.

🔦

If you're using functional components with React, note that Mantle offers MantleProvider.

Step 1: Install the package

npm install @heymantle/client
# or
yarn add @heymantle/client

Step 2: Initialize for backend use

Using the credentials from our previous step:

const { MantleClient } = require('@heymantle/client');

const mantleClient = new MantleClient({
  appId: process.env.MANTLE_APP_ID,
  apiKey: process.env.MANTLE_APP_API_KEY,  // Your API key for backend operations
});

Step 3: Test your setup

You can verify your setup with a simple test:

const customer = await mantleClient.getCustomer('CUSTOMER ID HERE');
console.log(customer);

You should now see some JSON representing the customer in your terminal's output. If you don't, the credentials or customer ID may be incorrect.

What's next?

Now that you have MantleClient set up for backend operations, you're ready to:

Throughout our getting started guide, we'll use MantleClient in our examples, but you can also use direct API calls if you prefer. The API reference shows both approaches.


Did this page help you?