# Authentication

This page describes how to authenticate to the Integrator via API and obtain an access token. The token is then used to authorize subsequent API calls (for example, sending Outbound flow data for flows set as "Outbound").

## <mark style="color:red;">`POST`</mark> <mark style="color:red;">Login</mark>

This method is used to authenticate a user by e‑mail address and password and to retrieve a **short-lived** access token.

**Path**: `/api/nifi/login`

* Prod Integrator: `https://flow.entegrator.akinon.net:3000/api/nifi/login`
* Dev Integrator: `https://flow-dev.entegrator.akinon.net:3000/api/nifi/login`

#### **Headers**

| Header       | Description          | Required | Value                               |
| ------------ | -------------------- | :------: | ----------------------------------- |
| Content-Type | Request content type |     ✓    | `application/x-www-form-urlencoded` |

#### **Body Parameters**

The login endpoint expects credentials in the request body, encoded as `application/x-www-form-urlencoded`.

| Parameter | In   | Description         | Required | Example           |
| --------- | ---- | ------------------- | :------: | ----------------- |
| username  | body | User e‑mail address |     ✓    | `user@akinon.com` |
| password  | body | User password       |     ✓    | `********`        |

#### **Example Request (cURL)**

```bash
curl --location 'https://flow-dev.entegrator.akinon.net:3000/api/nifi/login' \
	--header 'Content-Type: application/x-www-form-urlencoded' \
	--data-urlencode 'username=<user mail address>' \
	--data-urlencode 'password=<password>'
```

#### **Example Response (200 OK)**

The response body is plain text and contains only the access token string:

```
<token>
```

You must include this token in the `Authorization` header when calling other secured Integrator endpoints:

```http
Authorization: Bearer <token>
```

#### **Example Python Code (Using `requests`)**

The following example shows how to log in, retrieve the token, and prepare headers for subsequent API calls using the `requests` library:

```python
import requests

login_url = "https://flow-dev.entegrator.akinon.net:3000/api/nifi/login"

payload = {
		"username": "user@example.com",
		"password": "<password>",
}

headers = {
		"Content-Type": "application/x-www-form-urlencoded",
}

response = requests.post(login_url, data=payload, headers=headers)

if response.status_code == 200:
		# The response body is plain text token
		token = response.text.strip()
		print("Access token:", token)

		# Use the token for authorized requests
		auth_headers = {
				"Authorization": f"Bearer {token}",
		}

		# Example: send data to an outbound flow using the token
		outbound_url = "https://flow-dev.entegrator.akinon.net:3002/api/p1/akinon/<projectSlug>/<flowSlug>"
		outbound_headers = {
				"Authorization": f"Bearer {token}",
				"Content-Type": "application/json",
		}
		outbound_payload = [
				{
						"stock_list": "1",
						"unit_type": "qty",
						"product_sku": "12345",
						"stock": 123,
				},
				{
						"stock_list": "1",
						"unit_type": "qty",
						"product_sku": "12346",
						"stock": 0,
				},
				{
						"stock_list": "1",
						"unit_type": "qty",
						"product_sku": "12347",
						"stock": 9,
				},
		]
		outbound_response = requests.post(
				outbound_url, headers=outbound_headers, json=outbound_payload
		)
		print("Outbound flow response:", outbound_response.status_code, outbound_response.text)
else:
		print("Login failed:", response.status_code, response.text)
```

#### **Response Errors**

* Status Code 400: Returned when the supplied credentials are invalid. The response body is the plain text message: `The supplied username and password are not valid.`
* Status Code 400: Returned when the `username` and/or `password` are missing. The response body is the plain text message: `The username and password must be specified.`
