# KSA v2: Sign in

Sign in to your Complyance account with your refresh token and get the access token the other KSA ZATCA API v2 requests need. This page documents API v2, a legacy version.

> **Legacy API v2**
>
> This page documents API v2, which is no longer developed. New integrations should use the current API: see [Unify](https://docs.complyance.io/api-reference/unify/) and [Saudi Arabia](https://docs.complyance.io/countries/sa/).

Use this API to sign in to your Complyance account and get an access token for the other Complyance APIs. You need the refresh token you received when you [signed up](https://docs.complyance.io/legacy/v2/ksa/signup/).

Send every required parameter in the format shown below.

## Endpoint

```http
POST https://<your-v2-api-host>/api/v1/proto/signIn
```

Use the v2 API host you were given when your account was set up. If you no longer have it, contact <support@complyance.io>.

## Examples

**cURL**

```bash title="Sign in"
curl -X POST https://<your-v2-api-host>/api/v1/proto/signIn \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{"refreshToken": "eyJjdHkiOiJKV1QifQ.example-refresh-token.signature"}'
```

**JavaScript**

```javascript title="Sign in"
const inputBody = JSON.stringify({
  refreshToken: 'eyJjdHkiOiJKV1QifQ.example-refresh-token.signature'
});
const headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json'
};

fetch('https://<your-v2-api-host>/api/v1/proto/signIn', {
  method: 'POST',
  body: inputBody,
  headers: headers
})
  .then(function (res) {
    return res.json();
  })
  .then(function (body) {
    console.log(body);
  });
```

**Ruby**

```ruby title="Sign in"
require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json'
}

body = {
  refreshToken: 'eyJjdHkiOiJKV1QifQ.example-refresh-token.signature'
}.to_json

result = RestClient.post 'https://<your-v2-api-host>/api/v1/proto/signIn', body, headers

p JSON.parse(result)
```

**Python**

```python title="Sign in"
import requests

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}
body = {
  'refreshToken': 'eyJjdHkiOiJKV1QifQ.example-refresh-token.signature'
}

r = requests.post('https://<your-v2-api-host>/api/v1/proto/signIn', json=body, headers=headers)

print(r.json())
```

**PHP**

```php title="Sign in"
<?php

require 'vendor/autoload.php';

$headers = array(
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
);

$client = new \GuzzleHttp\Client();

// The request body.
$request_body = array(
    'refreshToken' => 'eyJjdHkiOiJKV1QifQ.example-refresh-token.signature',
);

try {
    $response = $client->request('POST', 'https://<your-v2-api-host>/api/v1/proto/signIn', array(
        'headers' => $headers,
        'json' => $request_body,
    ));
    print_r($response->getBody()->getContents());
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // Handle the exception or API errors.
    print_r($e->getMessage());
}
```

**Java**

```java title="Sign in"
URL obj = new URL("https://<your-v2-api-host>/api/v1/proto/signIn");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
String body = "{\"refreshToken\": \"eyJjdHkiOiJKV1QifQ.example-refresh-token.signature\"}";
try (OutputStream os = con.getOutputStream()) {
    os.write(body.getBytes(StandardCharsets.UTF_8));
}
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
```

**Go**

```go title="Sign in"
package main

import (
	"bytes"
	"net/http"
)

func main() {
	jsonReq := []byte(`{"refreshToken": "eyJjdHkiOiJKV1QifQ.example-refresh-token.signature"}`)

	req, err := http.NewRequest("POST", "https://<your-v2-api-host>/api/v1/proto/signIn", bytes.NewBuffer(jsonReq))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Accept", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	// ...
}
```

## Request parameters

| Parameter | Required | Type | Description | Example |
| - | - | - | - | - |
| `refreshToken` | Yes | string | The long-lived token you received when you signed up. It is valid for one year from the time it was created. | `eyJjdHkiOiJKV1QifQ.example-refresh-token.signature` |

```json title="Request body"
{
  "refreshToken": "eyJjdHkiOiJKV1QifQ.example-refresh-token.signature"
}
```

## Response parameters

| Parameter | Type | Description | Example |
| - | - | - | - |
| `accessToken` | string | A temporary token, valid for one day from the time it was created. Send it in the `Authorization` header to use the other Complyance APIs. | `eyJhbGciOiJSUzI1NiJ9.example-access-token.signature` |

```json title="Response"
{
  "accessToken": "eyJhbGciOiJSUzI1NiJ9.example-access-token.signature"
}
```

## Next step

[Generate an API key](https://docs.complyance.io/legacy/v2/ksa/api-key-generation/) with the access token.

Source: https://docs.complyance.io/legacy/v2/ksa/signin/
