Connecting to our API
GraphQL
Slerp API exposes our content via GraphQL, if you'd like to learn more about GraphQL take a look here: https://graphql.org/
Generating JWT tokens
You will need to authenticate and generate a JSON Web Token (JWT).
We provide three kinds of tokens.
- A public token you can use for your frontend apps. Limited mostly to product and cart creation functions.
- An authenticated customer token you can use for customer specific data such as their orders history. Please use this carefully.
Most examples in this documentation uses the public JWT.
You can generate a JWT by sending a POST request with your API key as your bearer token to the following enviroment urls:
Generating a public/guest JWT token
- Demo:
https://slerp.com.integrations.slerp.io/api/partners_auth/guest
- Production:
https://slerp.com/api/partners_auth/guest
Generating an authenticated JWT token
- Demo:
https://slerp.com.integrations.slerp.io/api/partners_auth
- Production:
https://slerp.com/api/partners_auth
Generating user/customer JWT tokens
A whole section is dedicated for generating customer related tokens here.
Example request:
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var requestOptions = {
method: 'POST',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://slerp.com.integrations.slerp.io/api/partners_auth/guest", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Example response
{
"token": "eyJhbGciOiJIUzI0NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}
For security reasons our JWT tokens expire every 6 months. If you require longer than that, please contact your account manager for a special request.
In most cases, you will only need this call to renew an expired JWT token.
Your JWT tokens carry many privileges, so be sure to keep them secure and not to share them in publicly accessible areas.
Querying our Graph API
Once you have your JWT key make the following query with your JWT in the headers as shown below:
Headers:
'Content-Type': 'application/json',
Authorization: 'Bearer ' + yourJWT,
Query:
query MyFirstQuery {
merchants {
id
name
}
}
To do this open Postman or similar and use the following link:
partner.api.slerp.com.integrations.slerp.io
In your headers set the following:
'Content-Type': 'application/json',
Authorization: 'Bearer ' + replaceWithYourApiKey,
And as we use GraphQL make sure it's a post request.
Then try something simple like this:
query MyFirstQuery {
merchants {
id
name
}
}
If successful you'll get a response like:
{
"data": {
"merchants": [
{
"id": "5abb3b22-86b3-49e6-8774-a3ae185a525a",
"name": "Crosstown"
}
]
}
}
This format is consistent in the api in that your response will be nested: data.something and often inside an array.
If unsuccessul you will receive an error. For example if you try to access something your token does not allow you will see:
{
"errors": [
{
"extensions": {
"path": "$.selectionSet.customers.selectionSet.id",
"code": "validation-failed"
},
"message": "field \"id\" not found in type: 'customers'"
}
]
}
The message will tell you why your request failed.
If you try to access something that doesn't exist you may simply receive an empty array in response.