queryCoupons() query syntax for sorted fields

I’m having trouble with

queryCoupons() backend method query syntax

Working in
Dev Mode

What I’m trying to do
Return results that are sorted / filtered by field

**What I’ve tried so far

// this query works as expected**

import { elevate } from "wix-auth";import { coupons as c } from "wix-marketing.v2";

export async function get_coupons_v2(){

const query = {
"paging": {
"limit": 50,
"offset": 0}
}   
 const el = elevate(c.queryCoupons)
    const result = await el(query)
return result

// adding different variations based on
// API Query Language
// leads to errors like

message: Unexpected value for StringValue details: applicationError: description: Bad Request code: BAD_REQUEST data: {}

Before debugging syntax, check the field is sortable at all. Half the Coupons fields aren’t, and sorting one that isn’t returns BAD_REQUEST.

Sortable: _id, name, code, startTime, expirationTime, usageLimit, limitPerCustomer, minimumSubtotal, _dateCreated, numberOfUsages, appId.

Not sortable: active, expired, type, limitedToOneItem, appliesToSubscriptions. scope is neither filterable nor sortable.

active and expired are filterable with eq and ne only — no hasSome, no ranges.

Second thing: your error names StringValue, which is a type complaint, not a structure complaint. active and expired are booleans. Passing “true” as a string instead of true will throw exactly this. Same for numeric fields passed as strings.

Isolate it — run filter with no sort, then sort with no filter. That tells you which half is rejected in one pass instead of guessing at the shape.

BAD_REQUEST on queryCoupons usually means you’re sorting by a field that doesn’t support it. The Marketing Coupons collection is heavily restricted.

Sortable fields: _id, name, code, startTime, expirationTime, usageLimit, limitPerCustomer, minimumSubtotal, _dateCreated, numberOfUsages, appId.

NOT sortable: active, expired, type, scope, limitedToOneItem, appliesToSubscriptions.

For filters: active and expired accept eq/ne only. The scope field is neither filterable nor sortable despite appearing in the schema.

Working example:

import { coupons } from 'wix-marketing.v2';

export async function getCoupons() {
  const results = await coupons.queryCoupons()
    .eq('active', true)
    .ascending('_dateCreated')
    .limit(50)
    .find();
  
  return results;
}

If you’re hitting this on a field not listed above, that field doesn’t support query operations. Check your query against the sortable list first — one non-sortable field anywhere in the chain throws the entire request.