Getting started with JavaScript
Company Data API querying example with JavaScript

Request code

1
require('isomorphic-fetch');
2
3
API_KEY = 'qfNfdijpFhbhPhA7j2ZxvtEGkfv8DftTtmTEbnWN';
4
API_ENDPOINT = 'https://api.craft.co/v1/query';
5
GRAPHQL_QUERY = 'query getCompany($domain: String!) { company(domain: $domain) { locations { city, country } } }';
6
7
requestHeaders= { 'Content-Type': 'application/json', 'x-craft-api-key': API_KEY };
8
requestData = { 'query': GRAPHQL_QUERY, 'variables': { 'domain': 'facebook.com' } };
9
10
fetch(API_ENDPOINT, {
11
method: 'POST',
12
headers: requestHeaders,
13
body: JSON.stringify(requestData),
14
})
15
.then(function(response) { return response.json() })
16
.then(console.log)
17
.catch(console.error);
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