Magento 2 API Manage Special Prices

Magento 2 API Manage Special Prices

Magento provides REST endpoints that allow you to update multiple special prices

Today I will show you how to set, get and delete special prices using Magento 2 API. You can efficiently schedule special prices for one or more products in a store’s catalog. 

Set Special Price

The call sets special prices for the following product types:

  • Simple
  • Bundle
  • Virtual
  • Downloadable

You can set multiple special prices in a single call or set just 1 special price as shown in the example below.

Step 1: Generate Admin Access Token

Endpoint: POST <host>/rest/V1/integration/admin/token

Enter your admin username and password in Body sections, then click Send.

{
  "username": "string",
  "password": "string"
}

Response: access token

Step 2: Set Special Price

Create a new request and enter the admin access token

Authorization: Bearer token

Endpoint: POST <host>/rest/<store_code>/V1/products/special-price

Payload:

{
  "prices": [
    {
      "price": 19,
      "store_id": 0,
      "price_from": "2021-09-22 00:00:00",
      "price_to": "2021-09-24 23:59:59",
      "sku": "24-MB02"
    }
  ]
}

Response:

An empty array.

[]

Step 3: Verify The Special Price

In Store, Search 24-MB02 (24-MB02 is SKU of the product I set a special price for). And look at the Special price in the price area.

Get Special Prices

The following call returns the special price information for a SKU value.

Step 1: Generate Admin Access Token

Endpoint: POST <host>/rest/V1/integration/admin/token

Enter your admin username and password in Body sections, then click Send.

{
  "username": "string",
  "password": "string"
}

Response: access token

Step 2: Get Special Prices

Create a new request and enter the admin access token

Authorization: Bearer token

Endpoint: POST <host>/rest/<store_code>/V1/products/special-price-information

Payload:

{
  "skus": [
    "24-MB02"
  ]
}

Response:

[
    {
        "price":19,
        "store_id": 0,
        "sku": "24-MB02",
        "price_from": "2021-09-22 00:00:00",
        "price_to": "2021-09-24 23:59:59"
    }
]

Delete a special price

Step 1: Generate Admin Access Token

Endpoint: POST <host>/rest/V1/integration/admin/token

Enter your admin username and password in Body sections, then click Send.

{
  "username": "string",
  "password": "string"
}

Response: access token

Step 2: Delete A Special Price

Create a new request and enter the admin access token

Authorization: Bearer token

Endpoint: POST <host>/rest/<store_code>/V1/products/special-price-delete

Payload:

{
  "prices": [
    {
      "price": 19,
      "store_id": 0,
      "price_from": "2021-09-22 00:00:00",
      "price_to": "2021-09-24 23:59:59",
      "sku": "24-MB02"
    }
  ]
}

Response:

An empty array.

[]

Step 3: Verify The Result

In Store, Search 24-MB02 (24-MB02 is the SKU of the product I set a special price for). The special price was deleted.

Magento 2 API Manage Special Prices

Above, I have just provided you with many steps to Manage special prices. I hope it will be helpful for you when managing special prices using Magento API. For more information, you can refer to Magento DevDocs. If you have any questions or new ideas, feel free to leave a comment below.

Want to Learn More?

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email