Snipplr API
Published in: API, Development, NewsPosted by Tyler on 07/06/06
Tonight I’m releasing an offical Snipplr API which will allow anyone to write their own plugins to communicate with Snipplr. You can use the API to talk to Snipplr from other websites, your favorite text editor, or any desktop app. It’s up to you. You’re in control now.
The Snipplr API uses the standard XML-RPC protocol and offers the following methods.
snippet.list- Returns a list of snippets based on the search criteria you provide.snippet.get- Retrieves the details (including source code) for a given snippet.snippet.post- Allows you to store a new snippet into Snipplr.snippet.delete- Allows you to delete a snippet.user.checkkey- Validates a user’s API key.languages.list- Returns a list of available languages.
I’d appreciate feedback letting me know about any problems you run into or features you’d like added.
Also, for all the TextMate hackers out there, I’ve got an offer for you. I’d like to replace the current TextMate Snipplr bundle with a more maintainable Ruby version. (The current one is a mess that uses shell scripting.) I only know a little Ruby, so along with their name on Snipplr and my eternal thanks, the first person to send in a good, working Snipplr plugin for TextMate gets a free Snipplr t-shirt
In fact, if you want to write a plugin for another editor (BBEdit!), and I approve it, I’ll send you a Snipplr t-shirt as well.
Using the API
| Server: | http://snipplr.com |
| End Point: | /xml-rpc.php |
| Full URL: | http://snipplr.com/xml-rpc.php |
snippet.list
snippet.list returns an XML formatted list of snippets matching the specified criteria. Takes two parameters (must be passed in this order):
api_key: Required. The API key of the Snipplr user. Snipplr returns all of this user’s snippets. An error message will be returned if the API key is invalid.
tags: Optional. A space delimited list of tags (keywords) to filter the results by. Snipplr returns snippets which contain at least one of the keywords in the snippet’s title or that match one of the snippet’s tags.
sort: Optional. Can be one of these three values: “title”, “date”, “random”.
limit: Optional. The number of snippets to return.
Note: snippet.list only returns snippets owned by the user or marked as favorites of the user. It does not search all of the snippets on Snipplr.
snippet.get
snippet.get returns a snippet’s details. Takes one parameter:
- snippet_id: Required. The ID of the snippet to fetch. An error message will be returned if the ID is invalid.
snippet.get currently returns the following snippet properties:
- id
- user_id
- username
- title
- language
- comment
- created (datetime when snippet was created)
- source
- snipplr_url (url to view snippet)
- tags (space delimited list of the snippet’s tags)
snippet.post
snippet.post stores a new snippet into Snipplr. Takes four parameters (must be passed in this order):
api_key: Required. The API key of the Snipplr user to which the snippet will belong. An error message will be returned if the API key is invalid.
title: Required. The title of the snippet.
code: Required. The snippet’s source code.
tags: Optional. A space delimited list of keywords to tag the snippet with.
language: Optional. The language to mark the snippet as. Use the language name found in Snipplr’s URLs. For example, “javascript” or “c-plus-plus”.
snippet.delete
snippet.delete deletes a snippet from your Snipplr account. Returns 1 on success, 0 if the snippet could not be deleted. Takes two parameters (must be passed in this order):
api_key: Required. The API key of the Snipplr user that created the snippet you are deleting. An error message will be returned if the API key is invalid.
snippet_id: Required. The ID of the snippet you are deleting.
user.checkkey
user.checkkey validates a user’s API key. Returns 1 if the key is valid. 0 if not valid. Takes one parameter.
- api_key: The API key to validate.
languages.list
languages.list returns a list of supported languages in Snipplr. It returns their urlname and pretty name. The urlname is the value you pass into the snippet.post method. The pretty name is a nicely formatted version of urlname. It’s just there for your reference. This method takes no parameters.
Comments
Textmate Bundle
[...] Based on visitor feedback (thanks, Hernán!) I updated the Snipplr API this morning. The snippet.get method now returns a list of the snippet’s tags. Also, I added a much needed snippet.delete method that (you guessed it) lets you delete snippets from your account. Click here for the API documentation. [...]
[...] You can view the API reference here. [...]
Really, you’re going to make me do that much Math just to post a comment?
Anyway, I’ve got problems accessing the API–I keep getting a 301 Protocol Error (”Moved Permanently”). Any ideas?
No idea. I ran a quick test of the API and received a 200 OK response. Are you connecting to “http://snipplr.com/xml-rpc.php”?
I’m building a plugin for eclipse (http://sourceforge.net/projects/snipplr4e) and I have small wishes for the xml-rpc-api
1.) The api doesn’t allow to remove a snippet from my favorite list. I think “snippet.delete” with the id of a favorite should remove the favorite from my list.
2.) Please indicate the type of the snippet (own or favorite) in the result from “snippet.list”.
Would you be providing a query invocation?
@Carlos - What specifically do you want?
I’m making a Snipplr plugin for the jEdit text editor. Is there a reason why the snippet.list sends an error response when there are no snippets returned by the query? It’s hard to tell on the client side the difference between a real XML-RPC error and an error resulting from a query that has no results.
@ Ian Lews - It shouldn’t be too hard to detect the error. The API returns a faultCode of “1″ and a faultString that says ” No snippets found with tags = ””. Other error codes are:
1 - No snippets found
2 - No snippet found (when search for snippet by ID)
3 - Incorrect API key
4 - Requested method name not found
@ Tyler
Perfect. That’s exactly the info I was looking for. Thanks.
something I think would be great is a “tags.list” or something method that returns a list of all different tags of your snippets
snippet.delete appears to return 0 whether or not the snippet was actually deleted.
That is, when a snippet is successfully deleted (no longer appears with snippet.list) the response is 0.
If snippet.delete is then called on the same snippet_id, the response is the same.
I think I found the cause of the issue Avinash described almost a year ago, since I also have experienced the same issue.
The error message comes when the URL for the server is sent as “http://snipplr.com:80/xml-rpc.php”, which includes the port number. Then a 301 HTTP error message is sent back redirecting to “http://snipplr.com/xml-rpc.php”.
Unfortunately it seems that some XML-RPC libraries always includes the port number in the URL, which makes them unusable together with your API.
Could the redirect system maybe be blacklisted from the xml-rpc.php file?
A little more testing shows that if you just use the HTTP 1.1 standard instead of HTTP 1.0, there is no problems with the 301 error.
@bela - I just fixed the snippet.delete method to return the correct code (1 on successful deletion, 0 otherwise)
Hi Tyler,
Is the server capable of outputting in JSON? Or would it be able to add the function?
snippet.list started returning multiple results for a single snippet.
For instance I searched my own snippets for one matching “mail” and got 7 results for only 2 matched snippets. 3 are for one snippet and 4 for another.
check_email_address() email validator
check_email_address() email validator
check_email_address() email validator
Send multi-part encoded mail with attachments
Send multi-part encoded mail with attachments
Send multi-part encoded mail with attachments
Send multi-part encoded mail with attachments
Is there a possibility of replacing a snippet with a local file?