|
ApiDocumentation
Documentation of the bit.ly REST API methods
See also the JavascriptClientApiDocumentation Sections InformationThe bit.ly API allows developers to interact in a programmatic way with the bit.ly website. The current API version is 2.0.1 Authentication and Shared ParametersAll APIs require authentication credentials supplied as query arguments: login=login&apiKey=apiKey All APIs require a version identifier to be present: version=2.0.1 All APIs support an optional return format specifier (json is the default response format. xml is also available): format=json All APIs support an optional callback specifier for use with json return format: callback=callback
Rate Limitingbit.ly currently limits API users to no more than five concurrent connections from a single IP address. In general, if you intend to be an extremely high-volume user of the api, please contact us at support@bit.ly to discuss your options. REST API/shortenGiven a long URL, /shorten encodes it as a shorter one and returns it. Additional Parameters
A long URL to shorten, eg: http://betaworks.com To shorten multiple URLs in a single API call, just post as many longUrl parameters. Note: Long URLs should be URL-escaped. Examples
/expandGiven a bit.ly URL or hash, /expand decodes it back into a long source URL and returns it. Additional Parameters Either shortUrl or hash must be given as a parameter. Examples
/infoGiven a bit.ly URL or hash, return information about that page, such as the long source URL, associated usernames, and other information. Additional Parameters Either shortUrl or hash must be given as a parameter. Examples
/statsGiven a bit.ly URL or hash, return traffic and referrer data. Additional Parameters Either shortUrl or hash must be given as a parameter. Examples
/errorsGet a list of bit.ly API error codes. Examples DiscussionPlease visit our Google Group for discussion of projects and technical issues. http://groups.google.com/group/bitly-api |
Sign in to add a comment
Great API. I was wondering if you could create an interesting dashboard as a gadget for iGoogle if you used www.youcalc.com?, just like this one that provides an {http://www.youcalc.com/apps/1218724763465 interactive dashboard] on ebay statistics feed.
Sorry my wiki skills are a bit rusty, the post should read: Great API. I was wondering if you could create an interesting dashboard as a gadget for iGoogle if you used youcalc, just like this one that provides an interactive dashboard on ebay statistics feed.
$ curl --location http://api.bit.ly/recent --include HTTP/1.1 200 OK Server: nginx/0.6.32 Date: Thu, 22 Jan 2009 09:05:40 GMT Content-Type: text/html;charset=utf-8 Connection: keep-alive Content-Length: 119 Allow: GET, HEAD, POST { "errorCode": 203, "errorMessage": "You must be authenticated to access recent", "statusCode": "ERROR" }Hmmm ... if Basic Authentication is required, should this not be returning "401 UNAUTHORIZED"?
i'm having the same experience. besides the fact that 'recent' (un-documented but referenced as an example above) isn't supported:
{ "errorCode": 202, "errorMessage": "Undefined method recent", "statusCode": "ERROR" }
and as @davidjanes states, no HTTP Auth support seems to be in play here
Has anyone else noticed that URLs shortened through the API do not show up in the user's history when their API key is used?
I have noticed it isn't showing in the history either. I found this thread so it appears there is a history parameter you can send.
http://groups.google.com/group/bitly-api/browse_thread/thread/d35fa7c5e1a764f9/3224b7104234b362?lnk=gst&q=history#3224b7104234b362
But don't know what the history parameter is.
Adding the parameter history=1 will publish to your history.
http://api.bit.ly/shorten?version=2.0.1&longUrl=http://cnn.com&login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&history=1
How do you customize the shortened url alias? I believe it's called "shortened custom name" or something like that. Hash is not the parameter for this, so is there a way to create a custom shortened url with this API?
Is there a parameter set optional custom name?
Is it a bug that the xml response format will return the original url (in nodeKey) within a CDATA section, but also escape the ampersands into HTML entities (&)? Wouldn't it make more sense to not escape the data inside of a CDATA section? For instance, try the following link and see what's in the CDATA section:
http://api.bit.ly/shorten?version=2.0.1&format=xml&longUrl=http://test.com?a=1%26b=2&login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07
For those looking to shorten to a custom keyword, the parameter is: keyword. Set the value to the keyword you desire.
What are the legal characters in a keyword? More specifically, how can I construct a regex to detect a bitly link in a body of text?
Bug: http://api.bit.ly/expand?version=2.0.1&shortUrl=http://bit.ly/31IqMl&login=bitlyapidemo&format=xml&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07
possibly generate: <hash>31IqMl</hash> instead of <31IqMl>
Correction in wording: "To shorten multiple URLs in a single API call, just post 2 longUrl parameters. " should read : To shorten multiple URLs with single API call, use as many longUrl parameters.
Does history=1 have to come last in the parameters list?
I'm passing it as part of a script that generates bit.ly urls, but the ones shortened via the API are not showing the user's history
Very interesting: "login" parameter is case sensitive. I.e. "login=ABC" doesn't work, but "login=abc" OK.
currenly twitter show short url after that the custom messages. How should I change this.. I would like to show custom message and then twitter short URL?
Can I get an aggregate hash from a users hash over the api? I don't see that anywhere. I am trying to get total aggregate clicks from a users hash
Hi
What is the method of obtaining an API key. I want all URL's shortened through the API to be available in my account. Is that possible?
If I json_encode the output of shorten method, I get url as a key. But the key contains invalid object characters like : or / cant we avoid it?
Output I see
{ "errorCode": 0, "errorMessage": "", "results": { "http://www.yahoo.com": { "hash": "4bYAV2", "shortKeywordUrl": "", "shortUrl": "http://bit.ly/PGr84", "userHash": "PGr84" } }, "statusCode": "OK" }JSON Decode output
I'm having issues getting urls with long queries to work over the api. I am not sure how I am supposed to encode something like this
http://news.google.com/news/url?sa=T&ct=us/1-0&fd=R&url=http://www.google.com/hostednews/ap/article/ALeqM5gXTqqeOkfGj1m48YIY_JoiFK-q3wD97MD5J81&cid=1337713190&ei=t9fsSfSKKIfQjAfDk7mCDA&usg=AFQjCNF2lEuKw4HPLPnIvUVB3Iqp6iYvqg
Any advice?
@smartocci just encode the url:
http://api.bit.ly/shorten?version=2.0.1&longUrl=http://news.google.com/news/url%3fsa%3dT%26ct%3dus/1-0%26fd%3dR%26url%3dhttp://www.google.com/hostednews/ap/article/ALeqM5gXTqqeOkfGj1m48YIY_JoiFK-q3wD97MD5J81%26cid%3d1337713190%26ei%3dt9fsSfSKKIfQjAfDk7mCDA%26usg%3dAFQjCNF2lEuKw4HPLPnIvUVB3Iqp6iYvqg&login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&history=1
I'm having trouble getting the API shorten call to work with long URLs that have multiple query arguments of their own. Surrounding them in quotes doesn't seem to work. It thinks the long URL ends at the & so the second argument (id in this case) isn't being read. e.g.:
http://www.prh.noaa.gov/ptwc/?region=2&id=hawaii.2009.04.22.030225
Also, is there an option to have it only output the short URL and nothing else? (The tinyurl API does this by default.) I'm calling this from a shell script and prefer not to have to parse the long JSON or XML output.
Any ideas? Thanks.
Interested if the stats functionality will ever include daily / hourly clicks? If not, is it acceptable to poll hourly and store the results on an external server to simulate this functionality?
I have a question regarding the FireFox? Extension UrlbarExt?. It uses the bit.ly api to shorten urls through a URL bar shortcut button. How can I incorporate using my bit.ly login account when shortening to be able to get proper stats etc.?
It has the following options available to fill in (I typed in the current settings as well):
API: http://bit.ly/api Arguments: url=%?url% Post: On or Off Filter: Prefix: Suffix:
How shall I fill these in to make it use my login details for bit.ly?
when using the api i don't see the links showing up in the recent section. i sometimes see these show up under "Top Bits" ... is there another place to keep track these links and get stats that are under the same api key?
It is possible to expand multiple URLs with single API call? Multiple shortUrl or hash parameters not working. How to?
I know I can limit the "shorten" call to returning ONLY the shortened URL by including "&format=text".
Is there a way to limit the "stats" call to returning ONLY total clicks?
URLs shortened via the API are not added to your history unless you append history=1 to your API call.
Is it allowed to poll the server hourly and store the results on an external server to make some simulations with the statistical data ?
How do I get an API key? and is there better documentation on how to use the API?
I, too, am interested in getting an API key so I can post from twitterfeed. How do I get one? I have a bit.ly account, but it is not evident.
@sent...@hindu.org You can get the API key from your accounts page. http://bit.ly/account/
I agree with twittermoo, you should be allowed to make one API call for multiple shortUrls or hashes with expand.
i'm working on an actionscript3 port of this, any idea how i can share?
I'm noticing a minor bug when using the API. If I try to shorten a URL for a domain and I forget the trailing slash, bit.ly adds the slash to the end of the URL automatically. This would be fine, except in situations like this:
URL to shorten: http://www.mysite.com?track=yes
Bit.ly returns: http://www.mysite.com?track=yes/ <- Slash added to end
Can you advise?
Wrong xml (see "results" node) for http://api.bit.ly/errors?version=2.0.1&login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&format=xml
As far as I understand, each account (apikey) get's its own short url for a single link.
Is it possible to fetch all known short urls for one given long url?
Is it possible to reset the URL for an existing Custom Name? I want to change the target URL for a widely distributed Custom Name. I can't be the only one who wants to do that.
Great. I have one question about /stats. Do you have a plan to make it accessible the location of users who clicked the shorten URL? Those information are available through bit.ly web sites, but not through API.
Great API and great service from bit.ly! I wanted to ask if it is possible to have an API call to get the list of public urls shared by a particular user (maybe the logged in user). Thanks!
I am also interested in an api call that gets stats data for all of the logged in users urls.
Is a reverse search possible? i.e., list all bit.ly URLs for the long URL http://somesite.com/about.html
Does the custom keyword is broken ? I tried any keywords and it always return 'The custom keyword you tried to use was already used by someone else.'. Did I missed something ?
http://api.bit.ly/shorten?version=2.0.1&longUrl=http://www.cnn.com&login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&keyword=485fht653
Here the result : { "errorCode": 0, "errorMessage": "", "results": { "http://www.cnn.com": { "errorCode": 1212, "errorMessage": "The custom keyword you tried to use was already used by someone else.", "hash": "2EEjBl", "shortKeywordUrl": "", "shortUrl": "http://bit.ly/2iyjJb", "statusCode": "ERROR", "userHash": "2iyjJb" } }, "statusCode": "OK" }
David, I just emailed bit.ly support and they said that custom keywords were always an unsupported part of the API and have now been removed permanently.
Guess we have to stop using that part of the call now.
So it is encouraged to publish one's API key on a web site? Because if I use it from JavaScript? (for example with the Bitly client), everybody can just do "show source" and see my API key.
What's more, since history is not automatically logged(?), I won't even notice if somebody else uses my key.
Not that it necessarily matters, but I don't quite see the point of the API key if it is not a secret anyway.
Want to ask the same question that is asked above. Is it any harm to dislay the API key in public?
I was just about to add bit.ly support to Gravity (my S60 Twitter Client). Could you add an API call that's returning the URLs and hashes and stats for a specific (authorized) user? That would be cool for adding bit.ly to a mobile client.
Cheers Ole (ole at mobileways.de)
Just realized that I am creating a lot of bit.ly URLs just to get the information from /stats about a URL. Would be easier if you added a lonUrl parameter to the stats method, so that it could be accessed without a bitly hash for the URL.
has anyone seen any samples code? I have the API working on the post, but I can not figure out how to get the shortend URL back into my form.
Hi there,
The api chops off everything which is folloing an '&' in an URL, so the bit.ly link is getting useless. How to escape the '&" chars in the URL ?
brian.shiro, asked in Apr 25, 2009 the same.
Any ideas? Thanks.
@henkisdabro - I have the same question. I've tried a ton of different options for inputting everything, but not luck yet. Can anyone else help?
RE: UrlbarExt??. It uses the bit.ly api to shorten urls through a URL bar shortcut button. How can I incorporate using my bit.ly login account when shortening to be able to get proper stats etc.?
It has the following options available to fill in (I typed in the current settings as well):
API: http://bit.ly/api Arguments: url=%?url% Post: On or Off Filter: Prefix: Suffix:
How shall I fill these in to make it use my login details for bit.ly?
Escape the & in the URL:
Got it, replace in a URL the & with %26 Example for shorten: URL = "http://www.ceiberweiber.at/index.php?type=review&area=1&p=articles&id=1314"
curl or what you prefere, here curl
curl "http://api.bit.ly/shorten?version=2.0.1&longUrl=http://www.ceiberweiber.at/index.php?type=review%26area=1%26p=articles%26id=1314&login=yourid&apiKey=R_yourapiID"
Hello,
I wrote a PHP5-wrapper-class that implements all API-functions. Maybe it can be usefull for people that have to generate bit.ly-urls in their next Web 2.0-app.
http://blog.verkoyen.eu/blog/p/detail/bit-ly-php-wrapper-class
Hi, I screwed up and did not escape the & when I created my short url USING KEYWORDS. Now, I want to keep my keyword phrase, but I need to correct the underlying long link. How do I do that?
Is there a way through the API to get all Bit.ly hashes (short URLs) for a given long URL?
How can I delete a short URL from my account. When I am using googlespreadsheet, I keep modifying various values (campaigns, mediums, etc.,). As I keep modifying those, the api keeps on creating short urls.
There should be a mechanism for me to delete some of the short urls created by me. -Satish
I would love to see a bookmarklet for posting the current web page straight to twitter.
Is there any way to get the date the URL was submitted for shortening?
Is there a way to verify the API Key? I've looked around and haven't found anything!
Sorry, but I don't get the Authentication
What to use for:
login=login&apiKey=apiKey ?
Thanks in Advance!
I also don't get the authentication. What is the problem?
For login, use your username. The apiKey is given in account settings.
Here is a helper class for .NET. http://www.databatrix.com/2009/08/a-net-bit-ly-api-helper-class-visual-basic-net/
Am I able to get a list of the links I've published with Bit.ly (the history). It would make integration with my site much much easier.
When will there be API support for j.mp?
Although i use the correct login and apikey, i still get the error you're not authorized.... Help!
@ivantis3, from what I saw you can already use http://api.j.mp/shorten[rest_of_default_code] to get a j.mp shortened link.
Is it possible to perform search? I cannot seem to be able to figure it out (neither for tweetmeme). Thanks! @jparicka
Hi, when will the API be updated for posting image data and getting a bit.ly or j.mp URL in one go. Thanks.
I need to know the difference between
"userHash" and "hash"
in the XML return. Anyone? both link to my URL.
Since we're passing around login information, is there any chance we can get an ssl version at https://api.bit.ly/ ?
Is there any limitation of using API, some TOS for API usage.
I used this feature in my site (http://goseedo.net/index.php?menu=showevents&id=3512&country=United%20States&state=New%20York&city=New%20York) ; now this issue is : I had to block your script like this
<script type="text/javascript" charset="utf-8" src="http://bit.ly/javascript-api.js?version=latest&login=goseedo&apiKey=R_0d6e8a03b9f992777da49690f29db963"> </script> <script type="text/javascript" src="js/shorterurl.js"></script> <script type="text/javascript">
</script>As in IE anything underneath get invisible if I run the script.
Can anyone advice how to fix it?
@roberto.valerio When a logged-in user shortens a link, and this link has not been shortened before, both a user hash and a (global) hash are created that redirect to that same long link. All non-logged-in users will receive that same global hash for shortening that link, but the user hash is specific to that user. Hopefully that helps answer your question, and please feel free to email support@bit.ly with more questions.
@spcghst440 Try my Twitt.it (http://twitt.it)
after using curl i get alot of info back anyone know how to grep out only the shorten url?
Still hoping to get longURL returned as part of the stats api call. This will remove the need for me to have to separately call info() multiple times.
Kudos on the api super easy to use :)
thanks for an awesome api! however my long url contains a get param "&image=23" even though i am url encoding using rawurlencode, when i try accessing the returned json object, the &image param seems to have been converted to the following character: ℑ which makes me unable to access the results stdClass for my long url. :( anyone have any ideas?
edit: using the php function get_object_vars seems to have sidestepped this issue.
Having got the information in some strange format or other, how does one pick out the bit one wants? I'm assuming someone has already done this, or is there a php function to do it? Would be useful if there was a name for this type of format. then I could find something online most likely
I agree that we need a way to connect over SSL, because the calls fail if the user clicks the wrong option in IE's mixed SSL content warning (that is, if they're on a page using HTTPS/SSL).
I'd even settle for a way to pass this an alternate API URL so that we can proxy the real API through a mod_rewrite rule. That's what I'm doing right now to avoid the initial error, but once I actually call the API it still throws the warning asking the user if they want to allow the non-SSL content.
What's worse is that in IE 6-7, the correct answer is "yes". In IE 8, it's "no" (the questions were all rephrased so that the more secure answer is always "yes"). This makes it really easy for the user to make a mistake, and once they do there's no way to make the calls work on that page.
I dont get the correct url when it is shortened. I send: http://api.bit.ly/shorten?version=2.0.1&longUrl=http://www.twindowpane.com/trend.php%3Ftrend%3D%23Iranelection&login=twindowpane&apiKey=R_7caf2d723a96bd07fb049b45f8a73084 which has the url encoded. however i get back a link to: http://www.twindowpane.com/trend.php?trend=#Iranelection not http://www.twindowpane.com/trend.php?trend=%23Iranelection how do i get a link to the correct url?
ok, just found the answer. you need to encode the parameter if it's likely to have reserved characters, before you encode the rest of the options like so (in php): $topUrl = "http://www.twindowpane.com/".urlencode("trend.php?trend=".urlencode($yy));
If you are using the PEAR class Services_ShortURL you will face the "bug" where bit.ly does not retain your history once you have shortened a URL.
The fix is easy.
Open Bitly.php in the Services/ShortURL/ directory. Go to line 93 in the "shorten" function.
Add the parameter 'history' => '1', to it making it look like this:
And its fixed!
Hope this helps..
The question marks should be open and close brackets..
for those asking about UrlBarExt?...
API: http://api.bit.ly/shorten arguments: version=2.0.1&format=xml&longUrl=%?url%&login=yourlogin&apiKey=yourapikey filter: <shortUrl>(.+)<\/shortUrl>
add &history=1 if you want it in your history
you could probably do it with JSON too but parsing XML was easier for me to think through at the time :)