---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://yandex.ru/dev/direct/doc/dg-v4/en/examples/python-json.md
  - https://yandex.ru/dev/direct/doc/dg-v4/ru/examples/python-json.md
  - href: en/examples/python-json.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.ru/dev/direct/doc/dg-v4/en/llms.txt

# JSON
Examples of accessing the API using Python in JSON format.
## Getting information about the client {#oauth}

This example demonstrates calling the [GetClientInfo](https://yandex.ru/dev/direct/doc/dg-v4/en/reference/GetClientInfo.md) method.

```python
import json, urllib2

#Address for sending JSON requests
url = 'https://api.direct.yandex.ru/v4/json/'

#data for OAuth authorization
token = 'e4d3b4d2a7444fa384a18cda5cd1c8d9'

#Yandex Direct login
login = 'agrom'

#input data structure (dictionary)
data = {
   'method': 'GetClientInfo',
   'token': token,
   'locale': 'ru',
   'param': [login]
}

#convert the dictionary to JSON format and UTF-8 encoding
jdata = json.dumps(data, ensure_ascii=False).encode ('utf8')

#execute the request
response = urllib2.urlopen(url,jdata)

#output the result
print response.read().decode('utf8')
```

## Calling finance methods {#fin-methods}

When calling the finance method, you must additionally specify the finance token and the transaction number (see [Accessing finance methods](https://yandex.ru/dev/direct/doc/dg-v4/en/concepts/finance-token.md)).

As an example, we will call the [CreateInvoice](https://yandex.ru/dev/direct/doc/dg-v4/en/reference/CreateInvoice.md) method, which creates an invoice. Below you can see how the finance token is formed. The input data are the master token (obtained from the Yandex Direct interface), the transaction number, the method name, and the username.

```python
import hashlib

masterToken  = 'AEgchkX2M3FBL8lU'
operationNum = 119
usedMethod   = 'CreateInvoice'
login        = 'agrom'

financeToken = hashlib.sha256(masterToken + str(operationNum) + usedMethod + login).hexdigest()
print financeToken
```

This creates a single-use finance token for calling the `CreateInvoice` method for the user `agrom`. An example of the token is shown below.

```
7215f95e84a766971d8ec4eb5a39ae96505b3a5529a91e5a03e5943565a6e6c7
```

The finance token and transaction number are included in the input data structure, as shown below.

```python
#input data structure (dictionary)
data = {
   'method': 'GetCreditLimits',
   'token': token,
   'finance_token': financeToken,
   'operation_num': operationNum,
   'param': ['agrom'],
   'locale': 'ru'
}
```

