Make your first request
A short tutorial that sends one query to the Prescient GraphQL API with curl, JavaScript, or Python and reads the response.
In this tutorial you send the channelNames query and read its response. The query takes no arguments, so it is a good test that your key works.
What do you need?
Section titled “What do you need?”- An API key. See Create and revoke an API key.
- One of these tools:
curl, Node.js 18 or later, or Python 3 with therequestspackage.
In each example, replace YOUR_API_KEY with your key.
Send the query
Section titled “Send the query”-
Save your key in an environment variable, so the key is not in your code.
export PRESCIENT_API_KEY="YOUR_API_KEY" -
Send the request. Each example sends the same query to the same endpoint.
curl https://api.prescient-ai.io/graphql \-H "Authorization: apikey $PRESCIENT_API_KEY" \-H "Content-Type: application/json" \-d '{"query": "query { channelNames }"}'const response = await fetch('https://api.prescient-ai.io/graphql', {method: 'POST',headers: {Authorization: `apikey ${process.env.PRESCIENT_API_KEY}`,'Content-Type': 'application/json',},body: JSON.stringify({ query: 'query { channelNames }' }),});const { data, errors } = await response.json();if (errors) throw new Error(errors[0].message);console.log(data.channelNames);import osimport requestsresponse = requests.post("https://api.prescient-ai.io/graphql",headers={"Authorization": f"apikey {os.environ['PRESCIENT_API_KEY']}"},json={"query": "query { channelNames }"},)body = response.json()if body.get("errors"):raise RuntimeError(body["errors"][0]["message"])print(body["data"]["channelNames"]) -
Read the response. The
datafield has one entry for the query, and the entry is a list of names.Example response {"data": {"channelNames": ["EXAMPLE_CHANNEL"]}}The name in this response is an example. Your response has the source names of the channels in your workspace. If your key has a channel scope, the list has only the channels in that scope.
What if the request fails?
Section titled “What if the request fails?”If the key does not work, the response has an errors list and data is null. The HTTP status is still 200.
{ "errors": [ { "message": "Authentication failed. Check your token.", "locations": [{ "line": 1, "column": 9 }], "path": ["channelNames"] } ], "data": null}Check that the header starts with apikey, that you copied the full key, and that the key is not revoked or expired. See Authentication.
What do you do next?
Section titled “What do you do next?”- Use a channel name as a check on the
sourceChannelNamevalues thatmodeledMetricsreturns. - Copy the rows of a date range. See Pull modeled metrics for a date range.