Subscribe to an Event
/restproxy/api/v2/channels/{channelName}/event-subscriptions
Request
- application/json
-
channelName(required): string
ID of the channel
object-
block:
integer(int64)
Number of the block
-
callbackTLSCerts:
object callbackTLSCerts
-
callbackURL(required):
string
URL to callback
-
chaincode:
string
Name of the chaincode
-
event:
string
Name of the event
-
expires:
string
Expiration of the subscription
-
maxCallbackRetry:
integer
Maximum number of retries. The retry interval grows based on exponential backoff to a maximum of 2 minutes.
-
oauth:
object oauth
Optionally provide details of the OAuth application, if the callback server is OAuth2 protected. Only client credential and refresh token flows are supported.
-
role:
string
Specifies which Hyperledger Fabric enrollment should be used
-
seek:
string
Allowed Values:
[ "oldest", "newest", "from" ]Start postion of the event, only be used for type "block" and "filteredblock" -
txid:
string
ID of the transaction
-
type(required):
string
Allowed Values:
[ "block", "filteredblock", "transaction", "chaincode" ]Event type to subscribe to
object-
authInHeader:
boolean
Set to true if the authorization parameters have to be passed in the header.
-
clientID:
string
The client ID for the Oauth application. It is required in case of client credential flow and can be provided optionally in refresh token flow as well
-
clientSecret:
string
The client secret for the OAuth application. It is required for a client credential flow, and is optional in a refresh token flow.
-
refreshToken:
string
Generate and pass the refresh token if using a refresh token flow.
-
scopes:
array scopes
List of scopes to be associated with the token.
-
tokenUrl:
string
The URL against which the call for generating access token will be made.
Response
- application/json
200 Response
object-
error:
string
Default Value:Error message when operation fails
-
result:
object result
-
returnCode(required):
string
Allowed Values:
[ "Success", "Failure" ]
object-
subid(required):
string
ID of the subscription when operation succeeds
400 Response
-
opc-request-id: string
Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
object-
code(required):
string
A short error code that defines the error, meant for programmatic parsing.
-
message(required):
string
A human-readable error string.
401 Response
-
opc-request-id: string
Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
object-
code(required):
string
A short error code that defines the error, meant for programmatic parsing.
-
message(required):
string
A human-readable error string.
403 Response
404 Response
-
opc-request-id: string
Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
object-
code(required):
string
A short error code that defines the error, meant for programmatic parsing.
-
message(required):
string
A human-readable error string.
500 Response
-
opc-request-id: string
Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
object-
code(required):
string
A short error code that defines the error, meant for programmatic parsing.
-
message(required):
string
A human-readable error string.
Examples
This endpoint is used to request an event subscription.
Invoking Callback Endpoints with TLS Certs
The following example shows how to request an event subscription by submitting a POST request on the REST resource using cURL.
curl -v -X POST \ "https://<restproxy of your Blockchain instance>/api/v2/channels/<channelName>/event-subscriptions" \ -H "Authorization: Bearer <OAuth_access_ token>" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ --data @<JSON file with the request parameters>
Example request:
curl -v -X POST \ "https://myvm.oracle.com:10000/restproxy/api/v2/channels/default/event-subscriptions" \ -H "Authorization: Bearer mF_9.B5f-4.1JqM" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ --data @file.json
file.json file has the following contents:{
"role": "myinstance_defaultuser",
"type": "chaincode",
"callbackURL": "http://192.0.2.1:9000",
"expires": "1m",
"callbackTLSCerts": {
"caCert": "",
"clientCert": "",
"keyPassword": "" },
"txid": "b1c11242383212cfdcca97d68efc0b3641436b1845a9b4c6e822cf6099ca49ee",
"chaincode": "obcs-example02",
"seek": "oldest",
"block": 0,
"event": ".*",
"oauth": {}
}The parameters in the payload file represent the following values:
Table - Payload Parameters
| Parameter | Purpose | Possible Values |
|---|---|---|
role |
Name of the Fabric enrollment to use. | |
type |
Event type. |
|
callbackURL |
Event callback address. | Must be a valid HTTP/HTTPS address. |
maxCallbackRetry |
This parameter specifies how many times to retry the call until event delivery succeeds or until the REST proxy restarts.
The retry interval will exponentially increase, starting at 1 second and increasing to 120 seconds. An HTTP 4XX response (excluding HTTP 401 and HTTP 429) will override this value, as those responses are considered to be terminal failures. The system will log that particular event as a failure and proceed with any remaining events in the queue. |
Must be an integer. Represents the number of times to retry
after the initial call.
The default is 7. |
expires |
Subscribed event expiration time since the time of current request. |
|
callbackTLSCerts |
Callback TLS certificates. | This parameter contains the following values:
|
txid |
Transaction ID. | |
chaincode |
Chaincode ID of the chaincode application to subscribe to. | |
seek |
Specifies which blocks to deliver. |
This option can be used for all |
block |
Block number. | This value is used when the seek parameter is set to from.
|
event |
Chaincode's event filter. | Use an asterisk (*) to specify all events.
|
Note:
You can find the REST proxy value of your instance on the Nodes page of the instance console.The maximum payload size of an event is limited to 50 KB. Any events larger than the maximum payload size will be dropped. The Oracle DevOps team can modify this parameter by request. If you expect to subscribe to events where the payload will be larger than 50 KB, open a Service Request (SR) in Oracle Support to request a larger maximum event size.
Invoking Callback Endpoints Secured with OAuth 2.0
oauth parameter instead of the callbackTLSCerts parameter. The following example shows a payload file for event subscription using OAuth 2.0 tokens: {
"type": "block",
"callbackURL": "192.0.2.1",
"callbackTLSCerts": {},
"expires": "30m",
"seek": "newest",
"event": ".*",
"maxCallbackRetry": 7,
"oauth": {
"clientID": "my-client-id",
"clientSecret": "my-client-secret",
"tokenUrl": "https://identity.example.com/oauth2/v1/token",
"authInHeader": true,
"scopes": ["urn:opc:idm:__myscopes__"]
}
}typespecifies the event type. In this example,blockindicates that the data from a block will be returned.callbackURLspecifies the event callback address, which is a valid HTTP/HTTPS address.expiresindicates that this subscription expires after 30 minutes since the time of current request.seekspecifies which blocks to deliver. In this example,newestindicates that this subscription delivers the newest block. This option can be used for alltypeparameters except thetransactiontype.eventis the chaincode event filter. An asterisk (*) indicates that the user subscribes to all events in the specified chaincode.maxCallbackRetryspecifies the number of times event delivery is attempted until it succeeds. The default value of themaxCallbackRetryparameter is 7.
The oauth parameter contains the following parameters:
Table - OAuth Parameters
| Parameter | Purpose |
|---|---|
clientID |
The client ID. Required when using client credentials. Optional when refreshing an expired token. |
clientSecret |
The client secret. Required when using client credentials. Optional when refreshing an expired token. |
refreshToken |
The refresh token. Required when refreshing the use of an access token that has expired. |
tokenUrl |
The URL to use to obtain tokens. This parameter is always required. |
scopes |
A list of scopes to associate with the token. |
authInHeader |
A Boolean value indicating how the credentials will be passed. If true, the credentials will be passed in the header. If false, the credentials will be passed in the payload. |
The following example shows the contents of the response body in JSON format:
{
"returnCode": "Success",
"error": "",
"result": {
"subid": "obpuser-dc28b77c-7e58-4b09-ae23-b2c01fa01b70"
}
}