Ad

Difference Between Axios({method: "post"}) And Axios.post()

- 1 answer

I'm using Shopify Storefront API and Axios to develop locally a e-shop.

Shopify give me a response when I use axios(), but it returns 403 Forbidden when I do the same thing with axios.post().

What's the difference between those two?

axios.post(
    SHOPIFY_DOMAIN,
    {
    headers: {
        "Content-Type": "application/graphql",
        "X-Shopify-Storefront-Access-Token": SHOPIFY_TOKEN
    },
    data: `{ shop }`
})
axios({
  method: "post",
  url: SHOPIFY_DOMAIN,
  headers: {
    "Content-Type": "application/graphql",
    "X-Shopify-Storefront-Access-Token": SHOPIFY_TOKEN
  },
  data: `{ shop }`
})
Ad

Answer

The declaration of axios.post is axios.post(url[, data[, config]]). The correct way of using is:

axios.post(
    SHOPIFY_DOMAIN,
    `{ shop }`,
    {
        headers: {
            "Content-Type": "application/graphql",
            "X-Shopify-Storefront-Access-Token": SHOPIFY_TOKEN
        }
    }
);

See also: axios API

Ad
source: stackoverflow.com
Ad