Getting started with Ruby
Company Data API querying example with Ruby

Request

1
require 'net/http'
2
require 'json'
3
4
API_KEY = "qfNfdijpFhbhPhA7j2ZxvtEGkfv8DftTtmTEbnWN"
5
API_ENDPOINT = "https://api.craft.co/v1/query"
6
GRAPHQL_QUERY = "query getCompany($domain: String!) { company(domain: $domain) { locations { city, country } } }"
7
8
request_headers= { "Content-Type": "application/json", "x-craft-api-key": API_KEY }
9
request_data = {
10
"query": GRAPHQL_QUERY,
11
"variables": { "domain": "facebook.com" }
12
}
13
14
response = Net::HTTP.post(URI(API_ENDPOINT), request_data.to_json, request_headers)
15
puts response.body
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