Welcome to the Bulk Update Inventory with Shopify API template! This template is designed to help you integrate with the Shopify API to manage inventory levels efficiently. With this template, you can quickly set up an application that allows you to bulk update inventory levels and fetch current inventory statuses for products in a Shopify store. This is particularly useful for store owners or developers looking to automate inventory management tasks.
To begin using this template, click on "Start with this Template" in the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy or paste any code manually.
Before you can test and use the application, you need to set up an environment secret that the application requires:
SHOPIFY_ADMIN_API_TOKEN
: This is the Shopify admin API token used for authenticating requests to the Shopify GraphQL API.To obtain your Shopify admin API token, follow these steps:
Once you have your Shopify admin API token, go to the Environment Secrets tab within the Lazy Builder and add a new secret with the key SHOPIFY_ADMIN_API_TOKEN
and paste the token you copied as the value.
After setting up the environment secret, you can press the "Test" button in the Lazy platform. This will begin the deployment of the app and launch the Lazy CLI.
Once the app is deployed, if the code requires user input, the Lazy CLI will prompt you to provide the necessary information. For this template, you will need to input the store URL and location ID when prompted by the CLI.
After deployment, Lazy will provide you with a dedicated server link to use the API. Additionally, since this template uses FastAPI, you will also receive a link to the API documentation, which you can use to interact with the endpoints provided by the application:
/bulk_update_inventory
: A POST endpoint that allows you to send a JSON payload with the store URL, location ID, and a list of inventory updates to bulk update inventory levels./fetch_inventory_levels
: A GET endpoint that retrieves the inventory levels for a specific location in a Shopify store, requiring the store URL and location ID as query parameters.Here is an example of how to make a request to the /bulk_update_inventory
endpoint:
POST /bulk_update_inventory
Content-Type: application/json
{
"store_url": "your-shopify-store.myshopify.com",
"location_id": "gid://shopify/Location/123456789",
"updates": [
{
"inventory_item_id": "gid://shopify/InventoryItem/987654321",
"available_delta": 10
}
]
}
And you should expect a response similar to this:
{
"inventoryLevels": [
{
"id": "gid://shopify/InventoryLevel/123456789",
"available": 110
}
]
}
If you wish to integrate this app with other tools or services, you may need to use the server link provided by Lazy to set up webhooks or API calls from those external tools. Ensure that you have the correct permissions and scopes set up in Shopify to allow for inventory updates.
For example, if you're using a third-party inventory management tool, you might need to add the server link as an endpoint in that tool's settings, allowing it to send inventory update requests to your Lazy app.
By following these steps, you should be able to set up and use the Bulk Update Inventory with Shopify API template on the Lazy platform to manage your Shopify store's inventory levels efficiently.