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:
/V1/mw-giftcards?searchCriteria[filter_groups][filters][field]=order_id&searchCriteria[filter_groups][filters][value]=40&searchCriteria[filter_groups][filters][condition_type]=gteq -> Get Gift Cards matching the specified criteria (variable =>
card_id / order_id)
2. To receive data about a gift card by specifying its card code in the endpoint, use the following request:
/V1/mw-giftcards/:giftCardCode-> Get Gift Card Info by Card Code
3. Use the following request to create a gift card with a specific card code:
/V1/mw-giftcards-> Create Gift Card with the specified code
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.
/V1/mw-giftcards-> Update Gift Card
5. The DELETE request naturally allows deleting gift cards. This can be performed by specifying a gift card code in the endpoint:
/V1/mw-giftcards/:giftCardCode-> Delete Gift Card by Card Code
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:
/V1/mw-giftcards/:giftCardCode/balance-> Get Gift Card balance by Card Code
/V1/mw-giftcards/:giftCardCode/status-> Get Gift Card status label by Card Code
/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:
/V1/carts/:cartId/mw-giftcards/:giftCardCode-> Add Gift Card to Cart;
/V1/carts/guest-carts/:cartId/mw-giftcards/:giftCardCode-> Add Gift Card to Cart for Guest;
/V1/carts/mine/mw-giftcards/:giftCardCode-> Add Gift Card to Cart for Customer.
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.
/V1/carts/:cartId/mw-giftcards/:giftCardCode-> Remove Gift Card from Cart;
/V1/carts/guest-carts/:cartId/mw-giftcards/:giftCardCode-> Remove Gift Card from Cart for Guest;
/V1/carts/mine/mw-giftcards/:giftCardCode-> Remove Gift Card from Cart for Customer.