Magento 2 Gift Cards by MageWorx: Available REST API Requests

0
13065
Magento 2 Gift Cards by MageWorx: Available REST API Requests | MageWorx Magento Blog
Reading Time: 2 minutes

Now that you know the advantages and disadvantages of gift cards, you should have made your choice and decided to add such functionality to your Magento 2 business or not.

This article is for those who have already made their minds, and want to learn which REST API requests the Mageworx Gift Cards extension for Magento 2 offers.

In this article, we will cover the most critical for a business REST API requests, which have not been previously available within similar 3rd-party solutions.


With the help of the GET request, it is possible to receive the list of gift cards that were used when making an order. This request should contain ‘searchCriteria’ in the URL address. The main template for creating such requests is available here:

https://devdocs.magento.com/redoc/2.3/

GET /V1/mw-giftcards?searchCriteria[filter_groups][0][filters][0][field]=order_id&searchCriteria[filter_groups][0][filters][0][value]=40&searchCriteria[filter_groups][0][filters][0][condition_type]=gteq -> Get Gift Cards matching the specified criteria (variable => card_id / order_id)

Magento 2 Gift Cards by MageWorx: Available REST API Requests | MageWorx Magento Blog
Magento 2 Gift Cards by MageWorx: Available REST API Requests | MageWorx Magento Blog

2. To receive data about a gift card by specifying its card code in the endpoint, use the following request:

  • GET /V1/mw-giftcards/:giftCardCode -> Get Gift Card Info by Card Code
Magento 2 Gift Cards by MageWorx: Available REST API Requests | MageWorx Magento Blog

3. Use the following request to create a gift card with a specific card code:

  • POST /V1/mw-giftcards -> Create Gift Card with the specified code
Magento 2 Gift Cards by MageWorx: Available REST API Requests | MageWorx Magento Blog

4. The PUT request allows you to edit Magento 2 gift cards data conveniently. It is worth remembering that it is required to specify an ID of a gift card you wish to edit in the request body.

  • PUT /V1/mw-giftcards -> Update Gift Card
Magento 2 Gift Cards by MageWorx: Available REST API Requests | MageWorx Magento Blog

5. The DELETE request naturally allows deleting gift cards. This can be performed by specifying a gift card code in the endpoint:

  • DELETE /V1/mw-giftcards/:giftCardCode -> Delete Gift Card by Card Code
Magento 2 Gift Cards by MageWorx: Available REST API Requests | MageWorx Magento Blog

6. With the help of the following requests, you can find out the balance, status and the validity period of a gift card. This shall be done by specifying a gift card code in the endpoint:

  • GET /V1/mw-giftcards/:giftCardCode/balance -> Get Gift Card balance by Card Code
Magento 2 Gift Cards by MageWorx: Available REST API Requests | MageWorx Magento Blog
  • GET /V1/mw-giftcards/:giftCardCode/status -> Get Gift Card status label by Card Code
Magento 2 Gift Cards by MageWorx: Available REST API Requests | MageWorx Magento Blog
  • GET /V1/mw-giftcards/:giftCardCode/expireDate -> Get Gift Card expire date by Card Code

The next group of requests will come in handy if you develop a mobile app and need to use API requests in order to add/delete a gift card to/from the shopping cart. Let’s have an insight.

7. The below-mentioned requests allow you to add a gift card to the shopping cart, guest cart or a customer cart:

  • PUT /V1/carts/:cartId/mw-giftcards/:giftCardCode -> Add Gift Card to Cart;
  • PUT /V1/carts/guest-carts/:cartId/mw-giftcards/:giftCardCode -> Add Gift Card to Cart for Guest;
  • PUT /V1/carts/mine/mw-giftcards/:giftCardCode-> Add Gift Card to Cart for Customer.
Magento 2 Gift Cards by MageWorx: Available REST API Requests | MageWorx Magento Blog

8. The last but not least group of requests will come in handy if you need to delete a gift card from the shopping cart guest cart or a customer cart.

  • DELETE /V1/carts/:cartId/mw-giftcards/:giftCardCode -> Remove Gift Card from Cart;
  • DELETE /V1/carts/guest-carts/:cartId/mw-giftcards/:giftCardCode -> Remove Gift Card from Cart for Guest;
  • DELETE /V1/carts/mine/mw-giftcards/:giftCardCode -> Remove Gift Card from Cart for Customer.
Magento 2 Gift Cards by MageWorx: Available REST API Requests | MageWorx Magento Blog

Documentation:

LEAVE A REPLY

Please enter your comment!
Please enter your name here