Skip to content

Commit 9e4d9e0

Browse files
authored
Adding Section (#1011)
* Adding Section * Updating * adding curl command example
1 parent 379fe96 commit 9e4d9e0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

website/src/pages/en/subgraphs/querying/managing-api-keys.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,40 @@ A new window will pop up:
2626

2727
![Create API Key Window](/img/create-api-key.png)
2828

29+
## Using Your API Key
30+
31+
> [!IMPORTANT] Always keep your API key in environment variables or a secure secrets manager. Do not hardcode it in your codebase or expose it in client-side apps.
32+
33+
When you query The Graph from your dapp, you can use your API key in two ways:
34+
35+
1. In the URL (optimal method for Subgraph queries):
36+
37+
Include the API Key directly to your query endpoint:
38+
39+
```
40+
https://gateway.thegraph.com/api/<YOUR_API_KEY>/subgraphs/id/<SUBGRAPH_ID>
41+
```
42+
43+
2. As a bearer Token:
44+
45+
Include your API Key in the `Authorization` request header for added security:
46+
47+
```
48+
Authorization: Bearer <YOUR_API_KEY>
49+
```
50+
51+
Curl command example:
52+
53+
```
54+
curl -X POST \
55+
-H "Content-Type: application/json" \
56+
-H "Authorization: Bearer {api-key}" \
57+
-d '{"query": "{ graphNetworks(first: 5) { id controller graphToken epochManager } graphAccounts(first: 5) { id names { id } defaultName { id } createdAt } }", "operationName": "Subgraphs", "variables": {}}' \
58+
https://gateway.thegraph.com/api/subgraphs/id/DZz4kDTdmzWLWsV373w2bSmoar3umKKH9y82SUKr5qmp
59+
```
60+
61+
Check out [Querying from an App](/subgraphs/querying/from-an-application) for more details.
62+
2963
## Manage API Keys
3064

3165
The “API keys” table lists existing API keys and allows you to manage or delete them. For each key, you can see its status, the cost for the current period, the spending limit for the current period, and the total number of queries.

0 commit comments

Comments
 (0)