Create checkout example not working

Solved

Create checkout example not working

Rachio_Co
Excursionist
14 1 1

Hello all. I'm having some trouble creating checkouts...

 

I've

1) Created an app in my partner dashboard

2) Configured it to be a sales channel

3) Installed it on a development store

4) Setup a call that looks like this https://help.shopify.com/en/api/guides/sell-through-the-checkout-api#creating-a-checkout. Actual call:

const orderJson = {
    "checkout":{
      "email": "john.smith@example.com",
      "line_items": [{
        "variant_id": 19357625483360,
        "quantity": 1
      }],
      "shipping_address": {
        "first_name": "John",
        "last_name": "Smith",
        "address1": "126 York St.",
        "city": "Denver",
        "province_code": "CO",
        "country_code": "US",
        "phone": "(123)456-7890",
        "zip": "80204"
      }
    }
  }

  const url = `https://my-dev-store.myshopify.com/admin/api/2019-04/checkouts.json`

  const shopRequestHeaders = {
    'X-Shopify-Access-Token': 'MY-PERM-TOKEN',
    'Content-Type': 'application/json'
  }

    fetch(
      url,
      {method: 'POST', body:JSON.stringify(orderJson), headers: shopRequestHeaders }
    ).then(resp => resp.json()).then(resp => console.log(JSON.stringify(resp))).catch(err => console.error(JSON.stringify(err)))
  })

And I get back a response that looks like:

{"errors":{"line_items":{"0":{"variant_id":[{"code":"invalid","message":"is invalid","options":{}}]}}}}

 

The variant ID should be correct (pulled it from the product's XML page). What else should I look at/check?

 

Thanks in advance,

Dan

Accepted Solution (1)
Rachio_Co
Excursionist
14 1 1

This is an accepted solution.

It was a scopes issue. I needed to request the following scopes:

 

`write_checkouts,read_product_listings, unauthenticated_read_product_listings, unauthenticated_write_checkouts, unauthenticated_write_customers, unauthenticated_read_customer_tags`

 

Not 100% sure I needed all of them, but I requested all the unauthenticated scopes I could, re-installed and it worked 🙂

View solution in original post

Replies 16 (16)

Jason
Shopify Partner
11201 226 2311

There's a bunch of context that I'm missing here but will start with a quick question. Is that product published on that sales channel?

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
Rachio_Co
Excursionist
14 1 1

Thanks for the reply. It wasn't. When I try to add the product to that sales channel, it's not listed as an option.

 

Screen Shot 2019-05-04 at 10.25.09 AM.png

 

Could it be a scopes thing? Current scopes I'm passing/requesting are

'write_checkouts,read_product_listings'

Thanks,

Dan

Rachio_Co
Excursionist
14 1 1

Also, happy to provide any context that would be helpful...

 

Dan

Josh
Shopify Staff
1134 84 235

Hey Dan, 

 

How is it that you got the Sales Channel installed on your shop? Was this with the 'Install on development shop/store' (sorry, forgot the exact wording) button from the Partner Dashboard? 

Josh | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Rachio_Co
Excursionist
14 1 1

yes

Rachio_Co
Excursionist
14 1 1

Well, as I think about it, it may have been through the link specified here https://help.shopify.com/en/api/tutorials/build-a-shopify-app-with-node-and-express#step-6-run-your-...

Rachio_Co
Excursionist
14 1 1

Happy to re-do any part of the setup if it'll clear anything up

Josh
Shopify Staff
1134 84 235

Hey again Dan, 

 

I think that's worth a shot for sure - something seems off about your installation but it's difficult to put a finger on exactly what that might be. I have a test Sales Channel and every time I install that it appears in the 'Apps' section of my shop admin, whereas yours does not. 

 

Can you try the 'Install on development store' option from the Partner Dashboard? If you log into your Partner account and find your app, the option will be under the 'App actions' drop-down menu near the top of the page.

Josh | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Rachio_Co
Excursionist
14 1 1

Thanks for the reply Josh,

It shows up under "Sales Channels" but doesn't allow me to add any products to it 😞

 

Dan

Rachio_Co
Excursionist
14 1 1

See /c/image/serverpage/image-id/5840i00EA6FE061798AA0/image-size/large?v=1.0&px=999

Josh
Shopify Staff
1134 84 235

Hey again Dan, 

 

Sorry for the delay here - I've still been unable to replicate this, it's a tricky one. Would it be safe to assume you're still having the same problem? 

 

If you can confirm that this hasn't been resolved yet, I'll report it to our engineering team so they can investigate further. 

Josh | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Rachio_Co
Excursionist
14 1 1

This is an accepted solution.

It was a scopes issue. I needed to request the following scopes:

 

`write_checkouts,read_product_listings, unauthenticated_read_product_listings, unauthenticated_write_checkouts, unauthenticated_write_customers, unauthenticated_read_customer_tags`

 

Not 100% sure I needed all of them, but I requested all the unauthenticated scopes I could, re-installed and it worked 🙂

Josh
Shopify Staff
1134 84 235

Wow, that is very interesting - I was almost positive that I was copying your app scopes when trying to replicate. 

 

Very good information to have, thanks a lot for following up! 

Josh | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Vikas7819
Shopify Partner
24 1 4

Not working for me.. I have try all things but same error.

sardarusama4106
Tourist
15 0 0

Still having this problem, how to solve this?

sardarusama4106
Tourist
15 0 0

I'm still getting this error, products are listed in my app


@Rachio_Co wrote:

Hello all. I'm having some trouble creating checkouts...

 

I've

1) Created an app in my partner dashboard

2) Configured it to be a sales channel

3) Installed it on a development store

4) Setup a call that looks like this https://help.shopify.com/en/api/guides/sell-through-the-checkout-api#creating-a-checkout. Actual call:

const orderJson = {
    "checkout":{
      "email": "john.smith@example.com",
      "line_items": [{
        "variant_id": 19357625483360,
        "quantity": 1
      }],
      "shipping_address": {
        "first_name": "John",
        "last_name": "Smith",
        "address1": "126 York St.",
        "city": "Denver",
        "province_code": "CO",
        "country_code": "US",
        "phone": "(123)456-7890",
        "zip": "80204"
      }
    }
  }

  const url = `https://my-dev-store.myshopify.com/admin/api/2019-04/checkouts.json`

  const shopRequestHeaders = {
    'X-Shopify-Access-Token': 'MY-PERM-TOKEN',
    'Content-Type': 'application/json'
  }

    fetch(
      url,
      {method: 'POST', body:JSON.stringify(orderJson), headers: shopRequestHeaders }
    ).then(resp => resp.json()).then(resp => console.log(JSON.stringify(resp))).catch(err => console.error(JSON.stringify(err)))
  })

And I get back a response that looks like:

{"errors":{"line_items":{"0":{"variant_id":[{"code":"invalid","message":"is invalid","options":{}}]}}}}

 

The variant ID should be correct (pulled it from the product's XML page). What else should I look at/check?

 

Thanks in advance,

Dan