codesnipp.it API v2
API Index
Apps & Plugins Created by Users
- Android App - view timelines & post snipp.its by Stephan Losa
- Firefox Extension - view timelines & post snipp.its from Firefox by Alex Hall
- Chrome Extension - view timelines & post snipp.its from Chrome by Alex Hall
If you've created something awesome with our API, please let us know and we'll list it here!
Changelog
Timeline
- 11.07.11
- Added rate limiting to the API (currently set at 150 per hour)
- 27.05.11
- Added avatars to the timeline events
- 26.05.11
- Added the event ID to each timeline entry
- 25.05.11
- Added avatar function
- 24.05.11
- Updated the documentation a bit
- Added the delete snippit functions
- Event types end point enabled
- 23.05.11
- Complete redo of the API to fit in with v2 of the site
- Default output is now JSON :)
- Waaaaaaaaaay more methods exposed now as well
- 10.24.10 - initial version of the API is released
-
10.25.10
- Fixed syntax highlighter issues with the guide that caused sample XML to show up incorrectly on the page
- Version 1.01 is released
- 11.03.10 - XML headers are now generated if your request to the API results in an error. Previously the headers were only sent for successful requests.
Version
- 1.00 - 10.24.10 - initial version of the API
-
1.01 - 10.25.10
-
Server Response > List > Event > Snippit now contains a new node called Category:
<Category id="1"> <Name><![CDATA[HTML]]></Name> </Category>
- Server Response > List > Event > Snippit will return information in the following nodes as sanitized: Name, Body, Tags>Tag>Name The data is sanitized via PHP:htmlspecialchars. To retrieve the raw data, replace the response data in those tags: '&' with '&', '"' with '"' (double quote), '<' with '<' and '>' with '>'
-
Server Response > List > Event > Snippit now contains a new node called Category:
-
2.0a - 23.05.11 - new v2 of API
Key change is that the responses are now in JSON format
Overview
Most actions you perform on codesnipp.it are recorded internally as events. For example, if you add a snipp.it, follow someone, or like something, an event is created in our DB (DataBase) to commemorate your new action. The site then uses these events to construct the markup you see when looking at your timeline, someone else's profile, etc.
If you're planning to use the API, it's important to understand the difference between the concepts of the action and the event it generates. I.e. when you add a snipp.it, the action results in the snipp.it's name, body, category, etc. being stored in the snipp.its table. At the same time, the event of you adding the snipp.it results in data such as snipp.it ID, time of the event, event type, etc. being stored in the events table.
Keep in mind that if you have the event data, you can gain access to all pieces that generated that event. I.e. if you get a hold of the event data that was created when a user commented on a snipp.it, you'd be able to figure out that user's information by using a user ID stored in the event. You'd also be able to load the details of the snipp.it the user commented on by using the snipp.it ID stored in the event.
Why am I telling you all this? Because the API will in most cases return data describing events that fit the description you create in your request. But enough high level talk. Let's jump head first into the guts of the API :)
API v2
As with most API systems, you have a endpoint :) Ours, being funky and all, is http://codesnipp.it/v2/api Pretty nifty hey?
Sections
- Rate Limiting
- Authentication
- Useful information
- Timelines
- Snippits
- Users
- Comments
- Add
- Edit (coming soon!)
- Delete (coming soon!)
- Ninja Account Holder's Chat API (coming soon!)
- Ninja Account Holder's Live Demonstration API (coming soon!)
- Ninja Account Holder's Private Snippit Collaboration API (coming soon!)
- Final Thoughts
Rate Limiting
Up until now, the API was unlimited in its usage, i.e. you could make as many requests as you wanted. Due to some services we will be pushing out soon, the time has come to impose some restrictions to prevent abuse of the environment. As of current, the API has been configured to allow a user 150 calls per hour, which roughly translates to 2.5 calls per minute. To check how many calls you have left, or if any other restrictions etc have been imposed on your account to the API, you can call the status endpoint at any time. This endpoint, together with the listMethods endpoint do not count towards your call limiting, so feel free to use them :) The status endpoint requires you to either send through your API key, or your authenticated API token. If you don't provide it, your IP address will be used as a reference point, but this could pose problems as a blacklisting system is being developed and if your IP block appears on this list it would mean you will have no access to the API even though you have calls remaining, so rather play it safe and send these details through :)
Request
$status = call_api( 'status', array('api_key'=>'api-key-goes-here'), 'POST' );
// OR
$status = call_api( 'status', array('auth_token'=>'authenticated-token-goes-here'), 'POST' );
Response
[
{
status: "success"
message: {
status: "active"
calls_remaining: 145
}
}
]
// OR
[
{
status: "success"
message: {
status: "blacklisted"
}
}
]
// OR
[
{
status: "success"
message: {
status: "limited"
calls_remaining: 0
}
}
]
// OR
[
{
status: "success"
message: {
status: "whitelisted"
calls_remaining: 999999999
}
}
]
Authentication ... the OAuth way
But what would a API be if it wasn't secure? Well, we have a function for that! Simply point your code to http://codesnipp.it/v2/api/auth/your-api-key-here to get a API authentication token. This token is used in all communications hence forth as well as with your API key. Yup, we are now running OAuth security!!
Request
If you are using PHP (which most of you would be), you would simply do the following to have your access token ready for use:
$auth_token = call_api( 'auth', array(API_KEY) );
$auth_token = json_decode($auth_token);
$auth_token = $auth_token[0]->token;
Don't fret about what function call_api is right now, that is just a function I use to call this API for me (will post it on CS for your convenience as well)
If, however, you are like me, and have multiple languages that you delve into, especially when coding some nifty stuff (like a Android App for instance *wink wink*), you would use the following method in Java to get the authentication token:
/**
* Used to do a GET request to the API
* @param function The function to be called on the API stack
* @param parameters The additional parameters to pass to the stack
* @return Object
*/
private static Object do_get(String function, String parameters) {
Object content = new Object();
if(parameters == "" || parameters == null) {
parameters = "/";
} else {
parameters = "/" + parameters;
}
try {
HttpClient client = new DefaultHttpClient();
BasicHttpContext localContext = new BasicHttpContext();
HttpHost targetHost = new HttpHost("codesnipp.it", 80, "http");
HttpGet http = new HttpGet( "http://codesnipp.it/v2/api/" + function + parameters );
http.setHeader("Content-Type", "application/json");
HttpResponse response = client.execute(targetHost, http, localContext);
HttpEntity entity = response.getEntity();
content = EntityUtils.toString(entity);
} catch(Exception e) {
e.printStackTrace();
}
return content;
}
Object response = do_get("auth", api_key);
JSONArray ja = new JSONArray(response.toString());
for(int i = 0; i < ja.length(); i++){
JSONObject jo = ja.getJSONObject(i);
token = jo.getString("token");
}
See, pretty easy, right? ;) Oh, and that is working code btw
Response
A typical response from the API stack for a authentication request would look something like the following (note: this session key is encrypted with my API key when I generated this, so its useless to you :P):
[{"token":"2f3ee98b5ff0acf79e2a39105a76188d"}]
Some useful information
Not all the functions require that you are logged in/authenticated on the API stack. For instance, calling http://codesnipp.it/v2/api/categories directly in your browser will generate a nice listing of the categories available on the API stack for your snippit-awesomeness. What's more, in the redesign of the API I thought it worthwhile to give you guys something useful: not just my ramblings here on this page, but a API endpoint that you can use to check quickly what function does what and what parameters are required. Point your browser to http://codesnipp.it/v2/api/listMethods and you will be presented with the list of methods ;) What is more, it also tells you what to expect back, and the type of request that needs to be made against the method
The Timelines
Update:API Users, give thanks to Alex Hall who requested that event ID's be included with all events visible on the timeline, and he had his request granted [API Update Date - 26.05.11 | Changelog Entry 2e066f2ad13c]
Update:Wow, it would seem that Alex Hall is on fire! Thanks to his request, you all now have the ability to either have a avatar string present per event as well :) All you have to do is send a additional parameter named avatar_size as a POST parameter (while keeping to the size limitations) and you will be given a additional field in the $event->user array named avatar [API Update Date - 27.05.11 | Changelog Entry 0a890bd20b42]
As with the previous API, you can still retrieve all the timelines. One difference though, only the one's that require you to be authenticated will enforce authentication where the rest will happily abide to your calls. So, what does the timeline endpoint look like now? Well, firstly, the endpoint is: http://codesnipp.it/v2/api/timeline/ From here you would do some kewl stuff such as :
Specify a specific timelineWhen calling the timeline endpoint, you would need to specify which timeline you are requesting. I tried to make it as simple as possible, so that you can just for instance call http://codesnipp.it/v2/api/timeline/everyone to generate a list of the everyone timeline. The various timelines available are: everyone, following (requires authentication), likes (requires authentication), popular, updates (requires authentication) and private (requires authentication and you need to be a Ninja account holder)
Filter the event typesWhen you are accessing a timeline, you can filter the type of events (adds/questions) easily, by just specifying an additional URL parameter, such as http://codesnipp.it/v2/api/timeline/everyone/add. That will render all the adds by everyone on the network, whereas http://codesnipp.it/v2/api/timeline/everyone/questions will render the questions that were added
Limiting the number of events retrievedWhen calling the timelines, you are able to limit the number returned (the default being 15). Simply POST to the stack, as show here:
PHP
// Call the everyone timeline
$timeline = call_api( 'timeline/everyone', array('limit' => 2), 'POST' );
$timeline = call_api( 'timeline/everyone/questions', array('limit' => 2), 'POST' );
BASH
curl -d "limit=2" htp://codesnipp.it/v2/api/timeline/everyone
curl -d "limit=2" htp://codesnipp.it/v2/api/timeline/everyone/questions
This will return the everyone timeline as well as the questions timeline, but only the last 2 events for each of the timelines. Quick and easy :)
Continue from a previous timelineSomething new for you all :) When retrieving a timeline, you will notice that sometimes there is a last array entry with special data in it. What this will tell you are the following:
{
more_rows: true // There are more events for this timeline
last_id: 1297922144 // The event ID of the last event in the timeline
new_events: 1304005720 // The first event in the timelines' event ID (more about this in the next section)
}
So, this is where it becomes fun now ^^ You can now post to the same API stack that you want to continue from the last ID, i.e.
PHP
$timeline = call_api( 'timeline/popular', array('limit' => 10, 'last_id' => 1305154171 ), 'POST' );
BASH
curl -d 'limit=10' -d 'last_id=1305154171' http://codesnipp.it/v2/api/timeline/popular
And this will return the next 10 entries. This data will keep occurring until there are no more events available for the specified timeline
Get the latest events for the timelineNow this is something that I will be using, as well as you :) This function is powerful when coupled up with a NodeJS server and you can then do some wonderfull streaming type things *hint* *hint*
The endpoint for this function is the only one of the timeline functions that doesn't get called via http://codesnipp.it/v2/api/timeline, but has its own endpoint namely http://codesnipp.it/v2/api/checkNewEvents. So do take note of that! Also, this function only works on the following timelines: everyone, following (requires authentication), likes (requires authentication), updates (requires authentication) and private (requires authentication and you need to be a Ninja account holder)
Request
PHP
$timeline = call_api( 'checkNewEvent', array('timeline_name' => 'everyone', 'last_id' => 1305154171 ), 'POST' );
BASH
curl -d 'timeline_name=everyone' -d 'last_id=1305154171' http://codesnipp.it/v2/api/checkNewEvents
When calling this endpoint, it requires the following:
- timeline_name: Pretty much needed, don't you think? [required]
- sub_feed: If you want the sub feeds (all|add|questions) on the applicable timeline [optional]
- last_id: Without this, you won't get anywhere. This is the ID provided to you in the timeline requests as new_events [required]
- auth_token: This is used for the timelines that require authentication, so keep that in mind :) [optional/required]
Response
// When there are events
[
-[
-{
-meta: {
event_id: "15562"
event_type: "add"
likes: "0"
comments: "0"
time: "2011-05-26 23:53:25"
category: "Java"
categorySlug: "java"
-tags: [
-{
tag: "tag1"
slug: "tag1"
}
-{
tag: "tag2"
slug: "tag2"
}
-{
tag: "tag3"
slug: "tag3"
}
]
}
-user: {
full_name: "John Clarke"
slug: "jc"
}
name: "Tag test"
slug: "tag-test"
}
}
],
-{
more_rows: true
last_id: 1306015452
new_events: 1306446805
}
]
// When there are no events, a blank array
[]
As you can see, the full entries are returned, not just event IDs. There are a multitude of reasons for this, but the main reason is that you want to have the events ready when you are checking if there are new one's so that they can be displayed, not true? ;) So instead of having multiple calls for new events, there is a single call and you have everything you need from there.
Authenticated timelinesThe timelines that require you to be authenticated, will just as easily be accessible, i.e.
PHP
$auth_token = call_api( 'auth', array(API_KEY) );
$auth_token = json_decode($auth_token);
$auth_token = $auth_token[0]->token;
$timeline = call_api( 'timeline/updates', array('limit' => 10, 'api_key' => $api_key, 'auth_token' => $auth_token), 'POST' );
Snippits
AddingSo now that we have wettened your appetites, lets get into the juicy stuff! You are now able, as previously, to post snippits via the API. But, its now simpler and faster :) Look at this example for instance:
Request
/** Create a snippit **/
$s_body = '
<script>
console.log("Ooooo, some javascript");
</script>
<?php
$how = "Fun is this?";
?>
';
$response = call_api( 'snippit/add', array('snippit_name'=>'API v2 test', 'snippit_type'=>2, 'snippit_body'=>$s_body, 'snippit_category'=>17, 'snippit_tags'=>'test,testing,api v2', 'auth_token'=>$auth_token), 'POST' );
You will notice that for the snippit_category I use a number. These numbers are available via the categories endpoint. This is the same case for the snippit_type field where you are required to specify the type, which are available from http://codesnipp.it/v2/api/event_types (if nothing is specified it is just a normal add event). Also, the endpoint for this function is obviously http://codesnipp.it/v2/api/snippit/add ;) Once the addition was successfully, you will be presented with:
Response
{
"status":"success",
"message":"Snippit successfully saved"
}
But, if the addition was unsuccessful for some weird reason, you would receive the following:
{
"status":"error",
"message":"Could not save the snippit at this time, please try again"
}
There are various cases where this could occur, for instance another snippit with the same title already exists (this is for the URL generation and won't be changed anytime soon), as show here:
{
"status":"error",
"message":"Could not save the snippit at this time as another snippit with the same title already exists"
}
The message would always contain information pertaining to the error, so keep a eye on that :)
As with the site, you can view a snippit and its details.
Request
In order to use this endpoint, your query would go to http://codesnipp.it/v2/api/snippit/view with the following data:
$snippit = call_api( 'snippit/view', array('api-demo') );
As you can see, you need the slug for the snippit, which are readily available from the timelines endpoint
Response
{
"poster":
{
"name":"John Clarke",
"slug":"jc"
},
"snippit":
{
"id":"1275",
"title":"API Demo",
"created":"2011-05-22 03:09:47",
"category":"ColdFusion",
"categorySlug":"cf",
"body":"<script>\nconsole.log(\"Oooo, some javascript\");\n<\/script>\n<?php\n$how = \"Fun is this?\";\n?>",
"comment_count":"1",
"tags":["test","testing","api v2"],
"slug":"api-demo"
},
"comments":
[
{
"commentID":"3663",
"status":"1",
"timestamp":"2011-05-22 03:09:47",
"body":"\nThis is a API comment test\n<code><?php\n$bleh = 'foo';\necho $bleh;\n?>\n<\/code>\n",
"comment_slug":null,
"fullName":"John Clarke",
"userSlug":"jc"
}
]
}
}
As you can tell from this, you have the following data returned to you:
- snippit title
- snippit body
- who posted the snippit
- which category it belongs to
- the tags of the snippit
- when it was created (timestamps are GMT based for easier conversion to your native timezones)
- any comments that are associated with a snippit
Something very new in this version of the API is the ability to delete a snippit. The logic is already built in to check whether a delete request is from the owner, so you don't have to bother about that yourselves :)
Request
PHP
$snippit = call_api( 'snippit/delete', array('snippit_name'=>'api-v2-test', 'auth_token'=>$auth_token), 'POST' );
BASH
curl -i -d "snippit_name=api-v2-test" -d "auth_token=08fa69986ce77007da08671ee3babdfa" http://codesnipp.it/v2/api/snippit/delete
As you can tell from this, your endpoint is http://codesnipp.it/v2/api/snippit/delete, and it requires two parameters, snippit_name which is the URL slug of the snippit that you want to delete together with the auth_token that you get from authenticating on the API stack
Response
// Successful deletion
[{"status":"success","message":"Snippit successfully deleted"}]
As with all functions, you will receive a status of error if anything went wrong with the message containing information about what did go wrong. If, for instance, your request is against a snippit that doesn't belog to you, you will be returned the following data:
[{"status":"error","message":"Sorry, but that snippit doesn\'t belong to you"}]
Users
View ProfileAs of current, this endpoint is still going to grow a bit, i.e. allow users to update their profiles via the API, change passwords, etc etc. For the time being, I have set it up that you can view a user's profile information. The endpoint for this is http://codesnipp.it/v2/api/view_user and all you have to do is add the user slug to the end, e.g. http://codesnipp.it/v2/api/view_user/jc. Note that this endpoint is going to change in either the next version or the one after, so don't depend to heavily on it please :) I will keep you updated however, and code in some fallback just in case
Request
$userProfile = call_api( 'view_user/jc' );
Response
{
user_data:
{
firstName: "John"
lastName: "Clarke"
fullName: "John Clarke"
website: "http://blog.jc-interactive.co.za"
slugName: "jc"
geoData: "Cape Town, South Africa"
twitterName: "jc1arke"
profileData:
{
comments: 100
cs_posts: 42
likes: 612
}
}
}
Just some basic information, nothing major.
Get user avatarDue to security implementations, we are not exposing the user's e-mail addresses and as such you can't make direct queries to Gravatar in order to retrieve the avatar. The endpoint for this functionality is http://codesnipp.it/v2/api/avatar and requires the data to be POSTed to it
Request
PHP
$avatar = call_api( 'avatar', array('username'=>'jc', 'size'=>50), 'POST' );
BASH
curl -d 'username=jc' http://codesnipp.it/v2/api/avatar
Response
// Successfull
[{"avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=b47e71287044e9400eeffc0bb75d9c09&size=50&default=http:\/\/codesnipp.it\/resources\/images\/avatar_50x50.png"}]
// Incorrect avatar size specification (allowed sizes: 50, 108, 114)
[{"status":"error","message":"Invalid image size specifed"}]
As with other error messages, the status will be error and message will contain an relevant error message.
Commenting
Add CommentAs we all know by now, some of us loooooove to comment on these lovely snippits on the site :) So, you can do that now as well via the API. The endpoint for this is http://codesnipp.it/v2/api/comment and you would be required (by means of example) to send the following data:
Request
$c_body = '
This is a API comment test
<code>
<?php
$bleh = "foo";
echo $bleh;
?>
</code>
';
$comment = call_api( 'comment', array('snippit_slug'=>'api-demo','comment_body'=>$c_body,'api_key'=>$api_key,'auth_token'=>$auth_token), 'POST' );
So, the elements required are:
- snippit_slug: This is the slug of the snippit as it appears in the URL (once more, this available via the timeline and snippit endpoints)
- comment_body: What would a comment be without its contents :)
- api_key and auth_token: won't be able to post without these two bad boys :)
Response
{
"status":"success",
"message":"Comment successfully added"
}
But if the comment couldn't be submitted successfully, it would print out the same error information that you would get for snippit submissions, with a status of error and a message containing information as to why it didn't succeed
Final thoughts :)
Well, there you have it, v2 of the API stack. Have a browse through the listMethods as that would be the most up-to-date information about the API, as well as contain some methods that are not listed here yet but are available to you :) As always, please make use of the bug reporter if you find anything not working or any bugs
API v1.x (Legacy)
Our API endpoint (i.e. the URL you will be sending all of your requests to) is http://codesnipp.it/api.php At this point you can do two things with the API
- You can retrieve event information. This is just like looking at any one of the timelines on your codesnipp.it homepage. Except instead of the information being presented as markup to your browser, it's presented as XML to your script.
- You can add new snipp.its. This is just like adding a new snipp.it from your codesnipp.it homepage. The same restrictions apply. I.e. you have to have a name, you can't post more snipp.its than your account type allows, etc.
In order for the API to be granted access to a user's information, they have to enable "API Access" and generate an API key in their account section. The API key will be used to authenticate any applications requesting access to user's account. If the user does not grant API access to his account or an application sends a key that doesn't match the one specified in his/her account settings, an error will be generated and no user information will be delivered.
All requests need to be wrapped in a Request node. The version number dictates the format of the response. At this point the server supports all existing version. See bottom of the page for more version information. I.e.:
<Request version="1.01">...</Request>
Authentication
To authenticate your request, include an Authentication node with Username and XmlKey nodes inside. Username must be the email address of the user who's account you're trying to access. XmlKey is the API key that user set up in their account settings.
<Request version="1.01">
<Authentication>
<Username>user@user.com</Username>
<XmlKey>abc123</XmlKey>
</Authentication>
...
</Request>
Responses
All responses sent back from our server will be in the following format. In all responses, the Action tag will simply contain the action you asked our server to perform for you in your request (get your mind out of the gutter! >:V).
<Response>
<Action>...</Action>
<Status>...</Status>
<Code>...</Code>
<Messages>...</Messages>
...
</Response>
You can easily determine whether your request succeeded or not by checking the Status node. If it is set to "SUCCESS", you are good to parse through the rest of the information. If it's set to "FAIL", an error was generated by the server in response to your request :( In that case, they will be returned in the following format.
<Response>
<Action>...</Action>
<Status>FAIL</Status>
<Code>501|502|503...</Code>
<Messages>Error: Authentication failed. Username is invalid.|Error: Authentication failed. XML Key is invalid.|Error: Authentication failed. User does not allow API access.</Messages>
</Response>
The Code tag will contain all of the error codes separated by pipes (|). The Messages tag will contain all of the error messages separated by pipes. Codes and messages are related. I.e. the first error code is for the first error message, the second code is for the second error, etc. Even if your request succeeds, the Code and Messages elements will be present. They will just be empty. We did this so we can implement warnings, notifications, etc. in the future.
Retrieving Event Information
All events are sent back in descending order. I.e. the newest events will be returned to you first and the oldest last (this is just how our timelines work on the actual site).
Request
<Request version="1.01">
<Authentication>
<Username>user@user.com</Username>
<XmlKey>abc123</XmlKey>
</Authentication>
<Action>...</Action>
<Limit>...</Limit>
<Skip>...</Skip>
<SkipId>...</SkipId>
<Filter>...</Filter>
</Request>
-
Action - required - what are you asking the server to do for you? Possible values:
- ACTION_TYPE_TIMELINE_FOLLOWING - give me events from the "following" timeline.
- ACTION_TYPE_TIMELINE_EVERYONE - give me events from the "everyone" timeline.
- ACTION_TYPE_TIMELINE_POPULAR - give me events from the "popular" timeline.
- ACTION_TYPE_TIMELINE_LIKE - give me events from the "you liked" timeline.
- ACTION_TYPE_TIMELINE_INCOMING - give me events from the "incoming" timeline.
- ACTION_TYPE_TIMELINE_PRIVATE - give me events from the "private" timeline.
- Limit - optional - how many events to return. Defaults to 15
- Skip - optional - how many events to skip when generating the response data. Defaults to 0. You can use this to get older events. I.e. if you get a list of 5 events in your first call and want to get the next 5 events in your second call, you could set this to 5 before sending us your second request. Keep in mind that this isn't guaranteed to skip exactly the events you received through your first request. I.e. if you get events ID 50-46 (5 total - #50, 49, 48, 47, 46) in your first request, but before you send your second one the user deleted event ID 49, the system would then skip the first 5 (#50, 48, 47, 46, 45 - notice #49 is gone so #45 became a part of the first 5) events that still exist and you would end up getting events ID 44-40 (5 total - #44, 43, 42, 41, 40) thus skipping #45. To avoid this you can use the SkipId node described below.
- SkipId - optional - ID of the element you want to ignore. This is used to get older events. If this is passed, all of events with the given ID and higher will be ignored by the system when creating response data. Using the same example as Skip, if you get a list of 5 events in your first call, you would parse the response data and figure out the ID of the last event returned (specified in response XML) You could then pass that ID as SkipId to get the next 5 oldest events. In this case, if you get events ID 50-46 (5 total - #50, 49, 48, 47, 46) in your first request, but before you send your second one the user deleted event ID 49, the system would then skip all events up to and including ID 46 and return the next 5 - ID 45 - 41 (5 total - #45, 44, 43, 43, 41). Notice that #45 was not skipped.
-
Filter - optional - only supported by ACTION_TYPE_TIMELINE_FOLLOWING and ACTION_TYPE_TIMELINE_EVERYONE because "following" and "everyone" are the only two timelines you can filter on your codesnipp.it homepage. Controls what kind of events are returned in the response.
- EVENT_FILTER_TYPE_ALL - default value - display all events
- EVENT_FILTER_TYPE_ADDED - display only new snipp.it added events
- EVENT_FILTER_TYPE_QUESTIONS - display only new question added events
Response
Our server will return the response in the following format:
<Response>
<Action>ACTION_TYPE_TIMELINE_EVERYONE</Action>
<Status>SUCCESS</Status>
<Code></Code>
<Messages></Messages>
<List length="1">
<Event id="6642" type="snippit_add" time="1287955202">
<Snippit id="74">
<Link>http://codesnipp.it/code/74</Link>
<Name><![CDATA[Name of my snipp.it]]></Name>
<Body><![CDATA[body of my snipp.it
split up on myltiple lines]]></Body>
<Category id="1">
<Name><![CDATA[HTML]]></Name>
</Category>
<Tags length="4">
<Tag id="3932">
<Name><![CDATA[name of the first tag]]></Name>
</Tag>
<Tag id="3933">
<Name><![CDATA[name of the 2nd tag]]></Name>
</Tag>
<Tag id="3934">
<Name><![CDATA[name of the third tag]]></Name>
</Tag>
<Tag id="3935">
<Name><![CDATA[name of the 4th tag]]></Name>
</Tag>
</Tags>
</Snippit>
<User>
<Link>http://codesnipp.it/smellyfish</Link>
<Name><![CDATA[Nikita Makeyev]]></Name>
</User>
</Event>
</List>
</Response>
- List - node encompassing all of the Event nodes in the response. "length" attribute determines how many Event nodes are contained within.
-
Event - node containing all of the event information. "id" attribute contains the internal ID of the event. "time" attribute uses a UNIX timestamp to describes when this event happened. "type" attribute describes what kind of an event this is. Possible types are as follows:
- snippit_add - a snipp.it was added in this event
- snippit_like - a snipp.it was liked in this event
- snippit_comment - a comment was added to a snipp.it in this event
- snippit_question_add - a question was added in this event
- user_follow - a user was followed in this event
- user_unfollow - a user was unfollowed in this event
- Snippit - node containing all of the information about the snipp.it involved in this event. "id" attribute contains the internal ID of the snipp.it.
- User - node containing all of the information about the user involved in this event.
Adding new snipp.its
Request
<Request version="1.01">
<Authentication>
<Username>...</Username>
<XmlKey>...</XmlKey>
</Authentication>
<Action>ACTION_TYPE_SNIPPIT_ADD</Action>
<Object>
<Name><![CDATA[Test Snipp.it]]></Name>
<Body><![CDATA[Hi!
/*alert("test");*/
This body will has new lines in it.]]></Body>
<Question />
<Private />
<Category><![CDATA[PHP]]></Category>
<Tags>
<Tag><![CDATA[a]]></Tag>
<Tag><![CDATA[b]]></Tag>
<Tag><![CDATA[c]]></Tag>
<Tag><![CDATA[d]]></Tag>
</Tags>
</Object>
</Request>
Action of ACTION_TYPE_SNIPPIT_ADD will indicate that you are trying to add a snipp.it through the API. Snipp.it name, body and category are required. If you include the Question node, the snipp.it will be posted as a question. Omit it otherwise. If you include the Private node, the snipp.it will be posted as a private entry. Omit it otherwise.
Response
If you request succeeds, the response will contain the information of the event generated by our system on behalf of your request.
<Response>
<Action>ACTION_TYPE_SNIPPIT_ADD</Action>
<Status>SUCCESS</Status>
<Code></Code>
<Messages></Messages>
<List length="1">
<Event id="6651" type="snippit_question_add" time="1287961596">
<Snippit id="1283">
<Link>http://codesnipp.it/code/1283</Link>
<Name><![CDATA[Test Snipp.it]]></Name>
<Body><![CDATA[Hi!
/*alert("test");*/
This body will has new lines in it.]]></Body>
<Category id="4">
<Name><![CDATA[PHP]]></Name>
</Category>
<Tags length="4">
<Tag id="3940">
<Name><![CDATA[a]]></Name>
</Tag>
<Tag id="3941">
<Name><![CDATA[b]]></Name>
</Tag>
<Tag id="3942">
<Name><![CDATA[c]]></Name>
</Tag>
<Tag id="3943">
<Name><![CDATA[d]]></Name>
</Tag>
</Tags>
</Snippit>
<User>
<Link>http://codesnipp.it/smellyfish</Link>
<Name><![CDATA[Nikita Makeyev]]></Name>
</User>
</Event>
</List>
</Response>