I’m struggling to import the orders for a Shopify development store using the httr package in R. Here’s what I’ve tried.
- I’ve created a development store and made some fake orders.
- Within my development store, I added a private app and generated my API key and Password
- 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
Update 2019-05-13
I created an R package called shopr for querying data via the Shopify API. Fetching orders looks like this
Old Answer
Figured it out.
The trick was to explicitly put "https://..." in the url otherwise httr was prepending "http://" to the url, causing my 401 problem.
You’re close. Try this: