MISSING_ARG_ACCESS_TOKEN for v3/shorten

635 views
Skip to first unread message

Libby Batten

unread,
Mar 29, 2016, 10:44:25 AM3/29/16
to Bitly API

Hi there, 


While accessing the v3 Shorten API, I am getting a MISSING_ARG_ACCESS_TOKEN response no matter what I try. The access_token is correct, and the URL is encoded. I have confirmed this by accessing the api via a web link with my access token and a test URL. 


data: {"access_token":<access_token>,"longUrl":"http%3A%2F%2F<host><endodedparams>","format":"txt"}

bitly response: { "data": [ ], "status_code": 500, "status_txt": "MISSING_ARG_ACCESS_TOKEN" }


Does anything jump out in the code below that could be causing the error? Many thanks!



function shortenURL(accessToken : String, request : CurrentRequest) {

 
var _timeout  = '3000';

 
var host = 'api-ssl.bitly.com';

 
var endpt = '/v3/shorten';

 
var url : String = request.httpURL;

 
var data : String = JSON.stringify({

 access_token
: accessToken,

 longUrl
: encodeURIComponent(url),

 format
: 'txt'

 
});

 
var httpClient : HTTPClient = new HTTPClient();

 httpClient
.setTimeout(_timeout);

 httpClient
.open('GET', 'https://' + host + endpt);

 httpClient
.send(data);

 
if ( httpClient.statusCode != 200 ) {

 
throw new Error('HTTP Communication error : Status code ' + httpClient.statusCode + ' - ' + httpClient.statusMessage);

 
}

 
var bitlyURL = JSON.parse(httpClient.text);

 
return bitlyURL;

};


Peter Herndon

unread,
Mar 29, 2016, 10:56:57 AM3/29/16
to Bitly API
Hi Libby,

Looking at your code, you are turning your data from a hash into a JSON string and sending that to the endpoint. Our API does not accept JSON strings; instead, you should be turning the key-value pairs in your data blob into query parameters tacked on to the end of your request endpoint. I'm not conversant enough with JavaScript to know the idiomatic way of doing so, but your code should have the equivalent of this:


None of our APIs accept JSON, they all require percent-encoded query parameters. Let us know if you have further questions.

Regards,

---Peter

Peter Herndon
Sr. Application Engineer
@Bitly 

Libby Batten

unread,
Mar 29, 2016, 11:28:05 AM3/29/16
to Bitly API
Hi Peter, thank you for your help. 


With the parameters appended using the open method only, there is no response,

[ allResponseHeaders=null, errorText=null, statusCode=0, statusMessage=null, text=null


httpClient.open('GET', 'https://api-ssl.bitly.com/v3/shorten?access_token=' + accessToken +'&longUrl=' +encodeURIComponent(url) + '&format=txt');


Using the send method I'm still getting the 

bitly response: { "data": [ ], "status_code": 500, "status_txt": "MISSING_ARG_ACCESS_TOKEN" }


var httpClient : HTTPClient = new HTTPClient();
 httpClient
.setTimeout(_timeout);

 httpClient
.open('GET', 'https://api-ssl.bitly.com/v3/shorten');
 httpClient
.send('?access_token=' + accessToken +'&longUrl=' +encodeURIComponent(url) + '&format=txt');


Any more ideas?


On Tuesday, March 29, 2016 at 10:44:25 AM UTC-4, Libby Batten wrote:

Peter Herndon

unread,
Mar 31, 2016, 9:38:20 AM3/31/16
to Bitly API
Hi Libby,

Unfortunately, I'm not proficient with JavaScript, so I'm not going to be able to be much help to you in figuring out the specific syntax you need to accomplish an HTTP GET request. But the API URL example I gave you should be enough, along with the normal language documentation, to get you started in the right direction. I can point to some examples in Python, if that helps at all:  https://github.com/tpherndon/bitly_api_examples/blob/master/link_details.py

Regards,

---Peter

Peter Herndon
Sr. Application Engineer
@Bitly

On Tuesday, March 29, 2016 at 10:44:25 AM UTC-4, Libby Batten wrote:

Libby Batten

unread,
Mar 31, 2016, 12:10:44 PM3/31/16
to Bitly API
Hi Peter,

I was able to get this to work with your suggestion, the missing piece was httpClient.send() so thank you very much for your help. 


On Tuesday, March 29, 2016 at 10:44:25 AM UTC-4, Libby Batten wrote:
Reply all
Reply to author
Forward
0 new messages