API request handler

Setup a basic function to request our API

First, let's define an apiRequest function so we can call differents endpoints, in the following exemple we will use fetch to perform api calls :

const API_GETQUANTY_OEM = 'https://api.oem.getquanty.com/api';

async function apiRequest(uri, data) {
    const API_ENDPOINT = `${API_GETQUANTY_OEM}${uri}`;
    try {
        const response = await fetch(API_ENDPOINT, {
            method: "POST",
            headers: {
                'Content-type': 'application/json; charset=UTF-8',
                'Access-Control-Allow-Origin': '*',
                'gq-oem-key': '<oem-key>',
                'gq-oem-user': '<oem-user-id>'
            },
            credentials: 'include',
            body: JSON.stringify(data),
        });
        return response.json();
    } catch (error) {
        return null;
    }
}

Don't forget to replace <oem-key> with your OEM key and <oem-user-id> is a user id provided by you (ex: 12345678, user-55, johndoe, ...)

You are responsible of handling the <oem-user-id> values. Each unique user should have a unique id.


What’s Next