---
title: Getting Access
slug: service-user-credentials
icon: 🔐
createdAt: 2024-07-16T16:06:05.015Z
---

Your Service User credentials will have been sent to you via email. As part of your subscription setup, you will receive an email containing your API key for the Altrata Salesforce app. Please reach out to your Client Success representative or email [client-success@altrata.com](mailto\:client-success@altrata.com) if you have not received your API key or Service User details.

# GraphiQL

This guide will teach you how to to authenticate with GraphiQL so that you can use it for a particular API. To authenticate you will need to do the following steps:

:::::WorkflowBlock
::::WorkflowBlockItem
In your browser, enter the GraphiQL URL of the API that you wish to query against and press enter

:::hint{type="info"}
**If you are unsure of a GraphiQL URL for a service(s), please visit the&#x20;**[URLs](docId:3rGzMF5UH3ep0bh4snVm0) **page that outlines all URLs**
:::
::::

:::WorkflowBlockItem
Enter your service account credentials and press sign in.

![](https://api.archbee.com/api/optimize/OchO21fL_QwZk6Sym4QQl/dlrv1Gv_HO_u6TpQZDRQP_image.png)
:::

:::WorkflowBlockItem
You will now be authenticated and can build your queries.

![](https://api.archbee.com/api/optimize/OchO21fL_QwZk6Sym4QQl/OtRUzOYehHX_rAh8RMswq_image.png)
:::
:::::

:::hint{type="info"}
**If you are unsure on how to use GraphiQL, please go to our dedicated&#x20;**[GraphiQL Explorer](docId\:EMdAHN5GeURzcTXf9La94)**&#x20;section.**
:::

# APIs

To gain access to the Altrata API you will need to supply an API key in addition to your Altrata service user credentials.

This guide will teach you how to generate an access token and how to make a request to an Altrata GraphQL API endpoint.

:::hint{type="warning"}
Note: the username for your Altrata service credentials is **NOT** your email. The username sent during the initial password setup should be used for access
:::



## Generating an access token

The access token is a string that contains the credentials and permissions used to access a given resource.

### How to generate the access token

There are two ways to send your credentials when requesting an access token:

- **Authorisation header** — send the username and password as HTTP Basic credentials in the Authorisation header.
- **Request body** — send the username and password as parameters in the request body.

### Authorisation header flow

:::::WorkflowBlock
::::WorkflowBlockItem
To generate an access token, you will need to make an HTTP POST request to [`https://api-auth.altrata.com/oauth2/token`](https://api-auth.altrata.com/oauth2/token)

In the request, you will need to specify the following:&#x20;

:::ApiMethodV2
```json
{
  "name": "Request access token with Authorisation header",
  "method": "POST",
  "url": "https://api-auth.altrata.com/oauth2/token",
  "description": "This endpoint allows you to request an Altrata access token",
  "tab": "examples",
  "examples": {
    "languages": [
      {
        "id": "6uH2j_4Wpujw7EXkxFarR",
        "language": "curl",
        "code": "\ncurl -X POST \\\n-H \"x-api-key: yourApiKey\" \\\n-u \"username:password\" \\   \n\"https://api-auth.altrata.com/oauth2/token?grant_type=client_credentials\" \\\n",
        "customLabel": ""
      },
      {
        "id": "uqFdNCcuxhay4k5DUUoFE",
        "language": "nodejs",
        "code": "const request = require('request');\nconst username = 'yourUsername';\nconst password = 'yourPassword';\nconst token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64');\nconst apiKey = 'yourApiKeyValue';\n\nconst options = {\n   'method': 'POST',\n   'url': 'https://api-auth.altrata.com/oauth2/token?grant_type=client_credentials',\n   'headers': {\n      'x-api-key': apiKey,\n      'Authorization': `Basic ${token}`\n   }\n};\n\nrequest(options, function (error, response) {\n   if (error) throw new Error(error);\n   console.log(response.body);\n});\n",
        "customLabel": ""
      },
      {
        "id": "4_csYweSoKFgZV3u2y75K",
        "language": "curl",
        "code": "curl --request POST \\\n     --url 'https://api-auth.altrata.com/oauth2/token?grant_type=string' \\\n     --header 'accept: application/json' \\\n     --header 'x-api-key: string' \\\n     --header 'authorization: string'",
        "customLabel": ""
      },
      {
        "id": "0x09p75sSMYzctChYzjfi",
        "language": "nodejs",
        "code": "var request = require('request');\nvar options = {\n   'method': 'POST',\n   'url': 'https://api-auth.altrata.com/oauth2/token?grant_type=string',\n   'headers': {\n      'accept': 'application/json',\n      'content-type': 'application/json',\n      'x-api-key': 'string',\n      'authorization': 'string'\n   }\n};\nrequest(options, function (error, response) {\n   if (error) throw new Error(error);\n   console.log(response.body);\n});\n",
        "customLabel": ""
      },
      {
        "id": "KlkcDhrXAGdjXr_wjpdEE",
        "language": "javascript",
        "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\nmyHeaders.append(\"x-api-key\", \"string\");\nmyHeaders.append(\"authorization\", \"string\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"https://api-auth.altrata.com/oauth2/token?grant_type=string\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));",
        "customLabel": ""
      },
      {
        "id": "yCNAwe15rQEj27SOcM2un",
        "language": "python",
        "code": "import requests\nimport json\n\nurl = \"https://api-auth.altrata.com/oauth2/token?grant_type=string\"\n\npayload = {}\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json',\n   'x-api-key': 'string',\n   'authorization': 'string'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n",
        "customLabel": ""
      },
      {
        "id": "O8s-gL02qzVUZUizgEUKK",
        "language": "ruby",
        "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://api-auth.altrata.com/oauth2/token?grant_type=string\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\nrequest[\"x-api-key\"] = \"string\"\nrequest[\"authorization\"] = \"string\"\n\nresponse = https.request(request)\nputs response.read_body\n",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "6uH2j_4Wpujw7EXkxFarR"
  },
  "results": {
    "languages": [
      {
        "id": "PLT3pPr98TfWR5YKS9xzp",
        "language": "200",
        "customLabel": "",
        "code": "{\n      \"access_token\": \"yourAccessToken\",\n      \"expires_in\": 28800,\n      \"token_type\" \"Bearer\"\n}"
      }
    ],
    "selectedLanguageId": "PLT3pPr98TfWR5YKS9xzp"
  },
  "request": {
    "pathParameters": [],
    "queryParameters": [
      {
        "name": "grant_type",
        "kind": "required",
        "type": "string",
        "description": "Grant type will always be client_credentials",
        "children": []
      }
    ],
    "headerParameters": [
      {
        "name": "x-api-key",
        "kind": "required",
        "type": "string",
        "description": "Enter your API key as the value",
        "children": []
      },
      {
        "name": "Authorization",
        "kind": "required",
        "type": "string",
        "description": "Basic Auth - enter username:password",
        "": "required"
      }
    ],
    "bodyDataParameters": [],
    "formDataParameters": []
  },
  "currentNewParameter": {
    "label": "Header Parameter",
    "value": "headerParameters"
  },
  "hasTryItOut": false,
  "autoGeneratedAnchorSlug": "request-access-token-with-authorisation-header",
  "legacyHash": "3tc-VVB4MAOmV8N9we8Wg"
}
```
:::

| Property      | Parameter | Value                 | Description                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ------------- | --------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| grant\_type   | Query     | 'client\_credentials" | The OAuth2 grant type that is used to obtain an access token                                                                                                                                                                                                                                                                                                                                                                    |
| x-api-key     | Header    | yourApiKey            | You will need to enter your assigned API key as the value                                                                                                                                                                                                                                                                                                                                                                       |
| Authorization | Header    | username\:password    | `Basic Auth` is used for the authorization. <br />If you are making a request via Curl, you can supply your `username:password`. <br />If you are using a backend language/framework such as Node.js, you will need to ensure that your username and password is base64 encoded when making a request to obtain an access token. See the Node.js example on the right to see how to potentially base64 encode your credentials. |


::::

:::WorkflowBlockItem
Once you have made a successful request to obtain an access token, you will get back a 200 response code that contains your bearer access token.&#x20;

```json
{
      "access_token": "yourAccessToken",
      "expires_in": 28800,
      "token_type": "Bearer"
}
```

The token is a JSON Web Token. The expiration time for the tokens is set at 28800 seconds, which is the equivalent of 8 hours. Once 8 hours has passed, the token will have expired, and you will need to request a new token.&#x20;

Please note that if you request a new token before the 8 hours have passed on your existing access token, you will be issued with a new token that will terminate your previous token. This means that you will not be able to use your previous access tokens to make calls to any Altrata API.
:::

:::WorkflowBlockItem
Store your access token in a secure location.
:::
:::::

### &#x20;Request body flow

:::::WorkflowBlock
::::WorkflowBlockItem
To generate an access token, you will need to make an HTTP POST request to [`https://api-auth.altrata.com/oauth2/token`](https://api-auth.altrata.com/oauth2/token)

In the request, you will need to specify the following:&#x20;

:::ApiMethodV2
```json
{
  "name": "Request access token with authorisation in body",
  "method": "POST",
  "url": "https://api-auth.altrata.com/oauth2/token",
  "description": "This endpoint allows you to request an Altrata access token",
  "tab": "examples",
  "examples": {
    "languages": [
      {
        "id": "6uH2j_4Wpujw7EXkxFarR",
        "language": "curl",
        "code": "curl -X POST \\\n-H \"x-api-key: yourApiKey\" \\\n-H \"Content-Type: application/x-www-form-urlencoded\" \\\n--data-urlencode \"client_id=username\" \\\n--data-urlencode \"client_secret=password\" \\\n\"https://api-auth.altrata.com/oauth2/token?grant_type=client_credentials\"",
        "customLabel": ""
      },
      {
        "id": "uqFdNCcuxhay4k5DUUoFE",
        "language": "nodejs",
        "code": "const request = require('request');\nconst username = 'yourUsername';\nconst password = 'yourPassword';\nconst token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64');\nconst apiKey = 'yourApiKeyValue';\n\nconst options = {\n   'method': 'POST',\n   'url': 'https://api-auth.altrata.com/oauth2/token?grant_type=client_credentials',\n   'headers': {\n      'x-api-key': apiKey,\n      'Authorization': `Basic ${token}`\n   }\n};\n\nrequest(options, function (error, response) {\n   if (error) throw new Error(error);\n   console.log(response.body);\n});\n",
        "customLabel": ""
      },
      {
        "id": "lyDKkzDsGV3r5gBNJ0MTB",
        "language": "curl",
        "code": "curl --request POST \\\n     --url 'https://api-auth.altrata.com/oauth2/token?grant_type=string' \\\n     --header 'accept: application/json' \\\n     --header 'x-api-key: string'",
        "customLabel": ""
      },
      {
        "id": "EyYVCrGAwD3hCJfbRfB3V",
        "language": "nodejs",
        "code": "var request = require('request');\nvar options = {\n   'method': 'POST',\n   'url': 'https://api-auth.altrata.com/oauth2/token?grant_type=string',\n   'headers': {\n      'accept': 'application/json',\n      'content-type': 'application/json',\n      'x-api-key': 'string'\n   }\n};\nrequest(options, function (error, response) {\n   if (error) throw new Error(error);\n   console.log(response.body);\n});\n",
        "customLabel": ""
      },
      {
        "id": "5yDMtAcKnuioeIxVjybxL",
        "language": "javascript",
        "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\nmyHeaders.append(\"x-api-key\", \"string\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"https://api-auth.altrata.com/oauth2/token?grant_type=string\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));",
        "customLabel": ""
      },
      {
        "id": "dGdnr4CHS3qQCTh9n39uF",
        "language": "python",
        "code": "import requests\nimport json\n\nurl = \"https://api-auth.altrata.com/oauth2/token?grant_type=string\"\n\npayload = {}\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json',\n   'x-api-key': 'string'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n",
        "customLabel": ""
      },
      {
        "id": "FzSKsq0sFygY4nYVkvjMY",
        "language": "ruby",
        "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://api-auth.altrata.com/oauth2/token?grant_type=string\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\nrequest[\"x-api-key\"] = \"string\"\n\nresponse = https.request(request)\nputs response.read_body\n",
        "customLabel": ""
      },
      {
        "id": "wCgfM2Ml82FG6EkWQXtOQ",
        "language": "curl",
        "code": "curl --request POST \\\n     --url 'https://api-auth.altrata.com/oauth2/token?grant_type=string' \\\n     --header 'accept: application/json' \\\n     --header 'x-api-key: string'",
        "customLabel": ""
      },
      {
        "id": "oqnFOLET-ZaqxNGwgcITq",
        "language": "nodejs",
        "code": "var request = require('request');\nvar options = {\n   'method': 'POST',\n   'url': 'https://api-auth.altrata.com/oauth2/token?grant_type=string',\n   'headers': {\n      'accept': 'application/json',\n      'content-type': 'string',\n      'x-api-key': 'string'\n   }\n};\nrequest(options, function (error, response) {\n   if (error) throw new Error(error);\n   console.log(response.body);\n});\n",
        "customLabel": ""
      },
      {
        "id": "MvnZHlx8CTB2FojcEUg6C",
        "language": "javascript",
        "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"string\");\nmyHeaders.append(\"x-api-key\", \"string\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"https://api-auth.altrata.com/oauth2/token?grant_type=string\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));",
        "customLabel": ""
      },
      {
        "id": "JdcgwUH72Sq7EbzTK9lxr",
        "language": "python",
        "code": "import requests\n\nurl = \"https://api-auth.altrata.com/oauth2/token?grant_type=string\"\n\npayload = {}\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'string',\n   'x-api-key': 'string'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n",
        "customLabel": ""
      },
      {
        "id": "0nJeoARfAEFHhfHIRctXi",
        "language": "ruby",
        "code": "require \"uri\"\nrequire \"net/http\"\n\nurl = URI(\"https://api-auth.altrata.com/oauth2/token?grant_type=string\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"string\"\nrequest[\"x-api-key\"] = \"string\"\n\nresponse = https.request(request)\nputs response.read_body\n",
        "customLabel": ""
      },
      {
        "id": "4VQfUJpd1Z7CQkuDGuYc9",
        "language": "curl",
        "code": "curl --request POST \\\n     --url 'https://api-auth.altrata.com/oauth2/token?grant_type=string' \\\n     --header 'accept: application/json' \\\n     --header 'content-type: string' \\\n     --header 'x-api-key: string' \\\n     --data '{\n     \"client_id\": \"string\",\n     \"client_secret\": \"string\"\n     }'",
        "customLabel": ""
      },
      {
        "id": "TaMguPRGqB8xg3J8UltjA",
        "language": "nodejs",
        "code": "var request = require('request');\nvar options = {\n   'method': 'POST',\n   'url': 'https://api-auth.altrata.com/oauth2/token?grant_type=string',\n   'headers': {\n      'accept': 'application/json',\n      'content-type': 'string',\n      'x-api-key': 'string'\n   },\n   body: '{\\n  \"client_id\": \"string\",\\n  \"client_secret\": \"string\"\\n}'\n\n};\nrequest(options, function (error, response) {\n   if (error) throw new Error(error);\n   console.log(response.body);\n});\n",
        "customLabel": ""
      },
      {
        "id": "OvxmHxiy4MAih2CZNJgGS",
        "language": "javascript",
        "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"string\");\nmyHeaders.append(\"x-api-key\", \"string\");\n\nvar raw = \"{\\n  \\\"client_id\\\": \\\"string\\\",\\n  \\\"client_secret\\\": \\\"string\\\"\\n}\";\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://api-auth.altrata.com/oauth2/token?grant_type=string\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));",
        "customLabel": ""
      },
      {
        "id": "NQcXMs4kZl6uYBh7H-4FT",
        "language": "python",
        "code": "import requests\n\nurl = \"https://api-auth.altrata.com/oauth2/token?grant_type=string\"\n\npayload = \"{\\n  \\\"client_id\\\": \\\"string\\\",\\n  \\\"client_secret\\\": \\\"string\\\"\\n}\"\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'string',\n   'x-api-key': 'string'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n",
        "customLabel": ""
      },
      {
        "id": "360YHWOf2YUtneqaam2nu",
        "language": "ruby",
        "code": "require \"uri\"\nrequire \"net/http\"\n\nurl = URI(\"https://api-auth.altrata.com/oauth2/token?grant_type=string\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"string\"\nrequest[\"x-api-key\"] = \"string\"\nrequest.body = \"{\\n  \\\"client_id\\\": \\\"string\\\",\\n  \\\"client_secret\\\": \\\"string\\\"\\n}\"\n\nresponse = https.request(request)\nputs response.read_body\n",
        "customLabel": ""
      },
      {
        "id": "905EGcbPwS8mcNdvvYbA-",
        "language": "curl",
        "code": "curl --request POST \\\n     --url 'https://api-auth.altrata.com/oauth2/token?grant_type=string' \\\n     --header 'accept: application/json' \\\n     --header 'content-type: string' \\\n     --header 'x-api-key: string' \\\n     --data '{\n     \"client_id\": \"string\",\n     \"client_secret\": \"string\"\n     }'",
        "customLabel": ""
      },
      {
        "id": "RrM70ij0aCJF5ZvA4HJd-",
        "language": "nodejs",
        "code": "var request = require('request');\nvar options = {\n   'method': 'POST',\n   'url': 'https://api-auth.altrata.com/oauth2/token?grant_type=string',\n   'headers': {\n      'accept': 'application/json',\n      'content-type': 'string',\n      'x-api-key': 'string'\n   },\n   body: '{\\n  \"client_id\": \"string\",\\n  \"client_secret\": \"string\"\\n}'\n\n};\nrequest(options, function (error, response) {\n   if (error) throw new Error(error);\n   console.log(response.body);\n});\n",
        "customLabel": ""
      },
      {
        "id": "2H_DBL7g2mU6mkZOVO4FR",
        "language": "javascript",
        "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"string\");\nmyHeaders.append(\"x-api-key\", \"string\");\n\nvar raw = \"{\\n  \\\"client_id\\\": \\\"string\\\",\\n  \\\"client_secret\\\": \\\"string\\\"\\n}\";\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://api-auth.altrata.com/oauth2/token?grant_type=string\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));",
        "customLabel": ""
      },
      {
        "id": "vSN8rvdhutX2ekN5auU6p",
        "language": "python",
        "code": "import requests\n\nurl = \"https://api-auth.altrata.com/oauth2/token?grant_type=string\"\n\npayload = \"{\\n  \\\"client_id\\\": \\\"string\\\",\\n  \\\"client_secret\\\": \\\"string\\\"\\n}\"\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'string',\n   'x-api-key': 'string'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n",
        "customLabel": ""
      },
      {
        "id": "U_9M6w-qcxQEH93-aaf31",
        "language": "ruby",
        "code": "require \"uri\"\nrequire \"net/http\"\n\nurl = URI(\"https://api-auth.altrata.com/oauth2/token?grant_type=string\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"string\"\nrequest[\"x-api-key\"] = \"string\"\nrequest.body = \"{\\n  \\\"client_id\\\": \\\"string\\\",\\n  \\\"client_secret\\\": \\\"string\\\"\\n}\"\n\nresponse = https.request(request)\nputs response.read_body\n",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "6uH2j_4Wpujw7EXkxFarR"
  },
  "results": {
    "languages": [
      {
        "id": "PLT3pPr98TfWR5YKS9xzp",
        "language": "200",
        "customLabel": "",
        "code": "{\n      \"access_token\": \"yourAccessToken\",\n      \"expires_in\": 28800,\n      \"token_type\" \"Bearer\"\n}"
      }
    ],
    "selectedLanguageId": "PLT3pPr98TfWR5YKS9xzp"
  },
  "request": {
    "pathParameters": [],
    "queryParameters": [
      {
        "name": "grant_type",
        "kind": "required",
        "type": "string",
        "description": "Grant type will always be client_credentials",
        "children": []
      }
    ],
    "headerParameters": [
      {
        "name": "x-api-key",
        "kind": "required",
        "type": "string",
        "description": "Enter your API key as the value",
        "children": []
      },
      {
        "name": "Content-Type",
        "kind": "required",
        "type": "string",
        "description": "application/x-www-form-urlencoded",
        "": "required"
      }
    ],
    "bodyDataParameters": [
      {
        "name": "client_id",
        "kind": "required",
        "type": "string",
        "description": "Enter your username",
        "": "required"
      },
      {
        "name": "client_secret",
        "kind": "required",
        "type": "string",
        "description": "Enter your password",
        "": "Enter your password"
      }
    ],
    "formDataParameters": []
  },
  "currentNewParameter": {
    "label": "Body Parameter",
    "value": "bodyDataParameters"
  },
  "hasTryItOut": false,
  "autoGeneratedAnchorSlug": "request-access-token-with-authorisation-in-body",
  "legacyHash": "GiKiCQBi5Pj6MG5-8ZGzZ"
}
```
:::

| Property           | Parameter | Value                             | Description                                                                                                              |
| ------------------ | --------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| grant\_type        | Query     | 'client\_credentials"             | The OAuth2 grant type that is used to obtain an access token                                                             |
| x-api-key          | Header    | yourApiKey                        | You will need to enter your assigned API key as the value                                                                |
| Content-Type<br /> | Header    | application/x-www-form-urlencoded | **Required when&#x20;**<br />**credential**<br />**&#x20;is sent in the body.**<br /> The body is form-encoded, not JSON |
| client\_id         | Body      | username                          | **Without** the authorisation header when you are sending the credential in body this is the **username**                |
| client\_secret     | Body      | password                          | **Without**<br /> an <br />Authorization<br /> header this is your <br />**password**<br />.                             |


::::

:::WorkflowBlockItem
Once you have made a successful request to obtain an access token, you will get back a 200 response code that contains your bearer access token.&#x20;

```json
{
      "access_token": "yourAccessToken",
      "expires_in": 28800,
      "token_type": "Bearer"
}
```

The token is a JSON Web Token. The expiration time for the tokens is set at 28800 seconds, which is the equivalent of 8 hours. Once 8 hours has passed, the token will have expired, and you will need to request a new token.&#x20;

Please note that if you request a new token before the 8 hours have passed on your existing access token, you will be issued with a new token that will terminate your previous token. This means that you will not be able to use your previous access tokens to make calls to any Altrata API.
:::

:::WorkflowBlockItem
Store your access token in a secure location.
:::
:::::


Authenticating to use the GraphQL endpoint

Now that you have generated an access token, you will need to do the following to access the GraphQL endpoint:

:::hint{type="info"}
**If you are unsure of a GraphQL URL for a service(s), please visit the&#x20;**[URLs](docId:3rGzMF5UH3ep0bh4snVm0) **page that outlines all URLs**
:::

:::::WorkflowBlock
:::WorkflowBlockItem
Set your HTTP method to a POST request.
:::

:::WorkflowBlockItem
Set the URL to be the GraphQL endpoint that you wish to request.
:::

::::WorkflowBlockItem
Include both `x-api-key` and `Authorization` headers. Provide your api key as the value in the `x-api-key` header, and set the value`Bearer` and include your access token for the `Authorization` header.



:::ApiMethodV2
```json
{
  "name": "Example Profile GraphQL API",
  "method": "POST",
  "url": "https://profile.altrata.com/v1/graphiql/",
  "description": "Make a request to Profile API",
  "tab": "examples",
  "examples": {
    "languages": [
      {
        "id": "HXH1_3iOlXH-GJrsjmUbM",
        "language": "curl",
        "code": "curl --location --request POST 'https://profile.altrata.com/v1/graphql' \\\n--header 'Authorization: accessToken' \\\n--header 'x-api-key: apiKey'",
        "customLabel": ""
      },
      {
        "id": "VmJoqu8o6fd2j0WDYCexs",
        "language": "nodejs",
        "code": "const request = require('request');\nconst accessToken = \"yourAccessToken\"\nconst apiKey = 'qzAx5Wocf91vkGCVQvCi03kLebIX2gGe5PJZXRuP'\nconst options = {\n   'method': 'POST',\n   'url': 'https://profile.altrata.com/v1/graphiql/',\n   'headers': {\n      'x-api-key': ${apiKey},\n      'Authorization': 'Bearer ${accessToken}'\n   }\n};\nrequest(options, function (error, response) {\n   if (error) throw new Error(error);\n   console.log(response.body);\n});\n",
        "customLabel": ""
      },
      {
        "id": "JufmJnhddX-4n-tBuafkO",
        "language": "python",
        "code": "",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "HXH1_3iOlXH-GJrsjmUbM"
  },
  "results": {
    "languages": [
      {
        "id": "y2nzTtg2b85Ap1uQvzNFx",
        "language": "200",
        "customLabel": "",
        "code": "{\n // Response from the Altrata API\n}"
      }
    ],
    "selectedLanguageId": "y2nzTtg2b85Ap1uQvzNFx"
  },
  "request": {
    "pathParameters": [],
    "queryParameters": [],
    "headerParameters": [
      {
        "name": "x-api-key",
        "kind": "required",
        "type": "string",
        "description": "Provide you API key as the value",
        "children": []
      },
      {
        "name": "Authorization",
        "kind": "required",
        "type": "string",
        "description": "`Bearer {accessToken}`",
        "children": []
      }
    ],
    "bodyDataParameters": [
      {
        "name": "Body",
        "kind": "required",
        "type": "string",
        "description": "Provide constructed GraphQL query here",
        "": "Provide constructed GraphQL query here"
      }
    ],
    "formDataParameters": []
  },
  "currentNewParameter": {
    "label": "Body Parameter",
    "value": "bodyDataParameters"
  },
  "hasTryItOut": false,
  "autoGeneratedAnchorSlug": "example-profile-graphql-api",
  "legacyHash": "l6IwedpJmaOEjsqEGF7Fa"
}
```
:::
::::
:::::



