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.Â
Table of Contents
Create A Discount Code Using Postman In Shopify
Step 1: Generate API credentials from the Shopify admin
Â
-
- Log in to your Shopify admin
-
- Go to Apps – Manage private apps
Â
-
- 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
Â
-
- 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
Â
-
- {username} – The API key that you generated.
-
- {password} – The API password that you generated.
-
- {shop} – The name of your development store.
-
- {api-version} – The supported API version that you want to use.
-
- {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
Â
-
- Paste the URL above.
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"
}
}
Step 3: Verify The Result
In the Shopify Admin, Choose DiscountsÂ
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
Â
-
- Paste the URL above.
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"
}
}
Step 2: Verify the Updated Discount Code
In Admin, choose DiscountsÂ
As you can see, the discount code has been updated.Â
Shopify Wave Integration
Shopify Zoho-books Integration
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
Â
-
- Paste the URL above.
Then Click SEND
Response:
An empty array
Step 2: Verify the Result
In Admin, choose DiscountsÂ
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.
Hopefully, you can do it!