# Snapchat API ## Base URL https://snapchat-example-api.herokuapp.com/api/v1/ ## Notes - All endpoints accept JSON payloads for parameters - Must include "Content-Type" HTTP header with value "application/json" - All endpoints accept `/users/authenticate` require the `X-Api-Token` HTTP header - Test Users - jparishy, atecle, adeluca, zallen, enagele - All have password: "password" (no quotes) ## User APIs ### Authentication - POST /users/authenticate - Parameters - `username` - String - `password` - String - Returns - 401 if Invalid - 200 if Valid Example: ``` ➜ ~ curl -X POST -H "Content-Type: application/json" -d '{"username":"atecle","password":"password"}' http://snapchat-example-api.herokuapp.com/api/v1/users/authenticate {"user":{"id":2,"username":"atecle"},"api_token":"588886466b8206a50a0be4189f50c54f"} ``` ### Get Friends - GET /users/friends - Parameters: None - Returns - Array of User Objects Example: ``` ➜ ~ curl -H "X-Api-Token: cddb6686e7b408dc7292ea92bd833243" https://snapchat-example-api.herokuapp.com/api/v1/users/friends [{"id":2,"username":"atecle"},{"id":3,"username":"zallen"},{"id":4,"username":"adeluca"},{"id":5,"username":"enagele"}] ``` ## Snap APIs ### Get Snaps - GET /snaps - Parameters: None - Returns - 200 with array of snaps - Includes outgoing and incoming snaps - Snaps previously marked as read do not contain an `image_url` (it will be `null`) Example: ``` ➜ ~ curl -H "X-Api-Token: cddb6686e7b408dc7292ea92bd833243" https://snapchat-example-api.herokuapp.com/api/v1/snaps [{"id":1,"image_url":"http://placekitten.com/1080/1920","from_user":{"id":1,"username":"jparishy"},"unread":true,"created_at":"2016-01-20T04:37:41.528Z"},{"id":2,"image_url":"http://placekitten.com/1080/1920","from_user":{"id":1,"username":"jparishy"},"unread":true,"created_at":"2016-01-20T04:37:41.553Z"},{"id":3,"image_url":"http://placekitten.com/1080/1920","from_user":{"id":2,"username":"atecle"},"unread":true,"created_at":"2016-01-20T04:38:53.092Z"}] ``` ### Send a Snap - POST /snaps - Parameters - `to` - Integer OR Array of Integers - `image_url` - String of the S3 URL for the Image returned by the Media API endpoint `/media/upload` - Returns - 200 with the array of Snaps created Example: ``` ➜ ~ curl -H "X-Api-Token: cddb6686e7b408dc7292ea92bd833243" -H "Content-Type: application/json" -X POST -d '{"to":1, "image_url":"https://snapchat-api-photos.s3.amazonaws.com/snaps/snap_dcd02410e1dff942effa0b42f2df8e93.jpg"}' https://snapchat-example-api.herokuapp.com/api/v1/snaps [{"id":42,"image_url":"https://snapchat-api-photos.s3.amazonaws.com/snaps/snap_dcd02410e1dff942effa0b42f2df8e93.jpg","to_user":{"id":1,"username":"jparishy"},"from_user":{"id":1,"username":"jparishy"},"unread":true,"created_at":"2016-01-24T02:32:39.708Z"}] ``` ### Mark a Snap as Read - PUT /snaps/:snap_id/read - Parameters: None - Returns - The snap object that was updated with the `image_url` removed Example: ``` ➜ ~ curl -H "X-Api-Token: cddb6686e7b408dc7292ea92bd833243" -X PUT https://snapchat-example-api.herokuapp.com/api/v1/snaps/3/read {"id":3,"image_url":null,"created_at":"2016-01-20T04:38:53.092Z","updated_at":"2016-01-20T04:49:15.607Z","unread":false,"to_user_id":1,"from_user_id":2} ``` ### Get a Single Snap by ID - GET /snaps/:snap_id - Parameters: None - Returns - The snap object - 404 if not found - 401 if not for you Example: ``` ➜ ~ curl -H "X-Api-Token: cddb6686e7b408dc7292ea92bd833243" https://snapchat-example-api.herokuapp.com/api/v1/snaps/2 {"id":2,"image_url":"http://placekitten.com/1080/1920","created_at":"2016-01-20T04:37:41.553Z","updated_at":"2016-01-20T04:37:41.558Z","unread":true,"to_user_id":4,"from_user_id":1} ``` ## Media ### Upload an Image - POST /media/upload - Parameters: - `file` - The image using URL encoded form image uploading - Returns: - - `image_url` - A dictionary containing the URL to the uploaded image on S3 Example: ``` ➜ Desktop curl -X POST -H "X-Api-Token: af92581a0a48bc113fd3dda4ce543101" https://snapchat-example-api.herokuapp.com/api/v1/media/upload -F "file=@pul.gif" {"image_url":"https://snapchat-api-photos.s3.amazonaws.com/snaps/snap_dcd02410e1dff942effa0b42f2df8e93.jpg"} ```