Getting started with Python
Company Data API querying example with Python

Request code

1
import requests
2
3
API_KEY = "qfNfdijpFhbhPhA7j2ZxvtEGkfv8DftTtmTEbnWN"
4
API_ENDPOINT = "https://api.craft.co/v1/query"
5
GRAPHQL_QUERY = """
6
query getCompany($domain: String!) {
7
company(domain: $domain) {
8
locations {
9
city
10
country
11
}
12
}
13
}
14
"""
15
16
request_headers= { "x-craft-api-key": API_KEY }
17
request_data = {
18
"query": GRAPHQL_QUERY,
19
"variables": { "domain": "facebook.com" }
20
}
21
22
response = requests.post(API_ENDPOINT, json=request_data, headers=request_headers, timeout=30)
23
response_data = response.json()
24
25
print(response_data)
Copied!
Make sure to replace qfNfdijpFhbhPhA7j2ZxvtEGkfv8DftTtmTEbnWN with your unique API key.

Response

The above command returns JSON structured like this:
1
{
2
"data": {
3
"company": {
4
"locations": [
5
{
6
"city": "Tokyo",
7
"country": "JP"
8
},
9
{
10
"city": "Ottawa",
11
"country": "CA"
12
},
13
{
14
"city": "Jakarta",
15
"country": "ID"
16
},
17
...
18
]
19
}
20
}
21
}
Copied!

Read more

Last modified 1yr ago
Copy link