Feeds

Share Snipplr

Snipplr API

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

[...] 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. [...]

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.

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?

Hi, I’m working on a visual studio plugin for snipplr and it seems that I can retrieve a non private snippet but i can’t retrieve a private snippet even though i can see the snippet in a search result. Also I cannot seem to figure out how to submit a private snippet. This is a pretty important thing. Can anyone help?

Leave a Reply

Name (required)

Mail (will not be published) (required)

Website

6 + 10 × 2 = ?

You may use Markdown to format your comment. HTML renders as source code.