Skip to content

GET requests send data: {}, which fetch-based runtimes reject #850

Open

Description

@mburumaxwell

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions