Skip to content

Authenticated Requests

Once you have an access token, you can make authenticated requests to the Nexoya API.

To make authenticated requests, you will need to include the access token in the Authorization header of your request as a "Bearer" token.

sh
#!/bin/bash

# Replace with your actual access token
ACCESS_TOKEN="YOUR_ACCESS_TOKEN"

curl -X POST "https://gw.nexoya.io/api/graphql" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "query": "query User { user { user_id email teams { team_id name __typename } __typename } }",
    "variables": {}
  }'
js
const fetch = require('node-fetch');

const query = `
query User {
  user {
	user_id
	email
	teams {
	  team_id
	  name
      __typename
	}
    __typename
  }
}
`;

const variables = {};

// Implement this function to get the access token
const accessToken = getAccessToken();

const url = 'https://gw.nexoya.io/api/graphql',
  options = {
    method: 'POST',
    headers: {
      Authorization: 'Bearer ' + accessToken,
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: JSON.stringify({
      query,
      variables,
    }),
  };

fetch(url, options).then(handleResponse);

function handleResponse(response) {
  console.log(response);
  response.json().then(function (json) {
    console.log(json);
    return response.ok ? json : Promise.reject(json);
  });
}

JWT Tokens

The access tokens provided by the authorization flows are JWT tokens. You can use a JWT library to decode the token and get expiration date, and other information.