401 error on post request when calling Checkout.json

shahrukhAhmed
Shopify Partner
23 0 2

I am trying to create a checkout, but I am getting a 401 error. Below is the code. Can't figure out why. The scopes are `unauthenticated_write_checkouts, unauthenticated_read_checkouts`, `read_orders and write_orders`. 

 

var headers = new Headers();
headers.append('Authorization', 'Basic ' + btoa('API key' + ':' + 'Password'));
headers.append( 'Content-Type', 'application/json')
headers.append( 'Accept', 'application/json')
headers.append( 'X-Shopify-Access-Token', 'Storefront access token')

fetch('https://store.myshopify.com/admin/api/2020-04/checkouts.json', {
  method: 'POST',
  headers: headers,
  credentials: 'same-origin',
  body: JSON.stringify( 
      {
        "checkout":{
          "line_items": [
            {
              "variant_id": 37538365309090,
              "quantity": 1
            }
          ]
        }
      }
    )
  } 
)
.then( response => {
  return response.json()
})
.then( data => {
  debugger;
  data;
})

 

 

0 Likes