Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google apps script urlfetch encoding URL

I would like to use urlfetch to populate a spreadsheet with page data but the URL that I am trying to use is coming back with an error as an invalid argument. I think the problem is that I am using characters in the URL that are being misinterpreted (e.g. quotation marks and parentheses).

I have tried to encode the URL with the command below but I am assuming that I am double encoding some of the characters and that is causing a problem.

var encodedURL = encodeURIComponent(pageURL)
like image 645
Pigcowpig Avatar asked Aug 29 '12 17:08

Pigcowpig


2 Answers

Try using

baseURL + encodeURIComponent(parameterString)

Where you include the parameters you're passing to the base URL you are querying as the value passed to the encodeURIComponent function. This post may be of use to you:

Encode URL in JavaScript?

If you encode the entire URL, like it looks like you are doing above, you're encoding more than just the parameters, which I assume would be where your problem lies.

like image 63
TMan Avatar answered Sep 28 '22 00:09

TMan


You personally probably don't need the answer, but I write for the ones that need. In order to make a successful API call (API v4) to GitLab you need to encode only the "variables". See below:

var url = baseUrl + projectId + "/repository/files/" + encodeURIComponent(pathAndFileName) + "?branch=" + encodeURIComponent(branch) + "&author_email=" + encodeURIComponent(authorEmail) + "&author_name=" + encodeURIComponent(authorName) + "&content=" + encodeURIComponent(content) + "&commit_message=" + encodeURIComponent(commitMessage);

Where pathAndFileName is a variable that was defined earlier.

like image 34
Daniel Turuș Avatar answered Sep 28 '22 00:09

Daniel Turuș