PostEvent
API description
Send event messages to the callback URL provided by the user. The callback involves transmitting POST requests, so the user's callback server must support POST requests.
If the encryption field is configured in the rule, the request will include the Authorization signature to ensure the message is not forged or tampered with. Signature is optional.
Note:
- Only the
Status Code: 200 OKcan indicate the message push is successful. Otherwise, it shall be retried.- For overload protection, it supports
Status Code: 429 Too Many Requestsreturn value, and will retry after an interval;
Request
-
Request syntax
Plain Text1http 2POST /?event HTTP/1.1 3Host: <User_Host> 4Date: <Date> 5Content-Type: application/json; charset=utf-8 6Content-Length: <Content_Length> 7Authorization: <AuthorizationString> -
Request headers
None
-
Request parameters
| Field | Types | Description |
|---|---|---|
| version | String | Event version: currently 1.0 |
| eventFrom | String | The source of the request that triggers the event, indicating whether it originates from a user, BOS lifecycle, BOS data synchronization, or BOS batch processing. Valid values: Client/Lifycycle/Replication/Batch. It is "Client" by default. If this field is not set, the default value is used. |
| eventId | String | Unique identifier of event |
| eventOrigin | String | Event-triggering source. Currently, it supports incremental (bos:realtime). |
| eventType | String | Event type |
| eventTime | String | Event occurrence time (in GMT format) |
| configurationId | String | The ID of the event notification rule related to the event. |
| content | Object | Event details |
| +domain | String | Corresponding domain |
| +bucket | String | Corresponding bucket |
| +object | String | Object name |
| +eTag | String | The eTag of the object. If the object may be overwritten, the eTag is used to determine which version of the object triggers the event. |
| +contentType | String | Content-Type of the object |
| +copySourceBucket | string | CopyObject or BosLifecycle:Copy event indicates the bucket name of the source object. |
| +copySourceObject | string | CopyObject or BosLifecycle:Copy event indicates the name of the source object. |
| +copySourceStorageClass | string | CopyObject or BosLifecycle:Copy event indicates the storage class of the source object. |
| +storageClass | string | The storage class of the object that causes the event to trigger. |
| +filesize | Number | File size |
| +lastModified | String | File update time |
| +credentials | Object | Temporary authorization for related resources. Refer to [Temporarily Authorized Access](BOS/API Reference/Access control.md#Temporary authorized access) for specific usage. |
| ++accessKeyId | String | Temporarily authorized Access Key ID |
| ++secretAccessKey | String | Temporarily authorized Secret Access Key |
| ++sessionToken | String | Temporarily authorized Session Token |
| ++expiration | String | Validity period of temporary authorization |
| +xVars | String | Original xVars in the notification set by the user |
Response
Callback signature (optional)
Once users configure event notification rules and those rules are triggered, the BOS server sends a POST callback request to the user's application server based on the configured callback URL. Upon receiving the callback, if the application server needs to verify the authenticity of the request from BOS, it can do so by checking the signature included in the callback.
Callback signature is implemented using Baidu AI Cloud IAM signature algorithm, as shown in IAM Signature Algorithm.
The signature process consists of three steps:
(1) Pre-create an event notification rule and set the key "encryption" in the rule. This can be done via the console or SDK.
For example, the ID of the created event notification rule is "callback1", where the key is the key set by the user. It a length of 32 characters and can only contain digits [0-9] and lowercase letters.
1PUT /?notification HTTP/1.1
2Host: <BucketName>.bj.bcebos.com
3Date: Wed, 12 Sep 2018 06:34:40 GMT
4Authorization: <AthorizationString>
5Content-Type: application/json; charset=utf-8
6Content-Length: 0
7{
8 "notifications": [
9 {
10 "id": "callback1",
11 "name": "rule-name",
12 "appId": "app-id-1",
13 "status": "enabled",
14 "encryption": {
15 "key": "06a62b70f47dc4a0a7da349609f1a1ac",
16 },
17 "resources": [
18 "bucket-a/path1/*", "/path2/*.jpg"
19 ],
20 "events": [
21 "PutObject"
22 ],
23 "apps": [
24 {
25 "id": "app-id-1",
26 "eventUrl": "http://xxx.com/event",
27 "xVars": "<User-Define-Raw-Msg>"
28 }
29 ]
30 }
31 ]
32}
(2) The user submits a BOS request that matches the event notification rule.
(3) The BOS server sends a signed callback to the user's application server. The AK used for the signature corresponds to the user's current request (it defaults to "-" if no signature is provided), and the SK is the key the user configured in the first step. The signature is included in the "Authorization" request header.
Example
-
Request example
Plain Text1``` 2POST /<callback_url> HTTP/1.1 3Host: <User_Host> 4Date: Wed, 12 Sep 2018 06:34:40 GMT 5Authorization: <AthorizationString> 6Content-Type: application/json; charset=utf-8 7Content-Length: 0 8 9{ 10 "events": [ 11 { 12 "version": "1.0", 13 "eventFrom": "Client", 14 "eventId": "2a513199-bbb9-4ac7-b12a-60213c26810d", 15 "eventOrigin": "bos:realtime", 16 "eventTime": "2018-09-05T02:28:49Z", 17 "eventType": "CopyObject", 18 "configurationId": "notify-id-1", 19 "content": { 20 "userId": "c7ac82ae14ef42d1a4ffa3b2ececa17f", 21 "domain": "bj.bcebos.com", 22 "bucket": "bucket-test", 23 "object": "images/test.jpg", 24 "eTag": "977b9623a15e520c663ac5ff6647e881", 25 "contentType": "application/octet-stream", 26 "copySourceBucket": "src-bucket", 27 "copySourceObject": "src-object", 28 "copySourceStorageClass": "STANDARD", 29 "storageClass": "COLD", 30 "filesize": 24414, 31 "lastModified": "2018-09-05T02:28:49Z", 32 "credentials": { 33 "accessKeyId": "f3ade7c6b1a911e8bb6821a724cc157d", 34 "secretAccessKey": "07381a56d35e4b1193a418362221de81", 35 "sessionToken": "ZGZiM2M3MmU4Mjk4NGQ2MGEzYTNhYTAyMDE3NTZmZmV8AAAAAIcCAADaE18IR6jSaVWlMHxZG5wzb/7AQas3Y6V", 36 "expiration": "2018-02-22T11:22:33Z" 37 }, 38 "xVars": "<User-Define-Raw-Msg>" 39 } 40 } 41 ] 42} 43``` -
Response example
Plain Text1HTTP /1.1 200 OK 2x-bce-request-id: 4db2b34d-654d-4d8a-b49b-xxxxxx786409 3Date: Wed, 12 Sep 2018 06:34:40 GMT 4Content-Length: 0 5Connection: close 6Server: BceBos
