GET requests send `data: {}`, which fetch-based runtimes reject
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- nodejs, typescript
- Domain
- api
Research direction
Start with the generated GET methods such as AccountingApi.getContact and getContacts, where request options are built with data: {}, and with the applyToRequest authentication hook the issue uses as a workaround. Check whether the fix belongs in the generated client or in the generator templates, since the issue does not say. Done means GET and HEAD requests omit data and a fetch-adapter test or a nock test passes for a GET call.
Written by the indexing model from the issue text.
Description
SDK you're using: xero-node 20.0.0 (same in 10.2.0 through 19.3.0), axios 1.19.0, Cloudflare Workers
Describe the bug
Every generated GET method (e.g. AccountingApi.getContact, getContacts, getInvoices) builds its request options with data: {}. axios serializes that to a "{}" body. Node's http adapter tolerates it, but on runtimes where axios uses its fetch adapter (Cloudflare Workers, and anywhere Request follows the Fetch spec), creating the Request throws:
TypeError: Request with a GET or HEAD method cannot have a body.
So no GET call works on Workers, even after the token request succeeds.
Expected behavior
Requests without a body parameter omit data (or set it to undefined).
Workaround
Replace the default authentication hook, which runs on each request just before axios sends it:
xero.accountingApi.setDefaultAuthentication({
applyToRequest: (options) => {
if (options.method === 'GET' || options.method === 'HEAD') delete options.data;
},
});
Related: #737 (same cause, seen through nock), #740 (fetch adapter support).
- Dominant language
- TypeScript
- Stars
- 264
- Forks
- 177
- Avg merge
- 10h 5m
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from XeroAPI/xero-node
-
`getClientCredentialsToken()` sends `scopes` (comma-joined) instead of the OAuth `scope` parameterOpen
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
TrackingOptionId value missing from accountingApi.getInvoices()Possibly taken @miachillgood claimed this 152 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 18/100
-
BankTransaction type is missing the batchPayment object.Possibly taken @miachillgood claimed this 171 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 22/100
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
All issues in XeroAPI/xero-node
Similar issues
-
prio:low status:done type:content
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
davidsneighbour/samui-samui.de#1925 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
opensro-dev/opensro#4901 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
super-productivity/super-productivity#12128 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
danielmiessler/LifeOS#3047 ·
Maintainers usually reply within 5 days
-
A docs change can fail pnpm check, because outreach lint and gen:types both write .astro/ at oncePossibly taken @2389400626lh-ops claimed this today. OpenArea: Infrastructure Area: Outreach Bug Difficulty: Low Good First Issue Priority: Low
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
DouglasNeuroInformatics/OpenDataCapture#1956 ·
Maintainers usually reply within 1 day