The entire Busit platform relies on a cental REST API. The user panel, routing of messages,... all are handled via this endpoint.
Here are the main characteristics of the Busit REST API:
{
"response":
{
"user_name":"test",
"user_id":"2"
}
}
If multiple output formats are provided using different methods, the order of preference is first the query parameter, then the Accept header.
If multiple output formats are provided using different query parameters, then the peference is undefined.
Most operations require specific grants. Those grants are associated with a user token.
?auth=1234:1234567890abcdef1234567890abcdef
Authorization: Bearer 1234:1234567890abcdef1234567890abcdef
If multiple tokens are provided using different methods, the order of preference is first the query parameter, then the Authorization Bearer header, then the Authorization Basic header.
If multiple tokens are provided using different query parameters, then the peference is undefined.
When the user needs to perform an action on his own behalf, you should use the /self prefix in the URL. This forces the user parameter to be that of the matching token.
The /self prefix also allows privilegied actions that would otherwise not be granted. It is usually enforced by SELF_* grants.
Example:
The endpoint /system/user/delete requires an elevated USER_DELETE grant that regular users cannot use.
However, the endpoint /self/system/user/delete allows a SELF_USER_DELETE grant that is available to the current user authenticated with his token.
Every API error is composed of a message in English, a code to indicate the nature of the error, and some optional data that provide more detail about the error.
Caution: remember that the API will always return a HTTP response code of 200. (Discussion)
Possible error codes:
{
"error":
{
"message": "Unsufficient privileges",
"data": {"grants":["access"]},
"code":401
}
}
There are many internal limits and quotas about a bunch of things. Starting with the number of requests to the API itself.
A quota is a fixed increment counter. If it is reached, it can only be decremented by removing items.
A limit is a time-based increment counter. It is not reset at specific interval, it is a sliding window. Most of the time, waiting some time will solve it.
When a limit is exceeded, a 402 error is raised and the response will contain a X-Rate-Limit-Next header with an approximation of when the next request may be accepted in milliseconds.
X-Rate-Limit-Next: api=3600000
For some actions, the response or processing may be adjusted to match the user language. Hence, you may always set the user preferred language as either:
If both the query parameter and the header are specified, the query parameter has precedence.
If multiple languages are provided in different query parameters, the precedence is undefined.
In any case, the language code considered will be transformed to stick to ISO_639-1.
This implies that any unordered language preference set in the Accept-Language header will not be considered.
Note that the error messages issued by the API will not be localized.
Third party applications that want to gain control over a user BusApp instance can perform an OAuth2-like implicit authorization process as described in RFC6749. (Discussion)
In order to use BusApp Authorization, you should register with Busit in order to authorize your requestor and referer.
Contact us !
https://apps.busit.com/auth?data=
{
"instance": 12345,
"grants": null,
"requestor": "My Service",
"referer": "https://my.domain.com/callback",
"lease": 3600,
"state": "session_12345"
}
https://my.domain.com/callback?token=abcdef123456&state=session_12345
When using a BusApp token to perform requests to the API, the auth parameter MUST be formatted as follows : i:[instance_id]:[token]
Example:
https://api.busit.com/?auth=i:12345:abcdef123456Any user API parameter will be automatically induced and should be omitted.
When using this mechanism, you are bound to Busit's Tems and Conditions. If you do not fully understand those, do not use this procedure.
Note that to ensure the security of the user information, you MUST use https communications
Workflow:
USER YOUR SERVICE BUSIT | | | |-------------->| | | | (1) iframe to /auth | |--------------->| | | | (2) user login | |<-------------------------------| |------------------------------->| | | | (3) token | | (4) done |<---------------| |<--------------| |
Third party applications that want to gain control over a user external service via Busit can perform an OAuth-like authorization process.
Example:
External service My Service wants to get the user token for his Third Party Service account that is compatible and supported by Busit.
Each external service have a distinct URL endpoint of the form https://apps.busit.com/[service]/[...]
In order to use Forward Authorization, you should register with Busit in order to get the endpoint URL and authorize your redirect_uri.
Contact us !
https://apps.busit.com/service/config?redirect_uri=https://my.domain.com/callback&state=session_12345
https://my.domain.com/callback?access_token={...}&state=session_12345
When using this mechanism, you are bound to the third party service's Terms and Conditions as well as Busit's Tems and Conditions. If you do not fully understand those, do not use this procedure.
Note that to ensure the security of the user information, you MUST use https communications
Workflow:
USER YOUR SERVICE BUSIT THIRD PARTY | | | | |-------------->| | | | | (1) iframe to service | | |--------------->| | | | | | (2) user busit login | | |<-------------------------------| | |------------------------------->| | | | (3) redirect to OAuth | |------------------->| | (4) user third party login | |<----------------------------------------------------| |---------------------------------------------------->| | | | (5) token | | (6) token |<-------------------| | (7) done |<---------------| | |<--------------| | |
All messages are encrypted with a 2048 bit asymetric keypair specific to each user. This guarantees integrity, confidentiality and non-repudiation of the messages. Moreover, if any user key is compromised, it does not affect other users.
All tokens and passwords are in the form of 128 bit hexadecimal strings (32 characters) derived from the MD5 hash function. (Discussion)
Wherever applicable, encrypted communications should be used. As such, all requests to the API happen in HTTPS.
Anywhere JSON parsing is required, an efficient loose parsing is performed. This allows to circumvent common mistakes, trailing characters, comments and deviation from strict JSON. Some example of accepted syntax are shown below but there are more subtle things. (Discussion)
Features supported by the loose parser:
Strict JSON example:
{
"key1": "value",
"key2": ["string", false, null, 42]
}
Loose JSON alternative:
{
key1 'value' /* comment */
"key2" => [string fAlSE;;42
}
}
}
The most frequent operation you will probably need is to push messages into the system. Fortunately, this is just a simple HTTP call to the API. You will need:
Remember that you may pass parameters as a query string, or as form-data, that you can pass the authentication in the HTTP header if you like,... as explained previousely.
https://api.busit.com/vanilla/message/push ?auth=i:123:abcdef12345 &channel=my_channel &data=my_data
If the data is a JSON object, then it will be interpreted and all key/value pairs will be added to the message as properties. Otherwise, the message will contain one single property named data with the provided value. For convenience, you may also post a JSON body as the data. In that case, the data query string parameter must be omitted.
Example 1:POST /vanilla/message/push HTTP/1.1 Host: api.busit.com Authorization: Bearer i:123:abcdef12345 Content-Type: application/x-www-form-urlencoded channel=my_channel&data=my_dataWill be sent to the BusApp instance 123 on channel my_channel with a message of the form:
{"data": "my_data"}
Example 2:
POST /vanilla/message/push HTTP/1.1 Host: api.busit.com Authorization: Bearer i:123:abcdef12345 Content-Type: application/x-www-form-urlencoded channel=my_channel&data={"foo":"bar","key":42}Will be sent to the BusApp instance 123 on channel my_channel with a message of the form:
{"foo": "bar", "key": 42}
Example 3:
POST /vanilla/message/push?channel=my_channel HTTP/1.1 Host: api.busit.com Authorization: Bearer i:123:abcdef12345 Content-Type: application/json {"foo": "bar", "key": 42}Will be sent to the BusApp instance 123 on channel my_channel with a message of the form:
{"foo": "bar", "key": 42}