Listing saved cards without passing in sortOrder causes `BAD_REQUEST` error

Open Beginner friendly
#240 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
70/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
typescript
Domain
api

Research direction

Start at the cards.list entry point and trace how the optional sortOrder value is serialized into the request URL. Verify that omitting sortOrder no longer produces an empty sort_order query parameter, while an explicit value such as DESC remains supported and the list request succeeds.

Written by the indexing model from the issue text.

Description

Library Version: 44.2.0

  const cards = await client.cards.list({
    customerId: squareCustomerId,
  });
Response
Body: {
  "errors": [
    {
      "category": "INVALID_REQUEST_ERROR",
      "code": "INVALID_ENUM_VALUE",
      "detail": "`` is not a valid enum value for `sort_order`.",
      "field": "sort_order"
    }
  ]
}
"rawResponse":{"headers":{},"redirected":false,"status":400,"statusText":"Bad Request","type":"basic","url":"https://connect.squareupsandbox.com/v2/cards?customer_id=<redacted>&sort_order="},
Expected behaviour

Not passing sortOrder should just return the default, presumably by just removing the &sort_order= query from the url when not provided.

Workaround
  const cards = await client.cards.list({
    customerId: squareCustomerId,
    sortOrder: 'DESC',
  });
Dominant language
TypeScript
Stars
116
Forks
48
Avg merge
2h 13m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from square/square-nodejs-sdk

All issues in square/square-nodejs-sdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.