[#1132] Details for coupons and gift cards are not easily available, admin/promotions is broken

Migrated from Redmine #1132 | Author: Thomas Luzat
Status: New | Priority: Normal | Created: 2023-11-21


For our own frontend, I am trying to validate gift cards and coupons before creating an order. Currently, I do check the code against the REST API endpoints admin/promotions/coupons and admin/promotions/gift-cards with ?filter[code]=…&filter[service_id]=…

This somewhat works, but the returned data does include empty lists of restrictions as noted elsewhere (e.g. issue #1006):


{
    "service_restrictions": [],
    "booking_restrictions": [],
    "product_restrictions": [],
    "paid_attribute_restrictions": [],
    "memberships_restrictions": [],
}

The proposed solution is to use admin/promotions. This does not work well for multiple reasons:

  1. It’s necessary to query for basically all promotions. This can return a couple of hundred results and pages, which is very slow and requires caching (and hence possibly obsolete data) on our side.
  2. Paging does not work correctly: On page 1, the number of pages and results is shown to be 1 and 10:

{
  "metadata": {
    "items_count": 10,
    "pages_count": 1,
    "page": 1,
    "on_page": 10
  }
}

But adding ?page=2 results in:


{
  "metadata": {
    "items_count": 20,
    "pages_count": 2,
    "page": 2,
    "on_page": 10
  }
}

And so on … It’s not clear how many results there are and when to stop iterating. The correct count is only shown when specifying some large page number like ?page=1000:


{
  "metadata": {
    "items_count": 838,
    "pages_count": 84,
    "page": 1000,
    "on_page": 10
  }
}

Even so, this is a bad way to find a particular promotion. Without caching, this may currently require 85 API calls just to get all details for one code. Helpful would be a way to query for promotion by ID: admin/promotions/details/, admin/promotions/ or admin/promotions?filter[id]= or just include the full details in admin/promotions/(coupons|gift-cards) endpoints.

I have also been trying to use the Admin JSON-RPC API’s getPromotionDetails, but it is missing the same information.

Would it be possible to add one of the proposed solutions or is there any alternative that I am missing? We would like to offer some Black Friday and Christmas deals and would prefer not to build fragile workarounds.

Thank you!

Thomas Luzat wrote:

I noticed that I can pass on_page=100 to reduce the number of requests, but it’s still bad to have to query for all promotions.