Your API requests are authenticated using API keys. Any request that doesn't include an API key will return an error.
Please fill out this form for an API key if you are new to 0x API, or get Data API enabled in your current key through the existing communication channel.
A note on GraphQL
The 0x Tx History API is a GraphQL API, not a REST API. GraphQL takes a more modern approach to building APIs by using a type system and allowing for more flexible requests. See more in https://graphql.org/learn/.
In the headers section add a new header called 0x-api-key and use your API Key as the value.
The explorer should load the available types to start building a query.
Programmatic Access
asyncfunctionfetchGraphQL(operationsDoc, operationName, variables) {constresult=awaitfetch("https://api.0x.org/data/v0", { method:"POST", headers: {'0x-api-key':'USE_APY_KEY_HERE' }, body:JSON.stringify({ query: operationsDoc, variables: variables, operationName: operationName }) } );returnawaitresult.json();}constoperationsDoc=` query Chains { chains { name namespace reference uuid } }`;functionfetchChains() {returnfetchGraphQL( operationsDoc,"Chains", {} );}asyncfunctionstartFetchChains() {const { errors,data } =awaitfetchChains();if (errors) {// handle those errors like a proconsole.error(errors); }// do something great with this precious dataconsole.log(data);}startFetchChains();java
Install dependencies
pipinstallgql
Save the following as get_chains.py
from gql import Client, gqlfrom gql.transport.aiohttp import AIOHTTPTransport# Select your transport with a defined url endpointtransport =AIOHTTPTransport( url="https://api.0x.org/data/v0", headers={"0x-api-key": "YOUR API KEY GOES HERE"},)# Create a GraphQL client using the defined transportclient =Client(transport=transport, fetch_schema_from_transport=True)# Provide a GraphQL queryquery =gql(""" query getChains { chains { name namespace reference } }""")# Execute the query on the transportresult = client.execute(query)print(result)
Run with
pythonget_chains.py
More examples can be found in each of the types in the Reference section.