require 'net/http'
require 'json'
API_KEY = "<REPLACE_WITH_YOUR_KEY>"
API_ENDPOINT = "https://api.craft.co/v1/query"
GRAPHQL_QUERY = "query getCompany($domain: String!) { company(domain: $domain) { locations { city, country } } }"
request_headers= { "Content-Type": "application/json", "x-craft-api-key": API_KEY }
request_data = {
"query": GRAPHQL_QUERY,
"variables": { "domain": "meta.com" }
}
response = Net::HTTP.post(URI(API_ENDPOINT), request_data.to_json, request_headers)
puts response.body
{
"data": {
"company": {
"locations": [
{
"city": "Tokyo",
"country": "JP"
},
{
"city": "Ottawa",
"country": "CA"
},
{
"city": "Jakarta",
"country": "ID"
},
...
]
}
}
}