Use a Shopify Private App API via PowerShell for bulk management of your Shopify data.
Note that directly modifying Shopify data is risky, and you could end up deleting data accidentally -- make sure you know what you are doing and have a backup, e.g. downloaded CSV files or using a third-party backup app.
Examples are provided for the following operations:
- Managing postage rates, with examples for setting up standard Aus Post rates. See auspost-rates
- Bulk assigning Products to postage rates. See product-assign-rates
- Bulk managing Product attributes, with a focus on various attributes needed top satisfy postage rules, e.g. as EU product identifiers, USA HS Codes, and validation attributes such as those reported by Zonos (the customs service used by Australia Post)
This project contains PowerShell scripts that can be used to upload shipping rates to Shopify via the API.
You will need to have PowerShell Core (crossplatform) installed to run the scripts.
In the Shopfiy admin, go to Settings > Apps > Develop apps.
Can no longer create private apps; need to use Dev Dashboard
You will need to enable private apps, and then create a new app (call it something like "AusPost Rates" or "Data Manager", or whatever name makes sense to you). It will need Read and write permission to Shipping, as well as other functions you want to use, e.g. to use scripts to add products to shipping, you need Read access to Products.
Record the API parameters in variables, which will be used in other scripts. For graph queries you will need the 'Password' value (you don't need the API key for Shared Secret).
$password = '<Password>'
$shopName = '<shop name>'
First set up the base URL and headers, using the variables above.
$uri = "https://$shopName.myshopify.com/admin/api/2021-01/graphql.json"
$headers = @{
'Content-Type' = 'application/graphql';
'X-Shopify-Access-Token' = $password
}
A simple query can be used to retrieve data:
$body = '{
deliveryProfiles(first:10) {
edges {
node {
id
name
default
}
}
}
}'
Invoke-RestMethod -Method Post -Uri $uri -Headers $headers -Body $body | ConvertTo-Json -Depth 5
Parametised queries use application/json instead of raw application/graphql, with the query passed as a string
parameter (see one of the sections for a specific example).
$jsonHeaders = @{
'Content-Type' = 'application/json';
'X-Shopify-Access-Token' = $password
}
$getDeliveryProfileQuery = 'query($id: ID!)
{
deliveryProfile (id: $id) {
profileLocationGroups {
... // Rest of query
}
}
}'
$getDeliveryProfileData = @{
query = $getDeliveryProfileQuery;
variables = @{
id = $defaultProfileId;
}
}
$defaultProfileDetails = Invoke-RestMethod -Method Post -Uri $uri -Headers $jsonHeaders -Body (ConvertTo-Json -Depth 3 $getDeliveryProfileData)
$defaultProfileDetails | ConvertTo-Json -Depth 15
You can also interactively test out queries in the Shopify API developer documentation site: https://shopify.dev/docs/admin-api/graphql/reference/shipping-and-fulfillment/deliveryprofile#samples
See auspost-rates
Managing postage rates, with examples for setting up standard Aus Post rates.
Note: Unless you have specialised requirements, also consider using a third party app that can do this for your automatically.
Bulk assigning Products to postage rates.
TODO
Bulk managing Product attributes, with a focus on various attributes needed top satisfy postage rules, e.g. as EU product identifiers, USA HS Codes, and validation attributes such as those reported by Zonos (the customs service used by Australia Post)