Introduction
Welcome to the Snap.as API! Our API lets you build your own image-based applications or utilities on our platform.
Snap.as is part of the Write.as suite of apps, and follows a similar API design. So if you're familiar with the Write.as / WriteFreely API, working with the Snap.as API should be fairly straightforward.
Libraries
These are our official API libraries:
Language | Fetch | Docs | Repository |
---|---|---|---|
Go | go get github.com/snapas/go-snapas |
GoDoc | GitHub |
Base URL
Call all requests on this base URL: https://snap.as
Errors
Failed requests return with an error
code
anderror_msg
, like below.
{
"code": "400",
"error_msg": "Bad request."
}
The Snap.as API uses conventional HTTP response codes to indicate the status of an API request. Codes in the 2xx
range indicate success or that more information is available in the returned data, in the case of bulk actions.
Codes in the 4xx
range indicate that the request failed with the information provided. Codes in the 5xx
range indicate an error with the Snap.as servers (you shouldn't see many of these).
Error Code | Meaning |
---|---|
400 | Bad Request -- The request didn't provide the correct parameters, or JSON / form data was improperly formatted. |
401 | Unauthorized -- No valid user token was given. |
403 | Forbidden -- You attempted an action that you're not allowed to perform. |
404 | Not Found -- The requested resource doesn't exist. |
405 | Method Not Allowed -- The attempted method isn't supported. |
410 | Gone -- The entity was unpublished, but may be back. |
429 | Too Many Requests -- You're making too many requests, especially to the same resource. |
500, 502, 503 | Server errors -- Something went wrong on our end. |
Responses
Successful requests return with a
code
in the2xx
range and adata
object or array, depending on the request.
{
"code": "200",
"data": {
}
}
All responses are returned in a JSON object containing two fields:
Field | Type | Description |
---|---|---|
code |
integer | An HTTP status code in the 2xx range. |
data |
object or array | A single object for most requests; an array for bulk requests. |
This wrapper will never contain an error_msg
property at the top level.
Authentication
wc := writeas.NewClient()
u, err := wc.LogIn("username", "password")
if err != nil {
// Handle error...
}
sc := snapas.NewClient(u.AccessToken)
All endpoints require authentication. You'll need to pass a Write.as user access token with any requests:
Authorization: 00000000-0000-0000-0000-000000000000
See the Authenticate a User section in the Write.as API docs for information on logging in.
Photos
Upload a Photo
sc := snapas.NewClient("00000000-0000-0000-0000-000000000000")
p, err := sc.UploadPhoto(&snapas.PhotoParams{
FileName: "photo.jpeg",
})
curl "https://snap.as/api/photos/upload" \
-H "Authorization: 00000000-0000-0000-0000-000000000000" \
-F "file=@photo.jpeg"
Example Response
{
"code": 201,
"data": {
"id": "aBCd5678",
"body": null,
"filename": "photo.jpeg",
"size": 219995,
"url": "https://i.snap.as/aBCd5678.jpeg",
}
}
This uploads a new photo to the authenticated user's account.
Definition
POST /api/photos/upload
Arguments
Parameter | Type | Required | Description |
---|---|---|---|
file | file | yes | The photo to be uploaded. |
Returns
A 201 Created
HTTP status and the newly created photo object.
Delete a Photo
curl "https://snap.as/api/photos/aBCd5678" \
-X DELETE \
-H "Authorization: 00000000-0000-0000-0000-000000000000"
This deletes a photo from the authenticated user's account.
Definition
POST /api/photos/{PHOTO_ID}
Arguments
None.
Returns
A 200 OK
HTTP status.
Users
Retrieve User's Photos
curl "https://snap.as/api/me/photos" \
-H "Authorization: 00000000-0000-0000-0000-000000000000"
Example Response
{
"code": 200,
"data": [
{
"id": "aBCd5678",
"body": null,
"filename": "photo.jpeg",
"size": 219995,
"url": "https://i.snap.as/aBCd5678.jpeg",
},
{
"id": "efGh9012",
"body": null,
"filename": "vacation.jpg",
"size": 40346,
"url": "https://i.snap.as/efGh9012.jpg",
}
]
}
This retrieves all photos on a user's account.
Definition
POST /api/me/photos
Arguments
None.
Returns
A 200 Created
HTTP status and all photos on the user's account.
Organizations
Upload an Org Photo
sc := snapas.NewClient("00000000-0000-0000-0000-000000000000")
p, err := sc.UploadPhoto(&snapas.PhotoParams{
OrgAlias: "snap-as",
FileName: "photo.jpeg",
})
curl "https://snap.as/api/organizations/snap-as/photos/upload" \
-H "Authorization: 00000000-0000-0000-0000-000000000000" \
-F "file=@photo.jpeg"
Example Response
{
"code": 201,
"data": {
"id": "aBCd5678",
"body": null,
"filename": "photo.jpeg",
"size": 219995,
"url": "https://i.snap.as/aBCd5678.jpeg",
}
}
This uploads a new photo to the chosen organization.
Definition
POST /api/organizations/{alias}/photos/upload
Arguments
Parameter | Type | Required | Description |
---|---|---|---|
file | file | yes | The photo to be uploaded. |
Returns
A 201 Created
HTTP status and the newly created photo object.