skip to Main Content

I’m struggling to import the orders for a Shopify development store using the httr package in R. Here’s what I’ve tried.

  1. I’ve created a development store and made some fake orders.
  2. Within my development store, I added a private app and generated my API key and Password
  3. Following this article, I tried implementing the following request

Code

apikey <- "foo"
pass <- "bar"

shop <- GET(
  url = "my-test-store.myshopify.com/orders.json", 
  authenticate(user = apikey, password = pass)
)

But this gives a 401 status code. However, this works but returns xml instead of json

shop <- GET(
  url = "my-test-store.myshopify.com/orders", 
  authenticate(user = apikey, password = pass)
)

How can I retrieve the results as JSON instead of XML?

Note that I can also fetch the orders using the R package shopifyr but would rather not use that package as it is no longer maintained.

2

Answers


  1. Chosen as BEST ANSWER

    Update 2019-05-13

    I created an R package called shopr for querying data via the Shopify API. Fetching orders looks like this

    library(shopr)
    
    shopr_get_orders(
      shopURL = "https://my-test-store.myshopify.com", 
      APIKey = "abc123", 
      APIPassword = "def456"
    )
    

    Old Answer

    Figured it out.

    orders <- GET(
      url = "https://my-test-store.myshopify.com/admin/orders",
      add_headers(Accept = "application/json"),
      authenticate(user = apikey, password = pass)
    )
    orders
    

    The trick was to explicitly put "https://..." in the url otherwise httr was prepending "http://" to the url, causing my 401 problem.


  2. You’re close. Try this:

    library(httr)
    
    apikey <- "foo"
    pass <- "bar"
    
    orders <- GET(
      url = "https://yourshop.myshopify.com/admin/orders.json", 
      authenticate(user = apikey, password = pass)
    )
    
    content(orders)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search