Hi, I already lose over 10 hours trying to make this work… no luck!
from BASICS_v1 import *
import requests
import pandas as pd
import logging
import requests
import json
import shopify
class Test:
def init(self, api_key=shopify_api_key, api_secret=shopify_api_secret, token=shopify_token,
shop_url= shopify_shop_url, api_version= shopify_api_version 
self._shopify_api_key = api_key
self._shopify_api_secret = api_secret
self._shopify_token = token
self._shopify_shop_url = shop_url
self._shopify_api_version = api_version
self._folder = os.path.dirname(os.path.abspath(file))
self._headers = {
‘Content-Type’: ‘application/json’,
‘X-Shopify-Access-Token’: self._shopify_token
}
logging.basicConfig(filename=f’{self._folder}/error.log’, level=logging.ERROR)
self._session = shopify.Session(shop_url, api_version, token)
shopify.ShopifyResource.activate_session(self._session)
def update_products_in_bulk(self, product_data 
url = f"https://{self._shopify_shop_url}/admin/api/{self._shopify_api_version}/inventory_levels/set.json"
responses =
total_products = len(product_data)
print(f"Total products to update: {total_products}")
for i in range(0, total_products, 100 
batch = product_data[i:i + 100]
print(f"Processing batch {i//100 + 1}/{(total_products + 99) // 100}…")
json_payload = json.dumps({“inventory_levels” : batch}) # Trying to update on bulk = DO NOT WORK
json_payload_b = json.dumps(batch[0]) # Selecting only 1 dictionary from batch = WORKS
try:
response = requests.post(url, headers=self._headers, data=json_payload)
if response.status_code == 200:
responses.append(response.json())
print(f"Batch {i//100 + 1} update successful.“)
else:
print(f"Error updating batch {i//100 + 1}: Status Code {response.status_code}, Response: {response.text}”)
responses.append(response.json())
except json.JSONDecodeError as e:
print(f"JSON Decode Error: {str(e)} - Response text: ‘{response.text}’“)
except requests.RequestException as e:
print(f"Request failed: {str(e)}”)
return responses
def bulk_update_inventory(self, locationid=locationid, inventory_adjustments=None 
Define the mutation for bulk updating inventory quantities
mutation = “”"
mutation ($inventoryItemAdjustments: [InventoryAdjustItemInput!]!, $locationId: ID!) {
inventoryBulkAdjustQuantityAtLocation(inventoryItemAdjustments: $inventoryItemAdjustments, locationId: $locationId) {
inventoryLevels {
id
available
}
}
}
“”"
total_adjustments = len(inventory_adjustments)
responses =
for i in range(0, total_adjustments, 100 
batch = inventory_adjustments[i:i + 100]
Prepare the variables for the GraphQL mutation
inputs = {
“inventoryItemAdjustments”: batch,
“locationId”: f"gid://shopify/Location/{locationid}" # Example location ID, replace with actual ID
}
Execute the GraphQL mutation
response = shopify.GraphQL().execute(query=mutation, variables=inputs)
responses.append(response)
print(f"Processed batch {i//100 + 1}/{(total_adjustments + 99) // 100}: {response}")
Deactivate the session after the operation is complete
shopify.ShopifyResource.clear_session()
return responses
inventory= pd.read_pickle(f’{folder}/inventory’)[-20:]
Extract and adjust the relevant fields from the provided adjustments
simplified_adjustments = [
{‘location_id’: locationid,
‘inventory_item_id’: adj[‘inventory_item_id’],
‘available’: adj[‘available’]}
for adj in inventory
]
x= Test().update_products_in_bulk(simplified_adjustments) # WORK
Extract and adjust the relevant fields from the provided adjustments
simplified_adjustments = [
{“inventoryLevelId”: f"gid://shopify/InventoryItem/{adj[‘inventory_item_id’]}",
“locationId”: location,
“availableDelta”: int(adj[‘available’]),
}
for adj in inventory
]
x= Test().bulk_update_inventory(inventory_adjustments=simplified_adjustments) # DO NOT WORK
Does not matter what I do, I can only update 1 by 1 using requests, the same data used on GraphQL with Mutation never works
sample_data= [{‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49995823382866’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49995823415634’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49995823448402’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236281786706’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236281819474’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236281852242’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236281885010’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236281917778’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236281950546’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236281983314’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236282016082’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236282048850’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236282081618’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236282114386’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236282147154’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236282179922’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236282212690’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/49236282245458’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/42498772729991’, ‘availableDelta’: 0}, {‘inventoryLevelId’: ‘gid://shopify/InventoryItem/42535159529607’, ‘availableDelta’: 24}]
I tried add locationId, change the mutation, none work … the error on function above =
bulk_update_inventory()
A help would be VERY MUCH appreciated, I am doing this for my own web store… 
ERROR = Processed batch 1/1: {“errors”:[{“message”:“Field ‘inventoryBulkAdjustQuantityAtLocation’ doesn’t exist on type ‘Mutation’”,“locations”:[{“line”:3,“column”:9}],“path”:[“mutation”,“inventoryBulkAdjustQuantityAtLocation”],“extensions”:{“code”:“undefinedField”,“typeName”:“Mutation”,“fieldName”:“inventoryBulkAdjustQuantityAtLocation”}},{“message”:“Variable $inventoryItemAdjustments is declared by anonymous mutation but not used”,“locations”:[{“line”:2,“column”:9}],“path”:[“mutation”],“extensions”:{“code”:“variableNotUsed”,“variableName”:“inventoryItemAdjustments”}},{“message”:“Variable $locationId is declared by anonymous mutation but not used”,“locations”:[{“line”:2,“column”:9}],“path”:[“mutation”],“extensions”:{“code”:“variableNotUsed”,“variableName”:“locationId”}}]}