|
1 | 1 | ---
|
2 |
| -title: Using Azure Blockchain Workbench REST API |
3 |
| -description: Scenarios for how to use the Azure Blockchain Workbench REST API |
4 |
| -services: azure-blockchain |
5 |
| -keywords: |
6 |
| -author: PatAltimore |
7 |
| -ms.author: patricka |
8 |
| -ms.date: 5/16/2018 |
9 |
| -ms.topic: article |
10 |
| -ms.service: azure-blockchain |
11 |
| -ms.reviewer: zeyadr |
12 |
| -manager: femila |
13 |
| -#customer intent: As a developer, I want to understand the Azure Blockchain Workbench REST API to so that I can integrate apps with Blockchain Workbench. |
| 2 | +redirect_url: /azure/blockchain/workbench/use-api |
| 3 | +redirect_document_id: true |
14 | 4 | ---
|
15 |
| -# Using the Azure Blockchain Workbench REST API |
16 |
| - |
17 |
| -Azure Blockchain Workbench REST API provides developers and information workers a way to build rich integrations to blockchain applications. This document walks you through several key methods of the Workbench REST API. Consider a scenario where a developer wants to create a custom blockchain client, which allows signed in users to view and interact with their assigned blockchain applications. The client allows users to view contract instances and take actions on smart contracts. The client uses the Workbench REST API in the context of the signed-in user to do the following: |
18 |
| - |
19 |
| -* List applications |
20 |
| -* List workflows for an application |
21 |
| -* List smart contract instances for a workflow |
22 |
| -* List available actions for a contract |
23 |
| -* Execute an action for a contract |
24 |
| - |
25 |
| -The example blockchain applications used in the scenarios, can be [downloaded from GitHub](https://github.com/Azure-Samples/blockchain). |
26 |
| - |
27 |
| -## List applications |
28 |
| - |
29 |
| -Once a user has signed into the blockchain client, the first task is to retrieve all Blockchain Workbench applications for the user. In this scenario, the user has access to two applications: |
30 |
| - |
31 |
| -1. [Asset transfer](https://github.com/Azure-Samples/blockchain/blob/master/blockchain-workbench/application-and-smart-contract-samples/asset-transfer/readme.md) |
32 |
| -2. [Refrigerated transportation](https://github.com/Azure-Samples/blockchain/blob/master/blockchain-workbench/application-and-smart-contract-samples/refrigerated-transportation/readme.md) |
33 |
| - |
34 |
| -Use the [Applications GET API](https://docs.microsoft.com/rest/api/azure-blockchain-workbench/applications/applicationsget): |
35 |
| - |
36 |
| -``` http |
37 |
| -GET /api/v1/applications |
38 |
| -Authorization : Bearer {access token} |
39 |
| -``` |
40 |
| - |
41 |
| -The response lists all blockchain applications to which a user has access in Blockchain Workbench. Blockchain Workbench administrators get all blockchain applications, while non-Workbench administrators get all blockchains for which they have at least one associated application role or an associated smart contract instance role. |
42 |
| - |
43 |
| -``` http |
44 |
| -HTTP/1.1 200 OK |
45 |
| -Content-type: application/json |
46 |
| -{ |
47 |
| - "nextLink": "/api/v1/applications?skip=2", |
48 |
| - "applications": [ |
49 |
| - { |
50 |
| - "id": 1, |
51 |
| - "name": "AssetTransfer", |
52 |
| - "description": "Allows transfer of assets between a buyer and a seller, with appraisal/inspection functionality", |
53 |
| - "displayName": "Asset Transfer", |
54 |
| - "createdByUserId": 1, |
55 |
| - "createdDtTm": "2018-04-28T05:59:14.4733333", |
56 |
| - "enabled": true, |
57 |
| - "applicationRoles": null |
58 |
| - }, |
59 |
| - { |
60 |
| - "id": 2, |
61 |
| - "name": "RefrigeratedTransportation", |
62 |
| - "description": "Application to track end-to-end transportation of perishable goods.", |
63 |
| - "displayName": "Refrigerated Transportation", |
64 |
| - "createdByUserId": 7, |
65 |
| - "createdDtTm": "2018-04-28T18:25:38.71", |
66 |
| - "enabled": true, |
67 |
| - "applicationRoles": null |
68 |
| - } |
69 |
| - ] |
70 |
| -} |
71 |
| -``` |
72 |
| - |
73 |
| -## List workflows for an application |
74 |
| - |
75 |
| -Once a user selects the applicable blockchain application, in this case, **Asset Transfer**, the blockchain client retrieves all workflows of the specific blockchain application. Users can then select the applicable workflow before being shown all smart contract instances for the workflow. Each blockchain application has one or more workflows and each workflow has zero or smart contract instances. When building blockchain client applications, it is recommended to skip the user experience flow allowing users to select the appropriate workflow when there is only one workflow for the blockchain application. In this case, **Asset Transfer** has only one workflow, also called **Asset Transfer**. |
76 |
| - |
77 |
| -Use the [Applications Workflows GET API](https://docs.microsoft.com/rest/api/azure-blockchain-workbench/applications/workflowsget): |
78 |
| - |
79 |
| -``` http |
80 |
| -GET /api/v1/applications/{applicationId}/workflows |
81 |
| -Authorization: Bearer {access token} |
82 |
| -``` |
83 |
| - |
84 |
| -Response lists all workflows of the specified blockchain application to which a user has access in Blockchain Workbench. Blockchain Workbench administrators get all blockchain workflows, while non-Workbench administrators get all workflows for which they have at least one associated application role or is associated with a smart contract instance role. |
85 |
| - |
86 |
| -``` http |
87 |
| -HTTP/1.1 200 OK |
88 |
| -Content-type: application/json |
89 |
| -{ |
90 |
| - "nextLink": "/api/v1/applications/1/workflows?skip=1", |
91 |
| - "workflows": [ |
92 |
| - { |
93 |
| - "id": 1, |
94 |
| - "name": "AssetTransfer", |
95 |
| - "description": "Handles the business logic for the asset transfer scenario", |
96 |
| - "displayName": "Asset Transfer", |
97 |
| - "applicationId": 1, |
98 |
| - "constructorId": 1, |
99 |
| - "startStateId": 1 |
100 |
| - } |
101 |
| - ] |
102 |
| -} |
103 |
| -``` |
104 |
| - |
105 |
| -## List smart contract instances for a workflow |
106 |
| - |
107 |
| -Once a user selects the applicable workflow, this case **Asset Transfer**, the blockchain client will retrieve all smart contract instances for the specified workflow. You can use this information to show all smart contract instances for the workflow and allow users to deep dive into any of the shown smart contract instances. In this example, consider a user would like to interact with one of the smart contract instances to take action. |
108 |
| - |
109 |
| -Use the [Contracts GET API](https://docs.microsoft.com/rest/api/azure-blockchain-workbench/contracts/contractsget): |
110 |
| - |
111 |
| -``` http |
112 |
| -GET api/v1/contracts?workflowId={workflowId} |
113 |
| -Authorization: Bearer {access token} |
114 |
| -``` |
115 |
| - |
116 |
| -Response lists all smart contract instances of the specified workflow. Workbench administrators get all smart contract instances, while non-Workbench administrators get all smart contract instances for which they have at least one associated application role or is associated with a smart contract instance role. |
117 |
| - |
118 |
| -``` http |
119 |
| -HTTP/1.1 200 OK |
120 |
| -Content-type: application/json |
121 |
| -{ |
122 |
| - "nextLink": "/api/v1/contracts?skip=3&workflowId=1", |
123 |
| - "contracts": [ |
124 |
| - { |
125 |
| - "id": 1, |
126 |
| - "provisioningStatus": 2, |
127 |
| - "connectionID": 1, |
128 |
| - "ledgerIdentifier": "0xbcb6127be062acd37818af290c0e43479a153a1c", |
129 |
| - "deployedByUserId": 1, |
130 |
| - "workflowId": 1, |
131 |
| - "contractCodeId": 1, |
132 |
| - "contractProperties": [ |
133 |
| - { |
134 |
| - "workflowPropertyId": 1, |
135 |
| - "value": "0" |
136 |
| - }, |
137 |
| - { |
138 |
| - "workflowPropertyId": 2, |
139 |
| - "value": "My first car" |
140 |
| - }, |
141 |
| - { |
142 |
| - "workflowPropertyId": 3, |
143 |
| - "value": "54321" |
144 |
| - }, |
145 |
| - { |
146 |
| - "workflowPropertyId": 4, |
147 |
| - "value": "0" |
148 |
| - }, |
149 |
| - { |
150 |
| - "workflowPropertyId": 5, |
151 |
| - "value": "0x0000000000000000000000000000000000000000" |
152 |
| - }, |
153 |
| - { |
154 |
| - "workflowPropertyId": 6, |
155 |
| - "value": "0x0000000000000000000000000000000000000000" |
156 |
| - }, |
157 |
| - { |
158 |
| - "workflowPropertyId": 7, |
159 |
| - "value": "0x0000000000000000000000000000000000000000" |
160 |
| - }, |
161 |
| - { |
162 |
| - "workflowPropertyId": 8, |
163 |
| - "value": "0xd882530eb3d6395e697508287900c7679dbe02d7" |
164 |
| - } |
165 |
| - ], |
166 |
| - "transactions": [ |
167 |
| - { |
168 |
| - "id": 1, |
169 |
| - "connectionId": 1, |
170 |
| - "transactionHash": "0xf3abb829884dc396e03ae9e115a770b230fcf41bb03d39457201449e077080f4", |
171 |
| - "blockID": 241, |
172 |
| - "from": "0xd882530eb3d6395e697508287900c7679dbe02d7", |
173 |
| - "to": null, |
174 |
| - "value": 0, |
175 |
| - "isAppBuilderTx": true |
176 |
| - } |
177 |
| - ], |
178 |
| - "contractActions": [ |
179 |
| - { |
180 |
| - "id": 1, |
181 |
| - "userId": 1, |
182 |
| - "provisioningStatus": 2, |
183 |
| - "timestamp": "2018-04-29T23:41:14.9333333", |
184 |
| - "parameters": [ |
185 |
| - { |
186 |
| - "name": "Description", |
187 |
| - "value": "My first car" |
188 |
| - }, |
189 |
| - { |
190 |
| - "name": "Price", |
191 |
| - "value": "54321" |
192 |
| - } |
193 |
| - ], |
194 |
| - "workflowFunctionId": 1, |
195 |
| - "transactionId": 1, |
196 |
| - "workflowStateId": 1 |
197 |
| - } |
198 |
| - ] |
199 |
| - } |
200 |
| - ] |
201 |
| -} |
202 |
| -``` |
203 |
| - |
204 |
| -## List available actions for a contract |
205 |
| - |
206 |
| -Once a user has decided to deep dive into one of the contracts, the blockchain client can then show all available actions to the user given the state of the contract. In this example, the user is looking at all available actions for a new smart contract they created: |
207 |
| - |
208 |
| -* Modify: Allows the user to modify the description and price of an asset. |
209 |
| -* Terminate: Allows the user to terminate the contract of the asset. |
210 |
| - |
211 |
| -Use the [Contract Action GET API](https://docs.microsoft.com/rest/api/azure-blockchain-workbench/contracts/contractactionget): |
212 |
| - |
213 |
| -``` http |
214 |
| -GET /api/v1/contracts/{contractId}/actions |
215 |
| -Authorization: Bearer {access token} |
216 |
| -``` |
217 |
| - |
218 |
| -Response lists all actions to which a user can take given the current state of the specified smart contract instance. Users get all applicable actions if the user has an associated application role or is associated with a smart contract instance role for the current state of the specified smart contract instance. |
219 |
| - |
220 |
| -``` http |
221 |
| -HTTP/1.1 200 OK |
222 |
| -Content-type: application/json |
223 |
| -{ |
224 |
| - "nextLink": "/api/v1/contracts/1/actions?skip=2", |
225 |
| - "workflowFunctions": [ |
226 |
| - { |
227 |
| - "id": 2, |
228 |
| - "name": "Modify", |
229 |
| - "description": "Modify the description/price attributes of this asset transfer instance", |
230 |
| - "displayName": "Modify", |
231 |
| - "parameters": [ |
232 |
| - { |
233 |
| - "id": 1, |
234 |
| - "name": "description", |
235 |
| - "description": "The new description of the asset", |
236 |
| - "displayName": "Description", |
237 |
| - "type": { |
238 |
| - "id": 2, |
239 |
| - "name": "string", |
240 |
| - "elementType": null, |
241 |
| - "elementTypeId": 0 |
242 |
| - } |
243 |
| - }, |
244 |
| - { |
245 |
| - "id": 2, |
246 |
| - "name": "price", |
247 |
| - "description": "The new price of the asset", |
248 |
| - "displayName": "Price", |
249 |
| - "type": { |
250 |
| - "id": 3, |
251 |
| - "name": "money", |
252 |
| - "elementType": null, |
253 |
| - "elementTypeId": 0 |
254 |
| - } |
255 |
| - } |
256 |
| - ], |
257 |
| - "workflowId": 1 |
258 |
| - }, |
259 |
| - { |
260 |
| - "id": 3, |
261 |
| - "name": "Terminate", |
262 |
| - "description": "Used to cancel this particular instance of asset transfer", |
263 |
| - "displayName": "Terminate", |
264 |
| - "parameters": [], |
265 |
| - "workflowId": 1 |
266 |
| - } |
267 |
| - ] |
268 |
| -} |
269 |
| -``` |
270 |
| - |
271 |
| -## Execute an action for a contract |
272 |
| - |
273 |
| -A user can then decide to take action for the specified smart contract instance. In this case, consider the scenario where a user would like to modify the description and price of an asset to the following: |
274 |
| - |
275 |
| -* Description: "My updated car" |
276 |
| -* Price: 54321 |
277 |
| - |
278 |
| -Use the [Contract Action POST API](https://docs.microsoft.com/rest/api/azure-blockchain-workbench/contracts/contractactionpost): |
279 |
| - |
280 |
| -``` http |
281 |
| -POST /api/v1/contracts/{contractId}/actions |
282 |
| -Authorization: Bearer {access token} |
283 |
| -actionInformation: { |
284 |
| - "workflowFunctionId": 2, |
285 |
| - "workflowActionParameters": [ |
286 |
| - { |
287 |
| - "name": "description", |
288 |
| - "value": "My updated car" |
289 |
| - }, |
290 |
| - { |
291 |
| - "name": "price", |
292 |
| - "value": "54321" |
293 |
| - } |
294 |
| - ] |
295 |
| -} |
296 |
| -``` |
297 |
| - |
298 |
| -Users are only able to execute the action given the current state of the specified smart contract instance and the user's associated application role or smart contract instance role. If the post is successful, an HTTP 200 OK response is returned with no response body. |
299 |
| - |
300 |
| -``` http |
301 |
| -HTTP/1.1 200 OK |
302 |
| -Content-type: application/json |
303 |
| -``` |
304 |
| - |
305 |
| -## Next steps |
306 |
| - |
307 |
| -> [!div class="nextstepaction"] |
308 |
| -> [Azure Blockchain Workbench REST API reference](https://docs.microsoft.com/rest/api/azure-blockchain-workbench) |
0 commit comments