2

Apologies for any lack of technical specificity in this post, I’m stumbling around in the dark at the moment.

I’m currently trying to write a Google script to call the Insightly API (https://api.insight.ly) and I’ve run into a problem.

As far as I can see Insightly requires curly braces to be used when referring to a record’s ID in an API call, however Google script returns an error when URL’s containing curly braces are used.

How can I escape those curly braces so Google script treats them the same as any other bit of text?

Here’s my code

var url = "https://api.insight.ly/v2/Opportunities/{217}"
var response = UrlFetchApp.fetch(url, headers);

Thanks :)

Grokify
  • 15,092
  • 6
  • 60
  • 81
  • It's usually a really good idea to include the actual contents of the error message when asking a question like this. – Pointy Aug 03 '13 at 17:37

2 Answers2

1

Try

var url = "https://api.insight.ly/v2/Opportunities/" + encodeURIComponent("{217}");

The { must be encoded as %7B and } as %7D. You can hard-code those if you like, but it's nice to be able to see the actual string in the source code.

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • Thanks for your answer, I tried your suggestion, it returns Request failed for https://api.insight.ly/v2/Opportunities/%7B217%7D returned code 400 So far as I can tell that URI should be formatted correctly, at least according to this page https://api.insight.ly/V2/Help/Api/GET-Opportunities-id – user2649062 Aug 04 '13 at 06:55
  • @user2649062 maybe that "id" doesn't exist? If it's returning a 400 then that means that your HTTP request was correctly completed. If the server has a problem with the request, then that's an issue with the service itself. I don't know anything about that service unfortunately. – Pointy Aug 04 '13 at 14:54
  • The ID does exist, I'll drop Inisghtly an email and find out whats going on. – user2649062 Aug 04 '13 at 15:57
0

A bit late but.. Hope it helps.. You do not have to put the { and }.. the right code is

var url = "https://api.insight.ly/v2/Opportunities/217"
Dylan
  • 1