Skip to content
Open Prescient AI
Use the API

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.

In each example, replace YOUR_API_KEY with your key.

  1. Save your key in an environment variable, so the key is not in your code.

    export PRESCIENT_API_KEY="YOUR_API_KEY"
  2. 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 }"}'
  3. Read the response. The data field 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.

If the key does not work, the response has an errors list and data is null. The HTTP status is still 200.

Response
{
"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.