# Creating a Signature

Requests to interact with the service are signed using the SHA256 algorithm. The signature is created separately for each request.

To create a signature, the following steps must be taken:

1. **The request body is sorted alphabetically and encoded in BASE64.**
2. **Concatenate the encoded request body and the secret\_key (provided separately).**
3. **By using the SHA256 hash function, hash the concatenation result.**
4. **Add X-signature to the request headers.**

Request fields filled with <mark style="color:green;">**""**</mark> do not participate in creating the signature.

{% tabs %}
{% tab title="Python3" %}

```javascript
import json
import base64
import hashlib
#Тело запроса меняется в зависимости от запроса

request_data = {
  "agent": "tarlan",
  "project": "mobile",
  "service_code": "101",
}
#Для примера взяли secret 12345
secret = "12345"

sorted_data = json.dumps(
      request_data,
      sort_keys=True,
      ensure_ascii=False,
      separators=(',', ':'),
  )


base64_encoded_data = base64.b64encode(sorted_data.encode()).decode()

data_to_sign = base64_encoded_data + secret

sha256_hash = hashlib.sha256(data_to_sign.encode()).hexdigest()

print("Sign:",sha256_hash)
```

{% endtab %}

{% tab title="Golang" %}

```python
package main

import (
  "crypto/sha256"
  "encoding/base64"
  "encoding/json"
  "fmt"
) 
//Тело запроса меняется в зависимости от запроса

type Request struct {
  Agent       string `json:"agent"`
  Project     string `json:"project"`
  ServiceCode string `json:"service_code"`
}
//Для примера secret 12345
const secret = "12345"

func main() {
  request := Request{
      Agent:       "tarlan",
      Project:     "mobile",
      ServiceCode: "101",
  }

  notSortedJson, err := json.Marshal(&request)
  if err != nil {
      panic(err)
  }

  var notSortedMap map[string]interface{}

  if err = json.Unmarshal(notSortedJson, &notSortedMap); err != nil {
      panic(err)
  }

  sortedJson, err := json.Marshal(&notSortedMap)
  if err != nil {
      panic(err)
  }

  signData := base64.StdEncoding.EncodeToString(sortedJson)

  sign := sha256.Sum256([]byte(signData + secret))
fmt.Printf("Sign: %x", sign) }
```

{% endtab %}
{% endtabs %}


---

# 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://docs.tarlanpayments.kz/eng/agws/creating-a-signature.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.
