I'm struggling to import the orders for a Shopify development store using the httr package in R. Here's what I've tried.
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.
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"
)
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.