Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shayanabbas/fbb4e728898c0ac4743ae79f295af77e to your computer and use it in GitHub Desktop.
Save shayanabbas/fbb4e728898c0ac4743ae79f295af77e to your computer and use it in GitHub Desktop.
Import product to Shopify store using POST request to its API

Posting product details to a Shopify store to create new products can be done using Shopify's API. As of 2023, Shopify provides a comprehensive API that allows you to interact with your store programmatically. Here's a step-by-step guide on how to do this:

Set Up a Shopify Private App:

Log in to your Shopify admin panel. Go to "Apps" and then choose "Manage private apps" (or similar, depending on the current Shopify layout). Create a new private app to obtain API credentials (API key and password) which are required for authentication.

Authentication:

Shopify API uses basic HTTP authentication. You will use the API key as the username and the password you got from your private app. Always use HTTPS to ensure security while making API calls.

Understand Shopify API Endpoints:

Shopify's REST API provides various endpoints. For products, the endpoint is typically /admin/api/2023-01/products.json (the version part in the URL '2023-01' might change based on the latest available API version).

Prepare Product Data:

Format the product data in JSON. A typical product creation POST request will include details like title, body (description), vendor, product type, and variants (like price, SKU).

Make a POST Request to Create a Product:

You will need to send a POST request to the product endpoint with the product data. You can use tools and libraries like curl, Postman, or programming languages like Python, PHP, etc., to make these requests.

Example of a POST Request (using curl):

curl -X POST "https://{your-store-name}.myshopify.com/admin/api/2023-01/products.json" \
     -u {api_key}:{password} \
     -H "Content-Type: application/json" \
     -d '{
           "product": {
             "title": "My Product Title",
             "body_html": "<strong>Great product!</strong>",
             "vendor": "My Vendor",
             "product_type": "My Product Type",
             "variants": [
               {
                 "option1": "First",
                 "price": "19.99",
                 "sku": "123"
               }
             ],
             "images": [
               {
                 "src": "http://example.com/rails_logo.gif"
               }
             ]
           }
         }'

Bulk Uploads:

For bulk product uploads, you'll need to script the process, iterating over your product list and making a POST request for each product. Ensure you handle rate limits as Shopify API has rate limiting.

Testing:

Test with a few products in a development or test Shopify store first.

Error Handling:

Implement proper error handling in your script to capture and respond to any issues during the upload process.

Stay Updated with API Changes:

Shopify updates its API regularly; ensure that your integration is updated with the latest API version and changes. This method requires programming knowledge and familiarity with working with APIs. If you're not comfortable with this level of technical work, it might be worth consulting with a developer or looking into third-party services or apps that can handle Shopify product imports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment