chargebee / chargebee-typescript

Typescript library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=typescript
MIT License
23 stars 16 forks source link

Filtering is broken for customer "in id" filters #17

Closed eatsleepdeploy closed 3 years ago

eatsleepdeploy commented 3 years ago

Problem:

When attempting to retrieve a batch of customers whose IDs are in a batch of ids the filtering fails.

Example:

const results: ListResult =  await chargebee.customer
        .list({
          id: { in: ["id1", "id2"] },
        })
        .request(undefined)

Adding some logging to the lib shows that this gives the below encoding:

id[in][0]=id1&id[in][1]=id2&limit=10

The result is that the filter seems to be ignored and I get paginated response containing every single customer.

Workaround:

const results: ListResult =  await chargebee.customer
        .list({
          // @ts-ignore
          id: { in: JSON.stringify(["id1", "id2"]) },
        })
        .request(undefined)

Which gives the below encoding for the url:

id[in]=["id1","id2"]&limit=10

This seems to return only the customers whose IDs match.

Solution Ideas:

  1. Change in type to a string and update docs to indicate that we should stringify the list
  2. Fix the encoding to serialize the arrays properly.

Note:

I tried the node lib too (chargebee on npm) and hit the same issue so assume that the fix will need to be applied to that lib also.

eatsleepdeploy commented 3 years ago

Huh, never mind I guess, I updated the lib to latest version and it now works. My bad.