none
Azure Blockchain Workbench REST API returns 204 No content RRS feed

  • Question

  • 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 ?


    Sunday, January 20, 2019 5:57 PM

Answers

  • Hi,

    Thanks for using Workbench.

    This is the expected behavior. I'm assuming you are an Admin on Workbench and have deployed an application. When you created a service principal that principal by default is not an admin (like any other user in the directory) on Workbench and there are no Role Assignments on that service principal to any Workbench Application. That is why when you are trying to get all applications you get a 204. On the other hand, the SP doesn't need to be an admin to list all the users, that is why you can pull all the users.

    It can be tricky to assign a service principal to be an admin, so we've created this script to make the process easier. 

    Tuesday, January 22, 2019 2:13 AM
    Owner

All replies

  • Hi,

    Thanks for using Workbench.

    This is the expected behavior. I'm assuming you are an Admin on Workbench and have deployed an application. When you created a service principal that principal by default is not an admin (like any other user in the directory) on Workbench and there are no Role Assignments on that service principal to any Workbench Application. That is why when you are trying to get all applications you get a 204. On the other hand, the SP doesn't need to be an admin to list all the users, that is why you can pull all the users.

    It can be tricky to assign a service principal to be an admin, so we've created this script to make the process easier. 

    Tuesday, January 22, 2019 2:13 AM
    Owner
  • It works !!! Thank you very much !!!

    Now I tried to move the project forward and I'm able to call and get a response from the the following functions:

    /api/v2/applications

    api/v2/applications/2/workflows

    /api/v2/contracts?workflowId=2

    However when I call the function 
    /api/v2/contracts/1/actions
    I get 404 Not found (but in reality the contract Id "1" exist)

    I also tried to call the same function and pass via POST the following Json for posting an action:

    {"workflowFunctionId":5,"workflowActionParameters":[{"name":"requestMessage","value":"New action from my external program"}]}

    but I'm getting 400 Bad request

    What can be wrong ?


    • Edited by EvtSrl Tuesday, January 22, 2019 5:48 PM
    Tuesday, January 22, 2019 5:45 PM
  • Hi,

    Thanks for using Workbench.

    This is the expected behavior. I'm assuming you are an Admin on Workbench and have deployed an application. When you created a service principal that principal by default is not an admin (like any other user in the directory) on Workbench and there are no Role Assignments on that service principal to any Workbench Application. That is why when you are trying to get all applications you get a 204. On the other hand, the SP doesn't need to be an admin to list all the users, that is why you can pull all the users.

    It can be tricky to assign a service principal to be an admin, so we've created this script to make the process easier. 

    It works !!! Thank you very much !!!

    Now I tried to move the project forward and I'm able to call and get a response from the the following functions:

    /api/v2/applications

    api/v2/applications/2/workflows

    /api/v2/contracts?workflowId=2

    However when I call the function 
    /api/v2/contracts/1/actions
    I get 404 Not found (but in reality the contract Id "1" exist)

    I also tried to call the same function and pass via POST the following Json for posting an action:

    {"workflowFunctionId":5,"workflowActionParameters":[{"name":"requestMessage","value":"New action from my external program"}]}

    but I'm getting 400 Bad request

    What can be wrong ?


    Tuesday, January 29, 2019 6:10 PM
  • Hi there,

    That is also the expected behavior. Contract creation and actions access control is based on the application roles. 

    For example: in the web app you can deploy a contract till you added to a certain app role. Here is a great article about using SP's with workbench for contract creation.

     


    Microsoft Azure Blockchain Team

    Friday, February 1, 2019 1:08 AM
    Owner
  • Hi there,

    That is also the expected behavior. Contract creation and actions access control is based on the application roles. 

    For example: in the web app you can deploy a contract till you added to a certain app role. Here is a great article about using SP's with workbench for contract creation.

     


    Microsoft Azure Blockchain Team

    Hi, if I am using postman to impersonate a user to post a contract, can that work?

    In my situation, when I tried to post a new contract, I get a 200 OK, and I can see that a new contract is created by Get api/v2/contracts.

    However, the contract has no ledgerIdentifier, and when I try Get api/contract/{contractId}/actions from the user who created the contract, it returns me 204. FYI, the user who creates the contract should be able to take one action.

    The following is the contract info I get through postman by calling Get api/v2/contract/{contractId}

    ``

    "id": 12,
    "provisioningStatus": 0,
    "timestamp": "2019-08-15T18:41:49.5566667",
    "connectionID": 1,
    "ledgerIdentifier": null,
    "deployedByUserId": 1,
    "workflowId": 2,
    "requestId": "7140c8cd-8174-46af-8c1e-bb0717e02073",
    "contractCodeId": 2,
    "contractProperties": [],
    "transactions": [],
    "contractActions": [
    {
    "id": 30,
    "userId": 1,
    "provisioningStatus": 0,
    "timestamp": "2019-08-15T18:41:49.5566667",
    "parameters": [
    {
    "name": "description",
    "value": "from postman",
    "workflowFunctionParameterId": 9
    },
    {
    "name": "transferability",
    "value": "true",
    "workflowFunctionParameterId": 10
    },
    {
    "name": "expired time",
    "value": "1569011400",
    "workflowFunctionParameterId": 11
    }
    ],
    "workflowFunctionId": 7,
    "transactionId": null,
    "workflowStateId": null,
    "requestId": "7140c8cd-8174-46af-8c1e-bb0717e02073",
    "eventId": null
    }
    ]

    ``

    My questions are:

    1.what could possibly go wrong here?

    2.why there is no ledgerIdentifier and contractProperties for the contract?

    Thanks

    Really appreciate your help on this!!!!!

    Thursday, August 15, 2019 7:10 PM
  • I am experiencing the same issue, looks like the powershell scripts did not help. 

    May I know which tables I should check after creating service principal?

    Monday, October 21, 2019 8:17 AM