GraphQL

Fetch (JavaScript)

A basic example using the browser's fetch API to query for Amazon data. You will need to modify the example to use your API-KEY in the request header. We have provided a full example using Codesandbox for testing purposes.

Note: It is generally not recommended to expose your API-KEY to the browser. This is okay for testing and proof of concepts but your key should not be exposed to clients in production.

const query = `
  query amazonProduct {
    amazonProduct(input: {asin: "B0B3JBVDYP"}) {
      title
      mainImageUrl
      rating
      price {
        display
      }
    }
  }
`

const response = await fetch('https://graphql.canopyapi.co/', {
  method: 'POST',
  mode: 'cors',
  headers: {
    'Content-Type': 'application/json',
    'API-KEY': '<YOUR_API_KEY>',
  },
  body: JSON.stringify({query}),
})
return response.json()

Edit summer-glade-knu16k

Previous
Playground