JavaScript SDK
Get started with Monite's JavaScript SDK.
This quick start shows how to set up and utilize Monite's JavaScript SDK within your JavaScript application.
Before you begin
- To follow this quickstart guide, ensure you have retrieved your credentials from the Monite partner portal. For more information, see Get your credentials.
- Ensure that you already have an entity ID. For more information, see Create an entity.
1. Installation
To install the Monite JavaScript SDK:
npm install @team-monite/sdk-api
yarn add @team-monite/sdk-api
2. Initialization
To initialize the Monite JavaScript SDK, import the MoniteSDK
object instance from the package and initialize as shown:
import { MoniteSDK } from "@team-monite/sdk-api";
const monite = new MoniteSDK({
apiUrl: "https://api.sandbox.monite.com/v1",
entityId: "ENTITY_ID",
fetchToken: async () => {
const response = await fetch(
"https://api.sandbox.monite.com/v1/auth/token",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"x-monite-version": "2023-06-04",
},
// TODO: Replace the `client_id`, `entity_user_id` and `client_secret` fields with your Monite credentials
body: JSON.stringify({
grant_type: "entity_user",
entity_user_id: "ENTITY_USER_ID",
client_id: "CLIENT_ID",
client_secret: "CLIENT_SECRET",
}),
}
);
return response.json();
},
});
Initializing the SDK returns an instance that can be stored within a JavaScript constant—monite
. All calls to Monite servers must be made using the monite.api
object. This serves as the entry point to the Monite API.
3. Create a counterpart
Call the monite.api.counterparts.create
object to create a new counterpart. The object accepts a parameter that represents the payload/details of the counterpart to be created.
monite.api.counterparts
.create({
type: "individual",
individual: {
first_name: "Dana",
last_name: "Cruz",
title: "Mr.",
is_vendor: false,
is_customer: true,
phone: "+4930774619876",
email: "[email protected]",
residential_address: {
country: "DE",
city: "Berlin",
postal_code: "10115",
state: "BE",
line1: "Flughafenstrasse 52",
line2: "Additional address",
},
},
})
.then((response) => {
console.log(response);
})
.catch(() => {
// handle error response
});
A successful response to Monite servers returns details of the newly created counterpart.
4. Retrieve a counterpart
To retrieve a counterpart, use the monite.api.counterparts.getById
object and pass in the counterpart ID as shown:
monite.api.counterparts
.getById("644c3129-46c5-4868-9919-cbfc6f3851bb")
.then((res) => {
console.log(res);
})
.catch(() => {
// handle error response
});
A successful response to Monite servers returns an object with the counterpart details.
Updated about 1 month ago