Update Shopify Product Quantity using PowerShell via API

Here in this script, I have laid out the commands needed to update the quantity of a product. Adding in foreach to loop through multiple products will help with bulk uploads.

If you are looking to update the price of a Shopify product using API, check out this post here.

If you are looking for my help with getting a script created to help with bulk upload (for a service fee), reach out to me.

## Required Variables
$apiToken = "<your-token>"
$apiKey = "<you-api-key>"
$basestoreURL = "<your-shopify-store>.myshopify.com/"
$library = "2023-10"
$inventoryItemID = "<Item-Level-ID>"
$qty = "<the-new-quantity>"
$inventoryItemsURL = "inventory_levels/set.json"
$locationID = "<your-location-id>"
#################################
## API Header
#################################
$headers = @{
    "Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($apikey+":"+$apiToken))
    "Content-Type" = "application/json"
} 
###################################
## Base URL reset
###################################
$uri = "https://" + $basestoreURL + "admin/api/" + $library + "/" + $inventoryItemsURL
###################################
## Post to Shopify
###################################
$postbody = [pscustomobject]@{
    location_id = $locationID
    inventory_item_id = $inventoryItemID
    available = $qty
} | convertTo-json
$results = Invoke-WebRequest -Method POST -Uri $uri -Header $headers -Body $postbody -UseBasicParsing
Write-host "Response code:" $results.StatusCode
 

Sign Up to get updates on the latest article

Get the latest from my blog when you sign up.  Special offers are only offered to those who sign up.  Specific DIY are emailed to users when they become available.  Sign up today to get notified.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.