1

I'm trying to pull from the Amplitude Dashboard Rest API (documentation) in Google Apps Script, but am hitting a weird bug.

Here is the API call I want to make:

curl -u API_Key:Secret_Key 'https://amplitude.com/api/2/funnels?e={"event_type":"Any%20Active%20Event"}&e={"event_type":"Purchase%20Confirmation%20Page%20-%20Page%20View%20-%20W"\}&start=20180205&end=20180211&n=active&mode=unordered&cs=60'

And here is how my code is set up:

 var headers = {
    "Authorization" : "Basic " + Utilities.base64Encode("[I put my API key here]" + ':' + "[I put my secret key here]")
  };

  var params = {
    "method":"GET",
    "headers":headers
  };

var url ="https://amplitude.com/api/2/funnels?e=\{"event_type":"_active"\}&e=\{"event_type":"Purchase%20Confirmation%20Page%20-%20Page%20View%20-%20W"\}&start=20180214&end=20180215&n=active&mode=ordered&cs=86400"

function callAmp() {
  var response = UrlFetchApp.fetch(url, params);
  Logger.log(response.getContentText());
}

I'm getting the error:

Invalid argument: https://amplitude.com/api/2/funnels?e={"event_type":"_active"}&e={"event_type":"Purchase%20Confirmation%20Page%20-%20Page%20View%20-%20W"}&start=20180214&end=20180215&n=active&mode=ordered&cs=86400

Can someone help me understand what I'm doing wrong here?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
superpaow
  • 11
  • 1
  • That API call looks like it is much better served via POST with a JSON payload, not GET with URL-encoded parameters. If it really wants braces in the URL, perhaps https://meta.stackexchange.com/questions/79057/curly-brackets-in-urls is worth reading – tehhowch Mar 26 '18 at 16:41
  • In your search string, you have `e=` listed twice. I'm guessing that you should only use it once? And put all the values together. Also, I looked at the documentation, and I don't think that your search string is supposed to have JSON in it. From the examples, I don't see any examples with JSON in them. I would try: `?event_type=_active` Etc. – Alan Wells Mar 26 '18 at 20:54
  • Does this answer your question? [Invalid Argument with UrlFetch](https://stackoverflow.com/questions/13755863/invalid-argument-with-urlfetch) – Oleg Valter is with Ukraine Jun 17 '20 at 09:48

0 Answers0