> For the complete documentation index, see [llms.txt](https://developers.docstudio.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.docstudio.com/api-reference/authorization.md). Agents can also search and read this documentation through its [MCP server](https://developers.docstudio.com/~gitbook/mcp).

# Authorization

This document contains details for the /api/login endpoint, including the request body, response token, and status codes.

### Endpoint

| Method | Endpoint     |
| ------ | ------------ |
| `POST` | `/api/login` |

### Headers

<table><thead><tr><th width="164.333251953125">Header</th><th width="106.3333740234375">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>Content-Type</code></td><td>Yes</td><td><code>application/json</code></td></tr><tr><td><code>Client-Device-Id</code></td><td>No</td><td>Client device identifier. When provided, the response includes <code>deviceId</code>.</td></tr></tbody></table>

```http
Content-Type: application/json
```

### Request body

| Field      | Type   | Required | Description         |
| ---------- | ------ | -------- | ------------------- |
| `login`    | string | Yes      | User login or email |
| `password` | string | Yes      | User password       |

### Request example

{% tabs %}
{% tab title="Node.js" %}

```javascript
const response = await fetch(
  "https://api.docstudio.com/api/login",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      login: "user@example.com",
      password: "password"
    })
  }
);

const body = await response.text();

if (!response.ok) {
  throw new Error(
    `Request failed: ${response.status}\n${body}`
  );
}

console.log(body);
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$payload = json_encode([
    "login" => "user@example.com",
    "password" => "password"
], JSON_THROW_ON_ERROR);

$curl = curl_init(
    "https://api.docstudio.com/api/login"
);

curl_setopt_array($curl, [
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        "Content-Type: application/json"
    ],
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_RETURNTRANSFER => true
]);

$body = curl_exec($curl);

if ($body === false) {
    throw new RuntimeException(curl_error($curl));
}

$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException(
        "Request failed: {$status}\n{$body}"
    );
}

echo $body;
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

response = requests.post(
    "https://api.docstudio.com/api/login",
    json={
        "login": "user@example.com",
        "password": "password",
    },
    timeout=30,
)

response.raise_for_status()
print(response.text)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require "json"
require "net/http"
require "uri"

uri = URI(
  "https://api.docstudio.com/api/login"
)

request = Net::HTTP::Post.new(uri)
request["Content-Type"] = "application/json"
request.body = JSON.generate(
  login: "user@example.com",
  password: "password"
)

response = Net::HTTP.start(
  uri.hostname,
  uri.port,
  use_ssl: uri.scheme == "https"
) do |http|
  http.request(request)
end

unless response.is_a?(Net::HTTPSuccess)
  raise "Request failed: #{response.code}\n#{response.body}"
end

puts response.body
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	payload := map[string]string{
		"login":    "user@example.com",
		"password": "password",
	}

	requestBody, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}

	request, err := http.NewRequest(
		http.MethodPost,
		"https://api.docstudio.com/api/login",
		bytes.NewReader(requestBody),
	)
	if err != nil {
		panic(err)
	}

	request.Header.Set(
		"Content-Type",
		"application/json",
	)

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

	body, err := io.ReadAll(response.Body)
	if err != nil {
		panic(err)
	}

	if response.StatusCode < 200 ||
		response.StatusCode >= 300 {
		panic(fmt.Sprintf(
			"Request failed: %s\n%s",
			response.Status,
			body,
		))
	}

	fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
  public static void main(String[] args) throws Exception {
    String payload = """
        {
          "login": "user@example.com",
          "password": "password"
        }
        """;

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create(
            "https://api.docstudio.com/api/login"
        ))
        .header(
            "Content-Type",
            "application/json"
        )
        .POST(
            HttpRequest.BodyPublishers.ofString(payload)
        )
        .build();

    HttpResponse<String> response =
        HttpClient.newHttpClient().send(
            request,
            HttpResponse.BodyHandlers.ofString()
        );

    if (response.statusCode() < 200 ||
        response.statusCode() >= 300) {
      throw new RuntimeException(
          "Request failed: " + response.statusCode()
          + "\n" + response.body()
      );
    }

    System.out.println(response.body());
  }
}
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;

var payload = JsonSerializer.Serialize(new
{
    login = "user@example.com",
    password = "password"
});

using var client = new HttpClient();

using var request = new HttpRequestMessage(
    HttpMethod.Post,
    "https://api.docstudio.com/api/login"
);

request.Content = new StringContent(
    payload,
    Encoding.UTF8,
    "application/json"
);

using var response = await client.SendAsync(request);
var body = await response.Content.ReadAsStringAsync();

if (!response.IsSuccessStatusCode)
{
    throw new HttpRequestException(
        $"Request failed: {(int)response.StatusCode}\n{body}"
    );
}

Console.WriteLine(body);
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request POST \
  --url 'https://api.docstudio.com/api/login' \
  --header 'Content-Type: application/json' \
  --data '{
    "login": "user@example.com",
    "password": "password"
  }'
```

{% endtab %}
{% endtabs %}

### Response

{% hint style="info" %}
The response always contains a temporary authorization token. The `deviceId` field is returned only when the request includes the client device ID header; otherwise, this field is omitted.
{% endhint %}

<table><thead><tr><th width="104">Field</th><th width="97">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>token</code></td><td>string</td><td>Temporary authorization token. Expires after 3 hours</td></tr><tr><td><code>deviceId</code></td><td>string</td><td>Device ID returned only when the request includes the client device identifier header</td></tr></tbody></table>

### Response example

When the request does not include the `Client-Device-Id` header, the response contains only the temporary authorization token. When the header is provided, the response also contains the generated `deviceId`.

**Response without `Client-Device-Id`**

```json
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
```

**Response with `Client-Device-Id`**

```json
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "deviceId": "{deviceId}"
}
```

### Status codes

<table><thead><tr><th width="322.4444580078125">Code</th><th>Description</th></tr></thead><tbody><tr><td><code>200</code></td><td>Success. The response contains a temporary authorization token and, when requested, a device ID</td></tr><tr><td><code>401</code></td><td>Invalid login or password</td></tr><tr><td><code>403</code></td><td>Authenticated user lacks required access</td></tr></tbody></table>

### Related topics

* [Authentication and application tokens](https://developers.docstudio.com/introduction/authentication-and-application-tokens.md)
* [API token security](https://developers.docstudio.com/introduction/api-token-security.md)
* [Error Codes](https://developers.docstudio.com/error-codes/error-handling-and-api-error-codes.md)
