FAQ API
How do I get an API access authorization token?
the Sage Active Public API is secured by Oauth 2.0 authentication.
The example of obtaining a token is explained:
What rights are needed to call the API?
To have the right to call the APIs, the user must is a Sage Active user.
Error: Access denied due to invalid subscription key.
If this error occurs when using Sage Active Public API:
{
"statusCode": 401,
"message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription."
}
Check the following points :
-
With the sample postman collection :
Check that the subscriptionKey variable is the correct Subscription primary key or Subscription secondary key in your application. -
With your implementation or from Postman without the example collection :
Check in the Header of your request ifx-api-key
is filled in with the correct Subscription primary key or Subscription secondary key in your application.
If this error occurs when using Sage Active Public API
{
"statusCode": 401,
"message": "JWT not present."
}
Check the following points :
-
With the sample postman collection :
Check that the accessToken variable is filled in with a valid access token. -
With your implementation or from Postman without the example collection :
Check in the Header of your request ifAuthorization
is filled in with the correct Bearer [access token] retrieved from the authentication of the current user.
If this error occurs when using Sage Active Public API
{
"Message": "Bad Request",
"Code": null,
"Path": null,
"Locations": null,
"Extensions": null,
"Exception": null,
"SyntaxNode": null
}
Check the following points :
- With the sample postman collection :
- Check that the X-TenantId variable is filled in.
- Check that the X-OrganizationId variable is filled in.
- With your implementation or from Postman without the example collection :
- Check in the Header of your request if
X-TenantId
is filled in with a valid tenant Id. - Check in the Header of your request if
X-OrganizationId
is filled in with a valid Organization Id.
- Check in the Header of your request if
How to fetch created or modified objects after a specific date in GraphQL?
In most REST APIs, it’s common to set the modificationDate
to the creationDate
upon object creation.
This simplifies filtering and sorting by a single field.
However, in a GraphQL API using HotChocolate like the Sage Active Public API, this approach is unnecessary due to the advanced filtering capabilities natively supported.
GraphQL allows you to apply multiple conditions on different fields in a single query, making it easy to filter both creationDate
and modificationDate
without having to merge the two fields.
You can use logical operators such as or
or and
and comparison operators like gt
(greater than) to handle complex queries efficiently.
For example, with the Sage Active Public API you could filter objects created or modified after a certain date with a query like this:
Query
query ($currentDate : DateTime!) {
customers (
where:{
or: [
{ creationDate: { gt:$currentDate } },
{ modificationDate: { gt: $currentDate } }
]
}
) {
edges {
node {
creationDate
modificationDate
id
socialName
tradeName
code
}
}
}
}
Variables
{
"currentDate": "2024-10-17"
}
This flexibility eliminates the need for the “trick” of setting modificationDate
to creationDate
on creation, which is often used in REST APIs to avoid multi-condition queries. Instead, you can directly filter and sort on both dates with ease, offering greater precision and efficiency.