shopr is a collection of functions that make it easy to interact with the Shopify REST Admin API from R. Currently, shopr only supports read operations (i.e. HTTP GET requests).
Check out this tutorial on setting up and using shopr!
# install.packages("devtools")
devtools::install_github("ben519/shopr")
To use the Shopify API, you first need to
- Create a Shopify Partner Account
- Create a Development Store (Recommended but not necessary)
- Generate API credentials from the Shopify admin
It’d be wise to read Shopify’s Getting Started article before tinkering with this package.
The functions in this package require three parameters to connect to a shop:
- shopURL (e.g. “https://my-test-store.myshopify.com”)
- APIKey (e.g. “a1b2c3”)
- APIPassword (e.g. “d4e5g6”)
For many functions, these are the only required parameters, although additional parameters may be given.
Perhaps the most useful function in this package is
shopr_get_orders()
. Here’s the simplest way to use it.
library(shopr)
shopr_get_orders(
shopURL = "https://my-test-store.myshopify.com",
APIKey = "abc123",
APIPassword = "def456"
)
This returns a list of
- orders (a data.table of orders)
- discount_applications (a data.table of discount applications associated with orders)
- discount_codes (a data.tabe of discount codes associated with orders)
- note_attributes (a data.table of note attributes associated with orders)
- tax_lines (a data.table of tax lines associated with orders)
- line_items (a data.table of line items associated with orders)
- shipping_lines (a data.table of shipping lines associated with orders)
- fulfillments (a data.table of fulfillment details associated with orders)
- refunds (a data.table of refunds associated with orders)
For shops with many orders, this is a lot of data. You can filter the
fields or rows using filter criteria like created_at_min,
processed_at_min, fulfillment_status, and other parameters. See
?shopr_get_orders
for more details.
Some resources (e.g. orders and products) require pagination to return a
large result set. As an example, suppose we have a shop with 1001
products and we want to fetch every product. Shopify allows a max return
size of 250 items per query (limit_per_page = 250
), so we’ll need to
make 5 queries to retrieve all the products. shopr handles pagination
internally so you don’t have to.