Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

issues with sending requests with ampersands in POST body #10

@airhadoken

Description

@airhadoken

UrlFetchApp.fetch() works incorrectly when the payload is an object and one or more of the parameter values contains an ampersand (&). This creates issues with sending OAuthed statuses with ampersands to Twitter, for example. You will get "Could not authenticate you" errors because the post body sent by UrlFetchApp does not correspond to the one used to created the signature.

I recommend manually stringifying the payload to a correct POST body before sending the data if the content is going to be urlencoded (this is what I was doing under the old OAuth service, and worked well). However, if there is a blob in the payload, it will be sent multipart/form-data instead, so check for that:

//Service.gs, line 398
// Service_.prototype.fetchInternal_()
if(params.payload && !Object.keys(params.payload).reduce(function(truth, key) {
  return truth || typeof params.payload[key] === "object";
}, false)) {
  params.payload = signer.getParameterString(request, {});
}
return UrlFetchApp.fetch(url, params);

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