> ## Documentation index
> Fetch the complete documentation index at: https://docs.prescientai.com/llms.txt
> Use this file to discover all available pages before exploring further. Add `.md` to any page URL to get that page as Markdown.

# 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?

- An API key. See [Create and revoke an API key](https://docs.prescientai.com/account/manage-api-keys).
- One of these tools: `curl`, Node.js 18 or later, or Python 3 with the `requests` package.

In each example, replace `YOUR_API_KEY` with your key.

## Send the query

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

   ```sh
   export PRESCIENT_API_KEY="YOUR_API_KEY"
   ```

2. Send the request. Each example sends the same query to the same endpoint.

   **curl**

   ```sh
   curl https://api.prescient-ai.io/graphql \
     -H "Authorization: apikey $PRESCIENT_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{"query": "query { channelNames }"}'
   ```

   **JavaScript**

   ```js
   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);
   ```

   **Python**

   ```python
   import os
   import requests

   response = 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"])
   ```

3. Read the response. The `data` field has one entry for the query, and the entry is a list of names.

   ```json title="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?

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

```json title="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](https://docs.prescientai.com/api/authentication).

## What do you do next?

- Use a channel name as a check on the `sourceChannelName` values that [`modeledMetrics`](https://docs.prescientai.com/api/queries/modeled-metrics) returns.
- Copy the rows of a date range. See [Pull modeled metrics for a date range](https://docs.prescientai.com/api/pull-modeled-metrics).
