Sending API requests

The Cyanite.ai GraphQL API is served over HTTP.

New to GraphQL?

GraphQL is a query language that is used for reading data from our service in comparison to traditional Restful APIs it has a strict and typed schema. Clients that consume a GraphQL API must send a query that specifies the data they are interested in. There is only a single /graphql endpoint in the GraphQL api.

We recommend checking out the official GraphQL Learning Resources for covering the basics.

We also have a Query Builder as well as a full generated GraphQL Schema Documentation that can help you explore the API.

HTTP endpoint#

The endpoint is compliant with the GraphQL over HTTP specification. Our API should be compatible with all major GraphQL clients.

GraphQL over HTTP

You can learn more over here: https://graphql.org/learn/serving-over-http/

We recommend sending requests to https://api.cyanite.ai/graphql via the POST method.

Example Request Body#

{
"query": "query LibraryTracksQuery { libraryTracks(first: 10) { edges { node { id } } } }",
"operationName": "...",
"variables": { "first": 10 }
}

Authentication#

For authentication the Authorization header must be set. It uses the Bearer format.

The HTTP header should look similar to this: Authorization: Bearer ACCESS_TOKEN. ACCESS_TOKEN should be replaced with the integration access token we created in the Creating an integration guide.

Example curl call#

curl is a command line utility for sending HTTP requests available in most shells.

curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ACCESS_TOKEN"\
--data '{ "query": "query LibraryTracksQuery { libraryTracks(first: 10) { edges { node { id } } } }", "variables": { "first": 10 } }' \
https://app.cyanite.ai/graphql

Example Javascript Fetch Call#

fetch is a standard library in modern JavaScript runtimes for sending HTTP requests.

fetch("https://app.cyanite.ai/graphql", {
method: "POST",
body: JSON.stringify({
query: {
query: /* GraphQL */ `
query LibraryTracksQuery {
libraryTracks(first: 10) {
edges {
node {
id
}
}
}
}
`,
variables: {
first: 10,
},
},
}),
headers: {
"Content-Type": "application/json",
Authorization: "Bearer" + "xxxxxx1212",
},
})
.then((res) => res.json())
.then(console.log);

GraphQL Playground#

caution

We sometimes embed GraphiQL in the documents which is a similar tool like GraphQL Playground. However, GraphQL Playground requires you to additionally configure the Authorization header and is not linked to the documentation.

The Cyanite.ai API Schema is introspectable. You can play around with the API by visiting our GraphQL Playground in your browser. Make sure you set the correct Authorization header in the HTTP Header section.

Screenshot: HTTP Header Section GraphQL Playground

You can start by copy-pasting the following JSON, make sure to replace ACCESS_TOKEN with your actual access token.

{
"Authorization": "Bearer ACCESS_TOKEN"
}