From 6036093d1b22204eef5a39dab0d82b728f54f461 Mon Sep 17 00:00:00 2001 From: Idalith Bustos Date: Tue, 15 Jul 2025 16:10:32 -0700 Subject: [PATCH 1/3] Adding Section --- .../subgraphs/querying/managing-api-keys.mdx | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/website/src/pages/en/subgraphs/querying/managing-api-keys.mdx b/website/src/pages/en/subgraphs/querying/managing-api-keys.mdx index 0a16fca09f15..18589f2bbf94 100644 --- a/website/src/pages/en/subgraphs/querying/managing-api-keys.mdx +++ b/website/src/pages/en/subgraphs/querying/managing-api-keys.mdx @@ -26,6 +26,32 @@ A new window will pop up: ![Create API Key Window](/img/create-api-key.png) +## Using Your API Key + +> [!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. + +When you query The Graph from your dapp, you can use your API key in two ways: + +1. In the URL (Optimal Method for Subgraph Queries): + + Append the API Key directly to your query endpoint: + + ``` + https://gateway.thegraph.com/api//subgraphs/id/ + ``` + +> [!NOTE] This allows you to use various GraphQL client libraries to query Subgraphs and populate your application with indexed data. + +2. As a Bearer Token: + + Include your API Key in the request header for added security: + + ``` + Authorization: Bearer + ``` + +Check out [Querying from an App](/subgraphs/querying/from-an-application) for more details. + ## Manage API Keys 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. From 6284e6e5823d904d94386dd91597677021c94223 Mon Sep 17 00:00:00 2001 From: Idalith Bustos Date: Thu, 17 Jul 2025 17:30:59 -0700 Subject: [PATCH 2/3] Updating --- .../pages/en/subgraphs/querying/managing-api-keys.mdx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/website/src/pages/en/subgraphs/querying/managing-api-keys.mdx b/website/src/pages/en/subgraphs/querying/managing-api-keys.mdx index 18589f2bbf94..5764353a6d16 100644 --- a/website/src/pages/en/subgraphs/querying/managing-api-keys.mdx +++ b/website/src/pages/en/subgraphs/querying/managing-api-keys.mdx @@ -32,19 +32,17 @@ A new window will pop up: When you query The Graph from your dapp, you can use your API key in two ways: -1. In the URL (Optimal Method for Subgraph Queries): +1. In the URL (optimal method for Subgraph queries): - Append the API Key directly to your query endpoint: + Include the API Key directly to your query endpoint: ``` https://gateway.thegraph.com/api//subgraphs/id/ ``` -> [!NOTE] This allows you to use various GraphQL client libraries to query Subgraphs and populate your application with indexed data. +2. As a bearer Token: -2. As a Bearer Token: - - Include your API Key in the request header for added security: + Include your API Key in the `Authorization` request header for added security: ``` Authorization: Bearer From 75a4e625715d8ce4094c0d0e22f2f3de176da569 Mon Sep 17 00:00:00 2001 From: Idalith Bustos Date: Fri, 18 Jul 2025 15:22:42 -0700 Subject: [PATCH 3/3] adding curl command example --- .../pages/en/subgraphs/querying/managing-api-keys.mdx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/website/src/pages/en/subgraphs/querying/managing-api-keys.mdx b/website/src/pages/en/subgraphs/querying/managing-api-keys.mdx index 5764353a6d16..136cbf1ef657 100644 --- a/website/src/pages/en/subgraphs/querying/managing-api-keys.mdx +++ b/website/src/pages/en/subgraphs/querying/managing-api-keys.mdx @@ -48,6 +48,16 @@ When you query The Graph from your dapp, you can use your API key in two ways: Authorization: Bearer ``` + Curl command example: + + ``` + curl -X POST \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer {api-key}" \ + -d '{"query": "{ graphNetworks(first: 5) { id controller graphToken epochManager } graphAccounts(first: 5) { id names { id } defaultName { id } createdAt } }", "operationName": "Subgraphs", "variables": {}}' \ + https://gateway.thegraph.com/api/subgraphs/id/DZz4kDTdmzWLWsV373w2bSmoar3umKKH9y82SUKr5qmp + ``` + Check out [Querying from an App](/subgraphs/querying/from-an-application) for more details. ## Manage API Keys