beehexa integrationsidebar
beehexa logo

We Build HexaSync Integration Platform for Connecting ERP, POS, CRM, Accounting, and eCommerce Applications to Automate Business Processes

Create, Update, Delete A Discount Code

Shopify API 2024 – Create, Update, and Delete A Discount Code With Postman In Shopify

In a previous article, I showed you how to create a Price Rule with Postman, Price rule is a necessary condition to create a discount code. You can define the parameters for a discount with the Price Rule resource, but you’ll need to create associated discount codes for customers. I will show you how to create, update and delete a discount code with Postman In Shopify

Create A Discount Code Using Postman In Shopify

Step 1: Generate API credentials from the Shopify admin

     

      • Go to Apps – Manage private apps

    Generate API credentials from the Shopify admin

       

        • Click Create a new private app

        • In the App details section, enter a name for your app, and an emergency developer email

        • In the Admin API section, select the areas of your store that you want the app to access

      Generate API credentials from the Shopify admin

         

          • Click Save

        The Admin API section displays the app’s API key and password when you save the app’s details. 

        Step 2: Create a discount code using Postman in Shopify

        Before creating a discount code using Postman, you must create a Price Rule. Remember that Price Rule ID is to use in this step. 

           

            • Log in to your Postman and create a new workspace

            • Create a new POST with this URL:

          https://{username}:{password}@{shop}.myshopify.com/admin/api/{api-version}/{resource}.json

             

              1. {username} – The API key that you generated.

              1. {password} – The API password that you generated.

              1. {shop} – The name of your development store.

              1. {api-version} – The supported API version that you want to use.

              1. {resource} – A resource endpoint from the REST Admin API.

            Or you can copy this example in the Shopify Admin, remember to change {resource} to {price_rules/price rule ID/discount_codes}:

            https://33a72f01e02987636e1c1a9a4e95c840:[email protected]/admin/api/2021-10/price_rules/1001616998463/discount_codes.json

            Example URL

               

                • Paste the URL above.

              Post

              In the body section, enter this code, then click Send.

              {
                  "discount_code": {
                      "code": "SUMMERSALE10OFF"
                  }
              }

              Response:

              The API will return all information about the created discount code.

              {
                  "discount_code": {
                      "id": 12231414743103,
                      "price_rule_id": 1001616998463,
                      "code": "SUMMERSALE10OFF",
                      "usage_count": 0,
                      "created_at": "2021-12-16T16:44:57+09:00",
                      "updated_at": "2021-12-16T16:44:57+09:00"
                  }
              }

              Response

              Step 3: Verify The Result

              In the Shopify Admin, Choose Discounts 

              Result

              As you can see, the discount code has been created successfully.

              Update An Existing Discount Code Using Postman In Shopify

              Step1: Update An Existing Discount Code Using Postman In Shopify

                 

                  • Create a new PUT with this URL:

                https://{username}:{password}@{shop}.myshopify.com/admin/api/{api-version}/{resource}.json

                Or you can copy this example in the Shopify Admin,

                Remember to change {resource} to {price_rules/price rule ID/discount_codes/discount code ID}:

                https://33a72f01e02987636e1c1a9a4e95c840:[email protected]/admin/api/2021-10/price_rules/1001616998463/discount_codes/12231414743103.json
                
                

                Example URL

                   

                    • Paste the URL above.

                  Put

                  In the body section, enter this code, then click Send.

                  {
                      "discount_code": {
                          "Id":12231414743103,
                          "code": "WINTERSALE10OFF"
                      }
                  }
                  

                  Response:

                  The API will return all information about the updated discount code.

                  {
                      "discount_code": {
                          "id": 12231414743103,
                          "price_rule_id": 1001616998463,
                          "code": "WINTERSALE10OFF",
                          "usage_count": 0,
                          "created_at": "2021-12-16T16:44:57+09:00",
                          "updated_at": "2021-12-16T16:46:26+09:00"
                      }
                  }
                  

                  Response

                  Step 2: Verify the Updated Discount Code

                  In Admin, choose Discounts 

                  Result

                  As you can see, the discount code has been updated. 

                  Shopify Connector and Profile arrow Wave
                  Shopify Wave Integration
                  Shopify Connector and Profile arrow QuickBook
                  Shopify Quick-book Integration
                  Shopify Connector and Profile arrow Zoho Books
                  Shopify Zoho-books Integration
                  Shopify Connector and Profile arrow Sage Accounting
                  Shopify Sage Integration

                  Delete A Discount Code Using Postman In Shopify

                  Step 1: Delete A Discount Code Using Postman In Shopify

                     

                      • Create a new DELETE with this URL:

                    https://{username}:{password}@{shop}.myshopify.com/admin/api/{api-version}/{resource}.json

                    Or you can copy this example in the Shopify Admin, remember to change {resource} to {price_rules/price rule ID/discount_codes/discount code ID}:

                    https://33a72f01e02987636e1c1a9a4e95c840:[email protected]/admin/api/2021-10/price_rules/1001616998463/discount_codes/12231414743103.json

                    Example URL

                       

                        • Paste the URL above.

                      Delete

                      Then Click SEND

                      Response:

                      An empty array

                      Step 2: Verify the Result

                      In Admin, choose Discounts 

                      Result

                      As you can see, the discount code has been deleted. 

                      I have shown you all steps to create, update and delete a discount code with Shopify API using Postman. If you have any questions, please leave a comment below or refer to our blog: What is an API?. Besides, you can see more Shopify API documentation in the developer docs.

                      If you still do not understand the tutorial’s content, you can watch the video below for a more overview.

                      https://www.youtube.com/watch?v=w2Jihb1YVwA&t=4s
                      Shopify API – Create, Update, and Delete A Discount Code

                      Hopefully, you can do it!

                      Table of Contents

                      Ready to integrate and automate at scale ?

                      Learn how HexaSync lets you build enterprise-grade integrations and automations without having to code.

                      Receive Exclusive Productivity Tips Directly in Your Inbox

                      We’ll email you 1-3 times per week—and never share your information.

                      Get started for free

                      You can’t add more hours to the day. Beehexa is the next best thing.