Read Shopify Inventory Items

Updated: Oct 30, 2023

This example shows how to read inventory items for a Shopify store's location and save them in a JSON file.  The target can be changed to any format DataPipeline supports (like CSV, XML, Parquet, etc.).  The pipeline's job can also include filters, transformations, and lookups to fit your use-case. 

For this example, we'll need:

  1. A Shopify custom app.
  2. An ACCESS_TOKEN and the store's DOMAIN.

For information on how to create a custom app and obtain an access key visit Shopify custom apps.

Java Code Listing

package com.northconcepts.datapipeline.examples.shopify;

import com.northconcepts.datapipeline.core.DataReader;
import com.northconcepts.datapipeline.core.DataWriter;
import com.northconcepts.datapipeline.job.Job;
import com.northconcepts.datapipeline.json.JsonRecordWriter;
import com.northconcepts.datapipeline.shopify.ShopifyInventoryItemReader;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

public class ReadShopifyInventoryItems {

    private static final String DOMAIN = "https://your-store-domain.com";
    private static final String ACCESS_TOKEN = "ACCESS_TOKEN";
    
    public static void main(String[] args) throws FileNotFoundException {
        DataReader reader = new ShopifyInventoryItemReader(DOMAIN, ACCESS_TOKEN)
            .setIds("49129939697963", "49129939730731", "49129939763499", "49129939796267", "49129939829035");

        File file = new File("data/output/inventory-items.json");
        DataWriter writer = new JsonRecordWriter(new OutputStreamWriter(new FileOutputStream(file))).setPretty(true);

        Job.run(reader, writer);
    }
    
}


Code Walkthrough

  1.  An instance of ShopifyLocationReader which takes DOMAIN and ACCESS_TOKEN as arguments is created. This will be used to read a list of Shopify locations.
  2. Job.run() is then used to transfer data from the reader to JsonRecordWriter.

 

 

Mobile Analytics