Subscribe to an Event

post

/restproxy/api/v2/channels/{channelName}/event-subscriptions

Subscribe to an event.

Request

Supported Media Types
Path Parameters
Body ()
Request to subscribe to an event
Root Schema : EventSubscription
Type: object
Show Source
Nested Schema : callbackTLSCerts
Type: object
Show Source
Nested Schema : oauth
Type: object
Optionally provide details of the OAuth application, if the callback server is OAuth2 protected. Only client credential and refresh token flows are supported.
Show Source
  • Set to true if the authorization parameters have to be passed in the header.
  • 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
  • The client secret for the OAuth application. It is required for a client credential flow, and is optional in a refresh token flow.
  • Generate and pass the refresh token if using a refresh token flow.
  • scopes
    List of scopes to be associated with the token.
  • The URL against which the call for generating access token will be made.
Nested Schema : scopes
Type: array
List of scopes to be associated with the token.
Show Source
Back to Top

Response

Supported Media Types

200 Response

Operation successful
Body ()
Root Schema : schema
Type: object
Show Source
Nested Schema : result
Type: object
Show Source

400 Response

Bad Request
Headers
  • Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
Body ()
Root Schema : Error
Type: object
Error Information.
Show Source

401 Response

Unauthorized
Headers
  • Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
Body ()
Root Schema : Error
Type: object
Error Information.
Show Source

403 Response

Forbidden

404 Response

Not Found
Headers
  • Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
Body ()
Root Schema : Error
Type: object
Error Information.
Show Source

500 Response

Internal Server Error
Headers
  • Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
Body ()
Root Schema : Error
Type: object
Error Information.
Show Source
Back to Top

Examples

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
The 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.
  • transaction: returns events for a specific transaction ID.
  • chaincode: returns events emitted from a chaincode.
  • block: returns all of the data in a block.
  • filteredblock: returns block number and each transaction ID along with the validation code and payload of the chaincode event.
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.
  • <xx>M, <xx>w, <xx>d, <xx>h, <xx>m

    The variables in the example have the following values:

    • xx is a valid integer.
    • M represents months.
    • w is weeks.
    • d is days.
    • h is hours
    • m indicates minutes.
  • If not set, the default value is 1d; that is, one day.
callbackTLSCerts Callback TLS certificates. This parameter contains the following values:
  • caCert (optional): Callback server's CA certificate. It is used by the REST proxy to verify the callback server. The certificate must be in PEM format.
  • clientCert (optional): Client certificate to use as the REST proxy's certificate when connecting to the callback server. It is required only when the callback server enables mutual authentication. The certificate must be in PEM format, and assumes that the private key and the client certificate are concatenated.
  • keyPassword (optional): Encrypted private key's password. It must be base64 encoded and it is required only when the clientCert certificate contains an encrypted private key.
txid Transaction ID.  
chaincode Chaincode ID of the chaincode application to subscribe to.  
seek Specifies which blocks to deliver.
  • oldest: delivers all blocks from the oldest block.
  • newest: delivers the newest block.
  • from: delivers from the block number specified for the block parameter.

This option can be used for all typeparameters except for the transaction type.

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

You can invoke callback endpoints secured with OAuth 2.0. In this case you pass the 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__"]
  }
}
The variables in the example have the following values:
  • type specifies the event type. In this example, block indicates that the data from a block will be returned.
  • callbackURL specifies the event callback address, which is a valid HTTP/HTTPS address.
  • expires indicates that this subscription expires after 30 minutes since the time of current request.
  • seek specifies which blocks to deliver. In this example, newest indicates that this subscription delivers the newest block. This option can be used for all type parameters except the transaction type.
  • event is the chaincode event filter. An asterisk (*) indicates that the user subscribes to all events in the specified chaincode.
  • maxCallbackRetry specifies the number of times event delivery is attempted until it succeeds. The default value of the maxCallbackRetry parameter 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"
   }
}
Back to Top