Requires write_products access scope.
For more info, refer to:
POST https://{handle}.myshopline.com/admin/openapi/v20260301/products/:product_id/variants.json
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 .
Create a variant for the specified product.
Path Parameters
  • product_id string required
    The unique identifier for the product.
    Maximum length:64
    Example: 16057039432335097907370282
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 to obtain the access token, and then pass the obtained token in the Bearer format.
    Example:
    Bearer eyJhbGciOiJIUzUxMiJ9.eyJhcHBLZXkiOiJmMjM3OWQyMTYyOGMzM2QxMWRiMWZkYjY5N2EzZjdjMjZlNGMwYTA5Iiwic2VsbGVySWQiOiIyMDAwMjM0ODgwIiwic3RvcmVJZCI6IjE2NzIzNjk3Mjk2MDYiLCJ2ZXJzaW9uIjoiVjIiLCJkb21haW4iOiJodHRwczovL3NsLW9wZW4tc2cubXlzaG9wbGluZS5jb20iLCJ0aW1lc3RhbXAiOjE2NzUzMTk0OTI0MzksImlzcyI6Inlzb3VsIiwiZXhwIjoxNzY5OTI3NDkyfQ.UwQzomM2veGCUaOZ0paUxq5dpc7DXuhHYFvsQ_uIAKduzWcb_j2E4q_36El83sp145D4cKbpcE5KCeeIz-JNQw
Request Body
  • variantobject
    Variant information.
  • barcode string
    The barcode of the variant.
    Maximum length: 255
    Example: T0000001
  • compare_at_price string
    The original price of the variant. The value is rounded to two decimal places.
    Default value: 0
    Example: 129.99
  • imageobject
    The image of the variant.
  • alt string
    The alternative textual description of the variant image, usually a word or phrase with the characteristics or content of the image.
    Maximum length: 512
    Example: This is an image alt
  • id string
    The unique identifier for the variant image.
    Maximum length:64
    Example: 5759070976424132652
  • src string
    The link to the variant image, represented as a URL.
    Maximum length: 255
    Example: https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png
  • inventory_policy string
    Indicates whether the variant is allowed to be oversold.
    • deny: overselling not allowed
    • continue: overselling allowed
    Default value: deny
  • inventory_tracker boolean
    Indicates whether the inventory tracking is enabled.
    • true: Inventory tracking is enabled.
    • false: Inventory tracking is not enabled.
    Default value: true
  • option1 string
    Information of the first option of the variant.
    Maximum length: 255
    Example: red
  • option2 string
    Information of the second option of the variant.
    Maximum length: 255
    Example: xl
  • option3 string
    Information of the third option of the variant.
    Maximum length: 255
    Example: cotton
  • option4 string
    Information of the fourth option of the variant.
    Maximum length: 255
    Example: short
  • option5 string
    Information of the fifth option of the variant.
    Maximum length: 255
    Example: red
  • price string
    The selling price of the variant. The value is rounded to two decimal places.
    Default value: 0
    Example: 90.22
  • required_shipping boolean
    Indicates whether the variant is required to be shipped.
    • true: Shipping is required.
    • false: Shipping is not required.
    Default value: true
  • sku string
    The product SKU. It is distinct from variant.id returned by SHOPLINE.
    Maximum size: 255
    Example: S0000001
  • taxable boolean
    Indicates whether the variant is subject to tax.
    • true: Tax is required.
    • false: Tax is not required.
    Default value: true
  • weight string
    The weight of the variant. The value is required to be greater than 0,and rounded to two decimal places.
    Example: 0.23
  • weight_unit string
    The unit of weight for the variant. Valid values are:
    • g: gram
    • kg: kilogram
    • lb: pound
    • oz: ounce
    • zh_kg: kilogram
    Default value: g
Status Codes
For the complete list of codes and messages, see Http status code.

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
  • variantobject
    Variant information.
  • barcode string
    The barcode of the variant.
    Example: T000000001
  • compare_at_price string
    The original price of the variant. The value is rounded to two decimal places.
    Example: 129.99
  • created_at string
    The creation date and time of the product variant. Format: ISO 8601.
    Example: 2021-09-02T14:11:54+00:00
  • id string
    The unique identifier for the variant.
    Example: 18057039439794751459380282
  • imageobject
    The image of the variant.
  • alt string
    The alternative textual description of the variant image, usually a word or phrase with the characteristics or content of the image.
    Example: This is an image alt.
  • id string
    The unique identifier for the variant image.
    Example: 5785060242207917075
  • src string
    The link to the variant image, represented as a URL.
    Example: https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png
  • inventory_item_id string
    The unique identifier for the inventory item.
    Example: 5985060242375689228
  • inventory_policy string
    Indicates whether the variant is allowed to be oversold.
    • deny: overselling not allowed
    • continue: overselling allowed
  • inventory_quantity integer
    The total inventory quantity at all storage locations.
    Example: 99
  • inventory_tracker boolean
    Indicates whether the inventory tracking is enabled.
    • true: Inventory tracking is enabled.
    • false: Inventory tracking is not enabled.
  • option1 string
    Information of the first option of the variant.
    Example: red
  • option2 string
    Information of the second option of the variant.
    Example: xl
  • option3 string
    Information of the third option of the variant.
    Example: cotton
  • option4 string
    Information of the fourth option of the variant.
    Example: short
  • option5 string
    Information of the fifth option of the variant.
    Example: casual
  • price string
    The selling price of the variant. The value is rounded to two decimal places.
    Example: 90.22
  • product_id string
    The unique identifier for the product corresponding to the variant.
    Example: 16057039432335097907370282
  • required_shipping boolean
    Indicates whether the variant is required to be shipped.
    • true: Shipping is required.
    • false: Shipping is not required.
  • sku string
    The product SKU. It is distinct from variant.id returned by SHOPLINE.
    Example: S00000001
  • taxable boolean
    Indicates whether the variant is subject to tax.
    • true: Tax is required.
    • false: Tax is not required.
  • updated_at string
    The date and time when the variant was last updated. Format: ISO 8601.
    Example: 2021-09-02T14:11:54+00:00
  • weight string
    The weight of the variant. The value is rounded up if it exceeds two decimal places.
    Example: 0.23
  • weight_unit string
    The unit of weight for the variant. Valid values are:
    • g: gram
    • kg: kilogram
    • lb: pound
    • oz: ounce
    • zh_kg: kilogram
API Explorer
https://openapiceshidianpu.myshopline.com/admin/openapi/v20260301

ParamOptions

path required
header required

Body

required
{
  "variant": {
    "barcode": "T0000001",
    "compare_at_price": "129.99",
    "image": {
      "alt": "This is an image alt",
      "id": "5759070976424132652",
      "src": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png"
    },
    "inventory_policy": null,
    "inventory_tracker": null,
    "option1": "red",
    "option2": "xl",
    "option3": "cotton",
    "option4": "short",
    "option5": "red",
    "price": "90.22",
    "required_shipping": null,
    "sku": "S0000001",
    "taxable": null,
    "weight": "0.23",
    "weight_unit": null
  }
}

Language

curl --request POST \
--url https://openapiceshidianpu.myshopline.com/admin/openapi/v20260301/products/product_id/variants.json \
--header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJhcHBLZXkiOiJmMjM3OWQyMTYyOGMzM2QxMWRiMWZkYjY5N2EzZjdjMjZlNGMwYTA5Iiwic2VsbGVySWQiOiIyMDAwMjM0ODgwIiwic3RvcmVJZCI6IjE2NzIzNjk3Mjk2MDYiLCJ2ZXJzaW9uIjoiVjIiLCJkb21haW4iOiJodHRwczovL3NsLW9wZW4tc2cubXlzaG9wbGluZS5jb20iLCJ0aW1lc3RhbXAiOjE2NzUzMTk0OTI0MzksImlzcyI6Inlzb3VsIiwiZXhwIjoxNzY5OTI3NDkyfQ.UwQzomM2veGCUaOZ0paUxq5dpc7DXuhHYFvsQ_uIAKduzWcb_j2E4q_36El83sp145D4cKbpcE5KCeeIz-JNQw' \
--header 'Content-Type: application/json; charset=utf-8' \
--header 'accept: application/json'
Examples
Create a variant
Request
{
"variant": {
"barcode": "T0000001",
"compare_at_price": "99",
"image": {
"alt": "This is an image alt",
"src": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png"
},
"inventory_policy": "continue",
"inventory_tracker": "true",
"option1": "S",
"option2": "White",
"price": "90",
"required_shipping": "true",
"sku": "S0000001",
"taxable": "true",
"weight": "0.5",
"weight_unit": "kg"
}
}
Response
{
"variant": {
"barcode": "T0000001",
"compare_at_price": "99.00",
"created_at": "2023-08-29T15:32:54+08:00",
"id": "18060895634402500988513144",
"image": {
"alt": "This is an image alt",
"id": "6089563432963689533",
"src": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png"
},
"inventory_item_id": "6089563439612587791",
"inventory_policy": "continue",
"inventory_tracker": true,
"option1": "S",
"option2": "White",
"price": "90.00",
"product_id": "16060895302856191591063144",
"required_shipping": true,
"sku": "S0000001",
"taxable": true,
"updated_at": "2023-08-29T15:32:54+08:00",
"weight": "0.50",
"weight_unit": "kg"
}
}
Was this article helpful to you?