Do you have a jQuery example for generating an access token?

Modified on Mon, 07 Nov 2022 at 04:25 PM

Yes! You can generate a token suitable for supply queries by making a POST request to the Nexar identity server. There are a number of examples in our public GitHub samples (and a cURL example) but here is a snippet of jQuery code you can utilise on front-end applications. 

var settings = {
  "url": "",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded"
  "data": {
    "client_id": "<your_client_id>",
    "client_secret": "<your_client_secret>",
    "grant_type": "client_credentials"

$.ajax(settings).done(function (response) {

The response should be similar to the following:

The response should be similar to this:
    "access_token": "<your_access_token>",
    "expires_in": 86400,
    "token_type": "Bearer",
    "scope": "supply.domain"

Warning : For performance reasons, and to reduce the pressure on our identity service, please cache the access token (it is valid by default for up to 24 hours) rather than generate a new token for every query.

Be sure to replace the <your_client_id> and <your_client_secret> fields with your Nexar application client information.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article