PRJ – 24

Recently, I have been working on a consumer which sits inside the MLC business API. This consumer will communicate with the Shopify Admin GraphQL API in order to compare inventory levels of products on Shopify against their corresponding products in the stock information database of MLC. If the stock levels differ, the Shopify inventory levels will be updated to match the stock levels in the database. This is comparison is to be completed once at 12:00 AM everyday.

There are five main parts to creating this consumer, these are as follows:

  1. Retrieve all product inventory data from the Shopify API
  2. Retrieve the corresponding products from the MLC database
  3. Compare the stock levels and establish the difference and if an update needs to be made
  4. Update the Shopify inventory data using the Shopify API
  5. Schedule this process to run once daily at 12 AM.

Retrieve all product inventory data from the Shopify API
First I set up a development store where I will be testing this consumer. Next I followed the tutorial provided by Shopify to connect to the GraphQL API. Afterwards I set up a function inside my consumer which is using this GraphQL query object to retrieve inventory levels as well as SKU (Stock Keep Unit) for the test products I created in my development store. These SKU codes match the product codes in the MLC database.

Retrieve the corresponding products from the MLC database
Thanks to the convenience of the MLC GraphQL API, a query already exists for me to get the required data I need from the MLC database. I created another function which uses this query and retrieves products by ID using the SKU codes I retrieved in the first step.

Compare the stock levels and establish the difference and if an update needs to be made
Now that I have the data from both Shopify and the MLC database, I can compare the stock levels in each and calculate the difference. Again, I made a function which compares the data and returns the a new array containing the Shopify product ID and the stock update value which is the difference in stock. This value can be a positive or negative integer. Negative deducting from the stock on shopify and positive adding to it.

Update the Shopify inventory data using the Shopify API
The Shopify API provides this mutation I can use to bulk adjust inventory levels. Using the new array I got from the step above, I can send this to the Shopify API which then updates the Shopify product inventory levels for me.

Schedule this process to run once daily at 12 AM
I will use this package in order to schedule this process.

Leave a comment

Design a site like this with WordPress.com
Get started