Bit.ly v4 script for shortening URL's

Bit.ly v4 script for shortening URL's

Hi

On March 1, 2020 Bit.ly implemented a new version 4 of their API for shortening URL's. It was a challenge to find out how this would work with a Deluge script, but I finallyhave a working script, so I thought would share it. Bit.ly provides a free account option where you can generate an access token. The option below is used when you have an application using a single account. (Bit.ly V4 documentation is here.)

//URL TO SHORTEN
url="https://www.zoho.com/creator/newhelp/user-guides.html" [doesn't need to be encoded]

//ACCESS CODES
Authorization = "Bearer [ENTER ACCESS TOKEN}";
Group = "[ENTER GROUP NAME";
Domain = "bit.ly";

//CONSTRUCT MAP
Header_Map = Map();
Header_Map.put("Content-Type","application/json");
Header_Map.put("Authorization",Authorization);
Body_Map = Map();
Body_Map.put("long_url",url);
Body_Map.put("group_guid",Group);
Body_Map.put("domain",Domain);

//MAKE CALL AND RETURN VALUE
code = postUrl(Service,Body_Map.toString(),Header_Map,false);
shorturl=code.getjson("responseText").getjson("link");


Json code is returned to the "code" variable when the postUrl is executed. the getjson function returns the "link" node.

Hope this is helpful to someone else.

Glenn