Azure Blockchain Workbench REST API returns 204 No content

366 Views Asked by At

I have created and distributed a blockchain workbench project. I can access the Azure Blockchain Workbench client web site where I can create contracts, take actions, etc..

I tried to develop a simple program to use Azure Blockchain Workbench REST API for interacting with the blockchain with my own application.

Before calling any API function, I get the Authentication Token (I hope it's correct because I'm getting a value for the token)

If now I try to call the API function "https://myblockchain-xyz-api.azurewebsites.net/api/v2/users", then I get as result the list of users.

However, if now I try to call any other function about blockchain applications, for example "/api/v2/applications", I get return code 204 "No content".

If I try to call for example "/api/v2/applications/2/workflows" then I get 404 "Not found"

Following the API call :

Dim MyOauthToken As String = 
Utilities.BlockchainAuthentication.GetAuthenticationToken().Result

Dim MyHttpClient As New HttpClient()
MyHttpClient.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Bearer", MyOauthToken)
'--------------------------------------------------------
'Force security protocol
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
'---------------------------------------------------------
'Get list of applications
Dim MyServiceUriString As String = "https://myblockchain-xyz-api.azurewebsites.net/api/v2/users/applications"
Dim MyResponse As Task(Of HttpResponseMessage) = MyHttpClient.GetAsync(MyServiceUriString)
MyResponse.Wait()

The result of the "applications" function is 204 "No content" If I do the same calling ".../api/v2/users" it works and I get all users.

Can anybody help ?

I have tried to call "../users/me" to see what happens and I get the following result (I don't know if this maybe helps):

{"currentUser":{"userID":7,"externalID":"1r67sf88-5b49-47da-a27a-79g3gg345","firstName":null,"lastName":"","emailAddress":null,"userChainMappings":[{"userChainMappingID":5,"userID":7,"connectionID":1,"chainIdentifier":"0x32cfcf169813364563456348c99b9","chainBalance":null}]},"capabilities":{"canUploadApplication":false,"canUploadContractCode":false,"canModifyRoleAssignments":false,"canProvisionUser":false,"canUpgradeWorkbench":false}}

1

There are 1 best solutions below

0
On

The problem is that default user (created by deployment of Azure Blockchain Workbench) in off-chain DB is not mapped to any application. Just as workaround - you can always add this mapping manually in DB and after that you will be able to get applications (and use contracts etc).

What you need to do:

  1. Find external user id for Application(web api), which was provisioning with Azure Blockchain Workbench.

    • Navigate to Azure Azcive Directory
    • Enterprise Apps
    • Select all apss in drop down and press apply
    • Now you can see something like Azure Blockchain Workbench blockchaintest-XXXXX
    • Select an item and you will get external_id in browser address bar (last guid in row)
  2. Find resource group for AZ BCW which your create and find SQL database

  3. User Query editor (preview) for attaching to DB
  4. Find user ID in dbo.User with external_id from step 1
  5. Find Application ID in dbo.Application
  6. Add new record to dbo.RoleAssignment with user id from step 4 and app id from step 5

Now this should works

curl -H "Authorization: Bearer ${TOKEN}" -X GET 'https://blockchaintest-XXXXX-api.azurewebsites.net/api/v1/applications?isLatestVetsion=true' 
{"nextLink":"/api/v1/applications?skip=1","applications":[{"id":10,"version":"9.0","name":"CCCCC","description":"CCCCCCC","displayName":"CCCCCCCC","createdByUserId":2,"createdDtTm":"2019-04-30T05:13:40.87","enabled":true,"blobStorageURL":null,"isLatestVersion":null,"applicationRoles":null}]}