ABW - Obtaining the Contract Id (or LedgerIdentifier) on a newly created contract via Rest API?

Copper Contributor

Although I understand that a new contract will be written asynchronously (although a contract record is immediately written to Sql Server with a pending ledger identifier once it is pulled off the queue by the Worker node Docker endpoint), it seems there isn't currently a reliable way to tie up the contract back to the caller who created it.

 

The closest I've gotten thus far is to use the Rest API ContractsGet endpoint to query all contracts written for the given workflow by the given userId, and find the latest one by timestamp - this is obviously prone to latency and concurrency issues under load.

 

It seems to me that it would be a good idea to allow the caller to also specify a reference correlation identifier to be stored on the Contract record

 

Have I perhaps missed something else obvious?

3 Replies

Calling POST /api/v1/contracts should return back the ID of the contract, which you can use to query with GET. 

You're right, thanks, it's the GatewayApi sample code which is discarding the contractid: 

 

https://github.com/Azure-Samples/blockchain/blob/master/blockchain-workbench/rest-api-samples/dotnet...

 

Replacing string.Empty with await msg.Content.ReadAsStringAsync() returns the newly allocated contract id as a raw string

 

For anyone interested, ABW 1.5 and hopefully onward now DO allow for asynchronous tie-ups of the Request and Response on the Messaging API : https://docs.microsoft.com/en-us/azure/blockchain/workbench/messages-overview

 

The user-supplied `requestId` that Contract and Contract Action requests accept is then echoed back on the ABW EventGrid (and I think also on the egress Service Bus topic), along with the assigned ContractId ContractAddress (Contract Creates) and ContractActionId / TransactionId (Contract Actions)