---
title: "Create DiscountCode"
description: "Create promo code"
doc_type: openapi
doc_category: openapi
doc_version: v20260901
source_url:
  html: 'https://developer.shopline.com/docs/admin-rest-api/marketing/discount-code/create-discount-code'
  md: 'https://developer.shopline.com/docs/admin-rest-api/marketing/discount-code/create-discount-code.md'
---
# Create DiscountCode

Create promo code

- **Base URL:** `https://{handle}.myshopline.com/admin/openapi`
- **Required Scopes:** `write_discounts`
- **API Version:** v20260901
- **API Type:** Admin
- **API Protocol:** RESTful

## Endpoint

```http
POST /sales/price_rules/:price_rule_id/discount_codes.json
```

## Base URL

* `https://{handle}.myshopline.com/admin/openapi`

  * `{handle}`: `handle` : The store's unique identifier, which is the prefix of the store's domain name. For example, if a store's domain name is `open001.myshopline.com` , the store handle is `open001` .

## Required Permissions

* `write_discounts`

## Request

### Path Parameters

* `price_rule_id`

  string (required)

  Price rule id

### Request Headers

* `Content-Type`

  string (required)

  The field must be set to the fixed value `application/json; charset=utf-8`.

* `Authorization`

  string (required)

   The access token for the API resource. Refer to [App authorization](https://developer.shopline.com/docs/apps/api-instructions-for-use/app-authorization.md?lang=en) to obtain the access token, and then pass the obtained token in the Bearer format. 

### Request Body

* `discount_code`

  object

  discount code

  * `code`

    string

    Discount code content

  * `price_rule_id`

    string

    Discount code rules id

## Response

### Status Codes

* `200`

  For the complete list of codes and messages, see [Http status code](https://developer.shopline.com/docs/apps/api-instructions-for-use/http-status-code.md?lang=en).

* `401`

  

* `429`

  

### Response Headers

* `traceId`

  A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise.

### Response Body

#### 200

* `discount_code`

  object

  Discount code entity

  * `update_at`

    string

    Update time for discount code

  * `usage_count`

    integer

    Number of times used in discount codes

  * `code`

    string

    Discount code content

  * `create_at`

    string

    Discount code created time

  * `id`

    string

    Id for discount code

  * `price_rule_id`

    string

    Id for discount price rule


#### 401

* `errors`

  string

  Error message. 


#### 429

* `errors`

  string

  Error message. 


## OpenAPI Definition

```json
{
  "description": "Create promo code",
  "externalDocs": {
    "description": "Permission point used by the interface is `write_discounts` , For more information about the use of permission points, see",
    "url": "ec20/3cv5d7wpfgr6a8z5/xabczf5442284vkq?lang=en",
    "errorTableDescription": ""
  },
  "operationId": "NZxEIBPL",
  "parameters": [
    {
      "name": "price_rule_id",
      "in": "path",
      "description": "Price rule id",
      "required": true,
      "style": "simple",
      "schema": {
        "name": "price_rule_id",
        "description": "Price rule id",
        "type": "string",
        "example": "6018703930879383908"
      },
      "example": "6018703930879383908",
      "examples": {
        "Create discount codes": {
          "value": "6062017087609511417"
        },
        "Create distribution discount codes": {
          "value": "6019132058521049481"
        }
      }
    },
    {
      "name": "Content-Type",
      "in": "header",
      "description": "The field must be set to the fixed value `application/json; charset=utf-8`.",
      "required": true,
      "style": "string",
      "schema": {
        "name": "Content-Type",
        "type": "string",
        "example": "application/json; charset=utf-8"
      }
    },
    {
      "name": "Authorization",
      "in": "header",
      "description": " The access token for the API resource. Refer to [App authorization](https://developer.shopline.com/docs/apps/api-instructions-for-use/app-authorization.md?lang=en) to obtain the access token, and then pass the obtained token in the Bearer format. ",
      "required": true,
      "style": "string",
      "schema": {
        "name": "Authorization",
        "description": " The access token for the API. Please refer to [App authorization](https://developer.shopline.com/docs/apps/api-instructions-for-use/app-authorization.md?lang=en) to obtain the access token, and then put the obtained access token into the API request header in Bearer Token.",
        "type": "string",
        "example": "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MCwiYXBwS2V5IjoiNzU2ZjI1NWE2NjdlZTcwNTk1MzM0ZjVjYzk4NzU5MzBmN2E3NGZjMSIsImV4cCI6MTg3OTQ4MjA3NiwiaXNzIjoieXNvdWwiLCJzZWxsZXJJZCI6IjIwMDAyMzQ4ODAiLCJzdG9yZUlkIjoiMTY3MjM2OTcyOTYwNiIsInRpbWVzdGFtcCI6MTc4NDc4NzY3NjY2MSwidmVyc2lvbiI6IlYyIn0.3ZzbGAH4cLU1QR2VPEvMOQInUDvus-C4amkINSQIPuNVlXsFKj0sAt1c0KnUy9MWUOFV9cHlkf7J90r2y1FzpA"
      },
      "example": "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MCwiYXBwS2V5IjoiNzU2ZjI1NWE2NjdlZTcwNTk1MzM0ZjVjYzk4NzU5MzBmN2E3NGZjMSIsImV4cCI6MTg3OTQ4MjA3NiwiaXNzIjoieXNvdWwiLCJzZWxsZXJJZCI6IjIwMDAyMzQ4ODAiLCJzdG9yZUlkIjoiMTY3MjM2OTcyOTYwNiIsInRpbWVzdGFtcCI6MTc4NDc4NzY3NjY2MSwidmVyc2lvbiI6IlYyIn0.3ZzbGAH4cLU1QR2VPEvMOQInUDvus-C4amkINSQIPuNVlXsFKj0sAt1c0KnUy9MWUOFV9cHlkf7J90r2y1FzpA"
    }
  ],
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "discount_code": {
              "name": "discount_code",
              "description": "discount code",
              "type": "object",
              "properties": {
                "code": {
                  "name": "code",
                  "description": "Discount code content",
                  "type": "string",
                  "example": "DISCOUNT_CODE_CONTENT"
                },
                "price_rule_id": {
                  "name": "price_rule_id",
                  "description": "Discount code rules id",
                  "type": "string",
                  "example": "6018703930879383908\n"
                }
              },
              "required": [
                "code"
              ],
              "example": {
                "price_rule_id": "6018703930879383908\n",
                "code": "DISCOUNT_CODE_CONTENT"
              }
            }
          },
          "example": {
            "discount_code": {
              "price_rule_id": "6018703930879383908\n",
              "code": "DISCOUNT_CODE_CONTENT"
            }
          }
        },
        "examples": {
          "Create discount codes": {
            "value": {
              "discount_code": {
                "code": "DISCOUNT_CODE_CONTENT_1",
                "price_rule_id": "6062017087609511417"
              }
            }
          },
          "Create distribution discount codes": {
            "value": {
              "discount_code": {
                "code": "AFFILLIATE_DISCOUNT_CODE",
                "price_rule_id": "6019132058521049481"
              }
            }
          }
        }
      }
    },
    "required": true
  },
  "responses": {
    "200": {
      "description": "For the complete list of codes and messages, see [Http status code](https://developer.shopline.com/docs/apps/api-instructions-for-use/http-status-code.md?lang=en).",
      "headers": {
        "traceId": {
          "description": "A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise."
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "discount_code": {
                "name": "discount_code",
                "description": "Discount code entity",
                "type": "object",
                "properties": {
                  "update_at": {
                    "name": "update_at",
                    "description": "Update time for discount code",
                    "type": "string",
                    "example": "2023-07-12T00:08:02+08:00"
                  },
                  "usage_count": {
                    "name": "usage_count",
                    "description": "Number of times used in discount codes",
                    "type": "integer",
                    "example": 0
                  },
                  "code": {
                    "name": "code",
                    "description": "Discount code content",
                    "type": "string",
                    "example": "DISCOUNT_CODE_CONTENT"
                  },
                  "create_at": {
                    "name": "create_at",
                    "description": "Discount code created time",
                    "type": "string",
                    "example": "2023-07-12T00:08:02+08:00"
                  },
                  "id": {
                    "name": "id",
                    "description": "Id for discount code",
                    "type": "string",
                    "example": "6019053959104174638"
                  },
                  "price_rule_id": {
                    "name": "price_rule_id",
                    "description": "Id for discount price rule",
                    "type": "string",
                    "example": "6018703930879383908"
                  }
                },
                "example": {
                  "id": "6019053959104174638",
                  "price_rule_id": "6018703930879383908",
                  "update_at": "2023-07-12T00:08:02+08:00",
                  "usage_count": 0,
                  "code": "DISCOUNT_CODE_CONTENT",
                  "create_at": "2023-07-12T00:08:02+08:00"
                }
              }
            },
            "example": {
              "discount_code": {
                "code": "DISCOUNT_CODE_CONTENT",
                "create_at": "2023-07-12T00:08:02+08:00",
                "id": "6019053959104174638",
                "price_rule_id": "6018703930879383908",
                "update_at": "2023-07-12T00:08:02+08:00",
                "usage_count": 0
              }
            }
          },
          "examples": {
            "Create discount codes": {
              "value": {
                "discount_code": {
                  "code": "DISCOUNT_CODE_CONTENT_1",
                  "create_at": "2023-08-10T15:45:03+08:00",
                  "id": "6062034195202449185",
                  "price_rule_id": "6062017087609511417",
                  "update_at": "2023-08-10T15:45:03+08:00",
                  "usage_count": 0
                }
              }
            },
            "Create distribution discount codes": {
              "value": {
                "discount_code": {
                  "id": "6062073148844549600",
                  "price_rule_id": "6019132058521049481",
                  "update_at": "2023-08-10T16:23:45+08:00",
                  "usage_count": 0,
                  "code": "AFFILLIATE_DISCOUNT_CODE",
                  "create_at": "2023-08-10T16:23:45+08:00"
                }
              }
            }
          }
        }
      }
    },
    "401": {
      "headers": {
        "traceId": {
          "description": "A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise."
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "errors": {
                "description": "Error message. ",
                "type": "string"
              }
            },
            "required": [
              "errors"
            ]
          }
        }
      }
    },
    "429": {
      "headers": {
        "traceId": {
          "description": "A globally unique identifier for the request. It is used to track the request flow throughout the system, allowing for easy location and debugging when issues arise."
        }
      },
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "errors": {
                "description": "Error message. ",
                "type": "string"
              }
            },
            "required": [
              "errors"
            ]
          }
        }
      }
    }
  },
  "security": [
    {
      "oauth2": []
    }
  ],
  "method": "post",
  "path": "/sales/price_rules/:price_rule_id/discount_codes.json",
  "servers": [
    {
      "url": "https://{handle}.myshopline.com/admin/openapi",
      "variables": {
        "handle": {
          "default": "openapiceshidianpu",
          "description": "`handle` : The store's unique identifier, which is the prefix of the store's domain name. For example, if a store's domain name is `open001.myshopline.com` , the store handle is `open001` ."
        }
      }
    }
  ],
  "info": {
    "title": "Create DiscountCode",
    "version": "v20260901"
  },
  "authIndexes": [
    "write_discounts"
  ]
}
```