GraphQL API
FanPoints provides a GraphQL API. Note that the SDKs are the preferred way to interact with the API. Use the GraphQL API only if you need to access the system in a language other than JavaScript ot Python.
Auth
We use a OAuth 2.0 Client Credentials Flow to authenticate requests to the GraphQL API. The application credentials (client ID and client secret) can be created in the FanPoints dashboard. Depending on the queries you perform, you need a Marketing Partner or a Loyalty Program token.
An example implementation of the OAuth 2.0 Client Credentials Flow in JavaScript can be found in the FanPoints SDK.
Basically, you need to follow these rough steps (the details depend on your programming language and your GraphQL client):
- Call the authorization endpoint to fetch the temporary session token:
const oAuthDomain = 'https://main-user-exttest-pool-domain.auth.eu-central-1.amazoncognito.com/oauth2/token';
const bearerToken = btoa(`${clientId}:${secret}`);
const response = await fetch(oAuthDomain, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', Authorization: `Basic ${bearerToken}`, }, body: 'grant_type=client_credentials&scope=resource-server/api',});const json = await response.json();
if (!json.access_token) { throw new Error( 'Authentification failed. Are your client ID and secret correct?', );}
const token = json.access_token as string;return token;
- Use the temporary session token to perform a request to the GraphQL API:
const sessionToken = '<the temporary session token>';
const graphQlDomain = 'https://qwrxrvw2krfy3klzua7krlkmsq.appsync-api.eu-central-1.amazonaws.com/graphql';
const response = await fetch(graphQlDomain, { method: 'POST', headers: { 'Content-Type': 'application/json', 'authorization': sessionToken, }, body: JSON.stringify(query),});
Querying the GraphQL API
All the functions from the JavaScript SDK are available in the GraphQL API. The corresponding GraphQL queries can be found in the repository. The SDK documentation applies to the GraphQL API as well.
More details
For more details, consider the reference implementation in this repository.