Skip to content

Create token

POST/access-tokens

Account Management API · Token Management

Create access token for a tenant.

Required permissiondownload-token-management:write

Parameters

Name In Type Required Description
X-Tenant-ID header string (uuid) Yes Tenant ID.

Request body

Content type: application/json

Request body fields

labelstringrequired
Token label. Must be between 0 and 50 characters long and only contain alphanumeric characters, commas, hyphens and periods. Special characters are not allowed.
Must match the pattern ^[a-zA-Z\d,\s\-.]{0,50}$.
typestringrequired
Token type. * sophosLinuxSensor - Token that you can use to authenticate downloads of Sophos Linux Sensor.
Must be one of: sophosLinuxSensor.
expiresAtstring (datetime)
Token expires on.

Request samples

curl -X POST "https://api.central.sophos.com/accounts/v1/access-tokens" -H "Authorization: Bearer <access-token>" -H "X-Tenant-ID: <tenant-id>" -H "Content-Type: application/json" -d "{
  \"label\": \"Test Token\",
  \"type\": \"sophosLinuxSensor\",
  \"expiresAt\": \"2021-04-29T15:32:28.482Z\"
}"

import requests

response = requests.post(
    "https://api.central.sophos.com/accounts/v1/access-tokens",
    headers={
        "Authorization": "Bearer <access-token>",
        "X-Tenant-ID": "<tenant-id>",
        "Content-Type": "application/json",
    },
    json={   'label': 'Test Token',
    'type': 'sophosLinuxSensor',
    'expiresAt': '2021-04-29T15:32:28.482Z'},
)
print(response.json())

$headers = @{
    "Authorization" = "Bearer <access-token>"
    "X-Tenant-ID" = "<tenant-id>"
    "Content-Type" = "application/json"
}
$body = '{
  "label": "Test Token",
  "type": "sophosLinuxSensor",
  "expiresAt": "2021-04-29T15:32:28.482Z"
}'
Invoke-RestMethod -Method POST -Uri "https://api.central.sophos.com/accounts/v1/access-tokens" -Headers $headers -Body $body -ContentType "application/json"

package main

import (
    "fmt"
    "io"
    "net/http"
    "strings"
)

func main() {
    req, err := http.NewRequest("POST", "https://api.central.sophos.com/accounts/v1/access-tokens", strings.NewReader(`{
  "label": "Test Token",
  "type": "sophosLinuxSensor",
  "expiresAt": "2021-04-29T15:32:28.482Z"
}`))
    if err != nil {
        panic(err)
    }
    req.Header.Set("Authorization", "Bearer <access-token>")
    req.Header.Set("X-Tenant-ID", "<tenant-id>")
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

const response = await fetch("https://api.central.sophos.com/accounts/v1/access-tokens", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <access-token>",
    "X-Tenant-ID": "<tenant-id>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "label": "Test Token",
  "type": "sophosLinuxSensor",
  "expiresAt": "2021-04-29T15:32:28.482Z"
}),
});
const data = await response.json();
console.log(data);

Responses

201 — Access token.

Response fields

idstring (uuid)required
Unique token ID.
tokenstringrequired
Access token.
typestringrequired
Token type. * sophosLinuxSensor - Token that you can use to authenticate downloads of Sophos Linux Sensor.
Must be one of: sophosLinuxSensor.
labelstring
Token description.
createdAtstring (datetime)required
Token created.
expiresAtstring (datetime)required
Token expires on.
urlstringrequired
URL that the token gives access to.
createdByobjectrequired
Show child attributesHide child attributes
idstringrequired
Principal ID.
typestring (enum)required
Type of entity that made this change.
Must be one of: user, service.
namestring
Principal name.
accountTypestring
Account type for this principal.
Must be one of: partner, tenant, organization, distributor.
accountIdstring (uuid)
Account ID.

Errors

Status Meaning
400 Bad request.
403 Request is incompatible with tenant's current licenses.
500 Unexpected error.

All error responses share the same shape — see the error response object.

Response examples

201

{
  "id": "00000000-0000-0000-0000-000000000000",
  "token": "string",
  "type": "sophosLinuxSensor",
  "label": "string",
  "createdAt": "string",
  "expiresAt": "string",
  "url": "string",
  "createdBy": {
    "id": "string",
    "type": "user",
    "name": "string",
    "accountType": "partner",
    "accountId": "00000000-0000-0000-0000-000000000000"
  }
}

See the guide for a narrative walkthrough of this API.