Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Why am I receiving 400 Bad Request errors when creating a delegate access token?

Why am I receiving 400 Bad Request errors when creating a delegate access token?

artooras
Shopify Partner
24 0 12

Hi. I'm trying to create a delegate access token as documented here, but I'm getting 400 Bad Request errors.

 

Here's how I execute the call inside my auth/callback route (both shop and accessToken values are successfully retrieved):

const shop = req.query.shop
const {accessToken} = await Shopify.Utils.loadOfflineSession(shop)

fetch(`https://${shop}/admin/access_tokens/delegate.json`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Shopify-Access-Token': accessToken
  },
  body: JSON.stringify({
    delegate_access_scope: 'read_products'
  })
})
.then(result => console.log(result))

 

Side note: aside from the linked page, I can't find this documented anywhere in the REST Admin API reference. Am I looking in the wrong place?

Replies 2 (2)

haytio735
Visitor
1 0 0

In my code I am also facing the similar kind of problems while solving an error if I solve one then other error occurs so pleaseguide me why its not working for me?

julio_briceno
Shopify Partner
1 0 0

It seems that delegate_access_scope expects a list of access_scopes, so you would need to change its value to ['read_products']

 

 

const shop = req.query.shop
const {accessToken} = await Shopify.Utils.loadOfflineSession(shop)

fetch(`https://${shop}/admin/access_tokens/delegate.json`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Shopify-Access-Token': accessToken
  },
  body: JSON.stringify({
    delegate_access_scope: ['read_products']
  })
})
.then(result => console.log(result))