How to Enable Programmatic Interaction with Azure Blockchain Workbench APIs

Requirements

  • .NET Core SDK and Azure Functions SDK
  • VSCode or Visual Studio
  • Postman

Azure Function Code

Primer

  1. Authenticating via Azure AD with a username/password pair and retrieving a bearer token, which we use to call the Workbench API
  2. Messaging integration — this facilitates interaction with systems, services, and devices where an interactive login is not possible or desirable

Motivation and End Result

GIF of invoking a local Azure Function (debugging from VSCode) from Postman

It requires a little bit of work, so let's get started!

Step 1: Setting up Azure Active Directory

My registration is called “Workbench Blockchain Client”
Make sure we have both “Application” and “User” in the allowedMemberTypes section
I called my registration “workbench function api test”
  • View all applications even if the role isn’t assigned to one
  • Assign and remove application users roles
  • Modify and upload applications

This part is IMPORTANT — click “Grant Permissions”

Make a note of this GUID!
COPY THE VALUE OF THE KEY ONCE YOU SAVE IT. YOU WON’T BE ABLE TO SEE IT AGAIN.

Step 2: Invoking the Workbench API to create a new User for our API

Copy this value (MINUS the “Bearer” Part)
GET request on {yourAPIEndpoint}/api/v1/users
  • The “external id” — this is the GUID from the active directory page we copied earlier
  • First name, last name, and email address, which can be anything
SUCCESS! MAKE A NOTE OF THE ID THAT’S RETURNED
Great! The last user is our Blockchain API!
Awesome!

Step 3: Assigning our newly created “API User” to an Application

AppID is 29 for this “Asset Transfer” scenario
GET request on {yourAPIEndpoint}/api/v1/applications/{appID}
Success! We have now assigned our API user to the “Owner” Role
Awesome! Now our API has the role of Owner and can create new contracts!

Final Step — Creating our Azure Function, and using the ADAL Library to get a bearer token and interact with the Workbench API from our own API

FIRST — Let’s get a few Properties from our Active Directory :

  • The TenantID of our directory we’re using for Workbench
  • The AppID of the Workbench blockchain client registration
  • The AppID of our newly created app registration
  • The AppSecret (the key we copied before Step 2 way above)
The App IDs we want
The Directory ID

SECOND — let's find a few more IDs from Workbench:

  • The Workflow ID of the workflow we want to interact with
  • The WorkflowFunctionID of the function we want to invoke from our API. In this case, we want to create new contracts so we’ll need to know the “constructor ID”
Copy the constructorID and also the workflowID of the workflow you want to call from our API
VSCode on mac
The parameters are read from the request body

That’s it!

Debugging Local Functions with VSCode is Awesome!
Our function expects a body with a “description” and “price”

And Voila — We can create a new contract by invoking our API!

Invoking our local Function creates a new contract in Workbench!

That’s It! I hope you enjoyed this Walk-through!

We now have the ability to interact with our Azure Blockchain Workbench instance via the API instead of using the messaging service and Logic Apps.

--

--

--

Engineer | Blockchain | Mobile | Microsoft

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Lazy copy file from one terminal to the other

Giày da cá sấu Crox Leather lace-up Shoes

The power of emotion driven testing

Release update — 13 Feb ‘21

Python On Docker

Triall Product Spotlight: Medical Coder

Mastering Web Scraping in Python: Crawling From the Scratch

How We Work Smarter, Not Harder

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
mahdi alirezaie

mahdi alirezaie

Engineer | Blockchain | Mobile | Microsoft

More from Medium

Temporal (System-versioned) Tables

Indexes In Databases

Access DevCon Vienna 2022 — Day Two Recap (Part 2)

Let’s Deploy Angular App into Azure through Azure DevOps Pipeline