Subscribe to an Event
post
/restproxy/api/v2/channels/{channelId}/event-subscriptions
Subscribe to an event
Request
Supported Media Types
- application/json
Path Parameters
-
channelId: string
ID of the channel
Request to subscribe to an event
Root Schema : eventSubscription
Type:
Show Source
object
-
block(optional):
integer(int64)
Number of the block
-
callbackTLSCerts:
object callbackTLSCerts
-
callbackURL:
string
Callback URL
-
chaincode(optional):
string
Name of the chaincode
-
event(optional):
string
Name of the event
-
expires(optional):
string
Expiration of the subscription
-
role(optional):
string
Name of Fabric enrollment to be used
-
seek(optional):
string
Allowed Values:
[ "oldest", "newest", "from" ]
Start position of the event. Only used for type "block" and "filteredblock" -
txid(optional):
string
ID of the transaction
-
type:
string
Allowed Values:
[ "block", "filteredblock", "transaction", "chaincode" ]
event type to subscribe to
Response
Supported Media Types
- application/json
200 Response
Operation successful
Root Schema : schema
Type:
Show Source
object
-
error(optional):
string
Default Value:Error message when operation fails
-
result(optional):
object result
-
returnCode:
string
Allowed Values:
[ "Success", "Failure" ]
Nested Schema : result
Type:
Show Source
object
-
subid:
string
ID of the subscription when operation succeeds
400 Response
Bad Request
401 Response
Not authorized
403 Response
Forbidden
404 Response
Invalid parameters
500 Response
Service unavailable
Examples
This endpoint is used to request an event subscription.
The following example shows how to request an event subscription by submitting a POST request on the REST resource using cURL.
curl -v -u <username>:<password> -X POST \ "https://<restproxy of your Blockchain instance>/api/v2/channels/default/event-subscriptions" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ --data @<JSON file with the request parameters>
For example,
curl -v -u obpuser:<password> -X POST \ "https://myvm.oracle.com:10000/restproxy/api/v2/channels/default/event-subscriptions" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ --data @file.json
The contents of
file.json
are:
{ "role": "myinstance_defaultuser", "type": "chaincode", "callbackURL": "http://10.168.108.17:9000", "expires": "1m", "callbackTLSCerts": { "caCert": "", "clientCert": "", "keyPassword": "" }, "txid": "b1c11242383212cfdcca97d68efc0b3641436b1845a9b4c6e822cf6099ca49ee", "chaincode": "obcs-example02", "seek": "oldest", "block": 0, "event": ".*" }
Where each parameter in the payload file represents:
Table - Payload Parameters
Parameter | Purpose | Possible Values |
---|---|---|
role |
Name of the Fabric enrollment to be used. | |
type |
Event type |
|
callbackURL |
Event callback address. | Must be a valid HTTP/HTTPS address. |
expires |
Subscribed event expire time since the time of current request. |
|
callbackTLSCerts |
Call back TLS Certificates. | It contains:
|
txid |
Transaction ID | |
chaincode |
Chaincode ID of the chaincode application subscribed to. | |
seek |
Which blocks to be delivered. |
This option can be used only if the |
block |
Block number | This value is used when seek is from . |
event |
Chaincode's event filter | * specifies all events. |
Note:
You can find the restproxy value of your Blockchain instance from the Nodes tab of your instance console.Example of the Response Body
The following example shows the contents of the response body in JSON format:
{ "returnCode": "Success", "error": "", "result": { "subid": "obpuser-dc28b77c-7e58-4b09-ae23-b2c01fa01b70" } }