u-social

Responses and errors

Every response with a body, including errors, has the same envelope { Response: { status, data } }. One parser covers the whole API.

The code, total, page and pagesize fields are strings. Convert them to numbers on the client side. Fields in data have regular JSON types.

Envelope fields

Response.status.codestring
HTTP status code as text, for example "200".
Response.status.msgstring
Description of the result. For errors, it explains the cause.
Response.status.totalstring
Total number of items in paginated lists, "0" in other responses.
Response.status.pagestring
Page number, counted from 0.
Response.status.pagesizestring
Page size.
Response.dataobject | array | null
The actual data. null for errors.
Response 200
{
  "Response": {
    "status": {
      "code": "200",
      "msg": "OK",
      "total": "0",
      "page": "0",
      "pagesize": "0"
    },
    "data": {
      "id": 12,
      "name": "Linden Tree Café",
      "description": "Café in the old town"
    }
  }
}

Pagination

Paginated lists, such as GET /projects/{projectId}/posts, accept the page (from 0, default 0) and size (1–100, default 20) parameters. The number of pages is ceil(total / pagesize).

Response excerpt
{
  "Response": {
    "status": {
      "code": "200",
      "msg": "OK",
      "total": "47",
      "page": "1",
      "pagesize": "20"
    },
    "data": []
  }
}

Errors

For errors, data is null and msg describes the cause in English. Field validation errors have the form field: message, and several errors are separated by semicolons.

Exception: a 401 caused by a missing or invalid access token has no body. Recognize it by the HTTP status code.

HTTP status codes

200
Request completed.
201
Resource created (account, project).
202
Post accepted. Publishing continues in the background.
204
Completed, no response body (sign-out).
400
Invalid data. msg says which field and why.
401
Missing or invalid access token, or the session has expired.
403
Plan limit reached.
404
The resource does not exist or belongs to another account.
409
Conflict, for example an e-mail or project name already in use.
413
The files are too large.
500
Error on our side. Details are not disclosed; try again.
Response 400
{
  "Response": {
    "status": {
      "code": "400",
      "msg": "name: must not be blank; description: size must be between 0 and 500",
      "total": "0",
      "page": "0",
      "pagesize": "0"
    },
    "data": null
  }
}
Response 403
{
  "Response": {
    "status": {
      "code": "403",
      "msg": "Limit reached: plan FREE allows 30 publications per project this month",
      "total": "0",
      "page": "0",
      "pagesize": "0"
    },
    "data": null
  }
}