Handling responses

Making Requests

All API calls require the Medable-Client-Key header. An Organization creates one or more applications, providing the public key to all its clients. Note that some web applications may employ the Medable-Csrf-Token. If an application is configured as such, each authenticated request must include HTTP response header of the same name, sent with the login response (and each subsequent authenticated response).

For semantic reasons, API access to Objects is always through the use of the object plural name (e.g. /accounts).

Example: GET/accounts/me

$.ajax({
    url: "https://api.dev.medable.com/example/accounts/me",
    type: "GET",
    contentType: "application/json; charset=UTF-8",
    dataType : "json",
    headers: {
        "Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq",
        "Medable-Csrf-Token": "MvFkpcS0BCM9qpf4K0pFMyiE57e3VtI5Cb38NfQn6eWiPPp6CqZCOOrAljDZYWnU"
    }
});

Handling Responses

API responses always consist of JSON documents with an object property, whose values will either list or the name of the object type, such as account or connection.

Example: Single Object Response

GET/account

{
    "_id": "5516ee2634d8d93428169c0e",                       
    "object": "account",
    "roles": [
        "000000000000000000000007"
    ],
    ...    
}

When the response is an array, the data property contains the resulting array, and the hasMore property contains a boolean value that is true if there are more results that can be retrieved using Paging.

Example: Multiple Object Response

GET /c_examples?limit=1

{
    "data": [
        {
            "_id": "5519c01aae2fd2b02915c81f",                        
            "object": "c_example",
            "creator": {
                "_id": "5516ee2634d8d93428169c0e",
                "object": "Account",
                "path": "/accounts/5516ee2634d8d93428169c0e"
            },
            ...
        }
    ],
    "hasMore": true,
    "object": "list"
}

Lists are typically sorted by _id, in descending order. As such, results will have the newest items at the front of the result set.

If the response is a fault, the object property will be fault (see Faults).

GET /accounts/5516ee2634d8d93428169c0e/profile/missing

{
    "object": "fault",
    "name": "error",
    "code": "kNotFound",
    "status": 404,
    "reason": "Property not found.",
    "message":"Resource not found.",
    "path":"profile.missing"
}

Some responses, such as those retrieved via direct Property Access, will have result as their object property, as they do not represent a concrete, registered object type. Note, however, that directly accessed array properties will always be list objects.

Result Example

GET /accounts/5516ee2634d8d93428169c0e/name

{
    "object": "result",
    "data": {
        "first": "John",
        "last": "Smith"
    }
}

List Example

{
    "object": "list",
    "data": [
        "000000000000000000000007"
    ],
    "hasMore": false
}

Last updated