# How to Issue a Service Token

Here’s a step-by-step guide on how to issue a service token in Oz API 5 and 6.

{% stepper %}
{% step %}

## Step 1

Authorize using your ADMIN account: `{{host}}/api/authorize/auth`.

#### Example request

```markup
curl -L 'https://{{host}}/api/authorize/auth' \
-H 'Content-Type: application/json' \
--data-raw '{
    "credentials": {
        "email": "admin_email@email.com",
        "password": "your_admin_password"
    }
}'
```

#### Example response

```markup
{
  …
    "user": {
        "user_type": "ADMIN",
  …
    },
    "access_token": "<token>",
    …
}
```

{% endstep %}

{% step %}

## Step 2 (optional)

{% hint style="info" %}
This step can be omitted if a company already exists.
{% endhint %}

As a user must belong to a company, create a company: call {`{host}}/api/companies/` with your company name.

#### Example request

```markup
curl -L 'https://{{host}}/api/companies/'
-H 'X-Forensic-Access-Token: token_id'
-H 'Content-Type: application/json'
-d '{ "name": "your_company_name" }'
```

#### Example response

```markup
{
    "company_id": "company_id",
    "name": "your_company_name",
    "in_deletion": false,
    "technical_meta_data": {}
}
```

{% endstep %}

{% step %}

## Step 3

Create a service user. Call `{{host}}/api/users/` and write down `user_id` that you will get in response.

#### Example request

```markup
 curl -L 'https://{{host}}/api/users/'
-H 'X-Forensic-Access-Token: token_id'
-H 'Content-Type: application/json'
--data-raw '{
  "credentials": {
    "email": "<your_new_service_user@email.com>",
    "password": "<your_service_user_password>"
  },
  "profile": {
    "company_id": " company_id",
    <!-- the next line is for API 6 -->
    "user_type": "CLIENT_SERVICE",
    "first_name": "first_name",
    "last_name": "last_name",
    "middle_name": "",
    "is_admin": false,
    <!-- the next line is for API 5 and below -->
    "is_service": true,
    "can_start_analyse_biometry": true,
    "can_start_analyse_collection": true,
    "can_start_analyse_documents": true,
    "can_start_analyse_quality": true
  }
}
```

#### Example response

```markup
{
    "user_id": "user_id",
    "user_type": "CLIENT_SERVICE",
     …
    "is_active": true,
     …
    "is_service": true
}
```

As in API 6.0, the logic of issuing a service token has slightly changed, here are examples for both API 6 and API 5 (and below) cases.

#### API 6

In the request body, define `user_type` as CLIENT\_SERVICE.

```markup
{
  "credentials": {
    "email": " <your_new_service_user@email.com> ",
    "password": "your_client_service_user_password"
  },
  "profile": {
    "company_id": "{{company_id}}",
    "user_type": "CLIENT_SERVICE",
    "first_name": "john",
    "last_name": "doe",
    "middle_name": "",
    "can_start_analysis_biometry": true,
    "can_start_analysis_collection": true,
    "can_start_analysis_documents": true,
    "can_start_analysis_quality": true
  }
}

```

#### &#x20;API 5 and below

Set the `is_service` flag value to true.

```markup
{
    "credentials": {
        "email": "john.doe_client_service@ozforensics.com",
        "password": "your_client_service_user_password"
    },
    "profile": {
        "company_id": "{{company_id}}",
        "user_type": "CLIENT",
        "first_name": "john",
        "last_name": "doe",
        "middle_name": "",
        "is_admin": false,
        "is_service": true,
        "can_start_analyse_biometry": true,
        "can_start_analyse_collection": true,
        "can_start_analyse_documents": true,
        "can_start_analyse_quality": true
    }
}
```

{% endstep %}

{% step %}

## Step 4

If you need to obtain the service token to use it, for instance, with Web SDK, authorize as ADMIN (same as in Step 1) and call:

* API 6: `{{host}}/api/authorize/service_token/{user_id}` with `user_id` from the previous step.
* API 5 and below: `{{host}}/api/authorize/service_token`.

#### Example request

```markup
curl -L 'https://{{host}}/api/authorize/service_token/{{user_id}}' \
-H 'X-Forensic-Access-Token: token_id' \
-H 'Content-Type: application/json'
```

#### Example response

```markup
{
    "token_id": "token_id",
    "user_id": "user_id",
    "access_token": "service_token",
    "expire_date": 1904659888.282587,
    "session_id": 0
}
```

In response, you will get a service token that you can use in any service processes.

{% hint style="info" %}
For Web SDK, specify this token’s value as api\_token in the [Web Adapter configuration file](/oz-knowledge/guides/administrator-guide/web-adapter/configuration-file-settings.md).
{% endhint %}
{% endstep %}
{% endstepper %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.ozforensics.com/oz-knowledge/guides/developer-guide/api/oz-api/use-cases/authentication/how-to-issue-a-service-token.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
