Skip to main content

 none
ABW REST-API doesn't work on device telemetry RRS feed

  • Question

  • Hi, 

    We have 2 API accounts for ABW. One is an administrator which is created by the script "workbench-serviceprincipal" provided on github, and the other one is another admin with device role.
    The second API user created by following the steps described in this article: 
    medium.com/@malirezaie/how-to-enable-programmatic-interaction-with-azure-blockchain-workbench-apis-56c0d95c79c0

    Second API user can create users/applications/roles via api 
    but it returns 404 or 204 in different circumstances.

    [204 Error Case]
    Application:Refrigerated Transportation
    AllowedInstanceRoles for IngestTelemetry [ "Device" ]
    API User role : Device
    URL:{{baseURL}}/api/v2/contracts/1/actions
    Body:
    {
        "workflowFunctionId": "2",
        "workflowActionParameters": [
            {
                "name": "humidity",
                "value": "70"
            },
            {
                "name": "temperature",
                "value": "20"
            },
            {
                "name": "timestamp",
                "value": "1573457543"
            }
        ]
    }

    [404 Error Case]
    Application:Refrigerated Transportation2
    AllowedInstanceRoles for IngestTelemetry [ "Owner" ]
    API User role : Device, Owner
    Error Message: User n is not authorized to take this action
    URL:{{baseURL}}/api/v2/contracts/5/actions
    Body:
    {
        "workflowFunctionId": "6",
        "workflowActionParameters": [
            {
                "name": "humidity",
                "value": "70"
            },
            {
                "name": "temperature",
                "value": "20"
            },
            {
                "name": "timestamp",
                "value": "1573457543"
            }
        ]
    }

    [204 Response log]
    2019-11-14T08:09:52.308488377Z [08:09:52 INF] {Protocol="HTTP/1.1", Method="GET", ContentType=null, ContentLength=null, Scheme="http", Host="bc-wogitl-api.azurewebsites.net", PathBase="", Path="/api/v2/contracts/1/actions", QueryString="?top=100", EventId={Id=1}, SourceContext="Microsoft.AspNetCore.Hosting.Internal.WebHost", RequestId="0HLR7ABCO715D:00000001", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Request starting HTTP/1.1 GET http://bc-wogitl-api.azurewebsites.net/api/v2/contracts/1/actions?top=100
    2019-11-14T08:09:52.309370782Z [08:09:52 INF] {EventId={Id=2}, SourceContext="Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler", RequestId="0HLR7ABCO715D:00000001", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Successfully validated the token.
    2019-11-14T08:09:52.309816585Z [08:09:52 INF] {EventId={Id=8}, SourceContext="Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler", RequestId="0HLR7ABCO715D:00000001", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} AuthenticationScheme: Bearer was successfully authenticated.
    2019-11-14T08:09:52.310259287Z [08:09:52 INF] {SourceContext="data-access", RequestId="60cc8d6e-a666-4680-b8e4-9a78576bd930", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Execute [dbo].[GetUserByExternalId] with externalId = 731c9380-0e3e-41d3-a495-c6810dcd3669
    2019-11-14T08:09:52.310631289Z [08:09:52 INF] {SourceContext="data-access", RequestId="60cc8d6e-a666-4680-b8e4-9a78576bd930", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Executing sproc [dbo].[GetUserByExternalId]
    2019-11-14T08:09:52.314915513Z [08:09:52 INF] {SourceContext="data-access", RequestId="60cc8d6e-a666-4680-b8e4-9a78576bd930", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Execute [dbo].[GetUserChainMappings] with id = 3
    2019-11-14T08:09:52.315365115Z [08:09:52 INF] {SourceContext="data-access", RequestId="60cc8d6e-a666-4680-b8e4-9a78576bd930", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Executing sproc [dbo].[GetUserChainMappings]
    2019-11-14T08:09:52.319639739Z [08:09:52 INF] {EventId={Id=1}, SourceContext="Microsoft.AspNetCore.Authorization.DefaultAuthorizationService", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", ActionName="Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API)", RequestId="60cc8d6e-a666-4680-b8e4-9a78576bd930", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Authorization was successful for user: 731c9380-0e3e-41d3-a495-c6810dcd3669.
    2019-11-14T08:09:52.320345043Z [08:09:52 INF] {EventId={Id=1}, SourceContext="Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", RequestId="60cc8d6e-a666-4680-b8e4-9a78576bd930", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Executing action method Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API) with arguments (["1", "100", ""]) - ModelState is Valid
    2019-11-14T08:09:52.320806445Z [08:09:52 INF] {SourceContext="app-builder", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", ActionName="Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API)", RequestId="60cc8d6e-a666-4680-b8e4-9a78576bd930", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} ContractActionsGet top = 100, skip = null, contractId = 1
    2019-11-14T08:09:52.321238948Z [08:09:52 INF] {SourceContext="data-access", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", ActionName="Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API)", RequestId="60cc8d6e-a666-4680-b8e4-9a78576bd930", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Execute [dbo].[GetContractsActionsNext] with contractId = 1, userId = 3, top = 100, skip = null
    2019-11-14T08:09:52.321662050Z [08:09:52 INF] {SourceContext="data-access", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", ActionName="Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API)", RequestId="60cc8d6e-a666-4680-b8e4-9a78576bd930", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Executing sproc [dbo].[GetContractActionsNext]
    2019-11-14T08:09:52.329339793Z [08:09:52 INF] {EventId={Id=1}, SourceContext="Microsoft.AspNetCore.Mvc.StatusCodeResult", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", ActionName="Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API)", RequestId="60cc8d6e-a666-4680-b8e4-9a78576bd930", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Executing HttpStatusCodeResult, setting HTTP status code 204
    2019-11-14T08:09:52.329832595Z [08:09:52 INF] {EventId={Id=2}, SourceContext="Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", RequestId="60cc8d6e-a666-4680-b8e4-9a78576bd930", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Executed action Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API) in 10.0145ms
    2019-11-14T08:09:52.330572199Z [08:09:52 INF] {ElapsedMilliseconds=22.2499, StatusCode=204, ContentType=null, EventId={Id=2}, SourceContext="Microsoft.AspNetCore.Hosting.Internal.WebHost", RequestId="60cc8d6e-a666-4680-b8e4-9a78576bd930", RequestPath="/api/v2/contracts/1/actions", ServiceName="appbuilder.api"} Request finished in 22.2499ms 204


    [404 Response log]
    2019-11-14T08:07:25.378523009Z [08:07:25 INF] {Protocol="HTTP/1.1", Method="GET", ContentType=null, ContentLength=null, Scheme="http", Host="bc-wogitl-api.azurewebsites.net", PathBase="", Path="/api/v2/contracts/5/actions", QueryString="?top=100", EventId={Id=1}, SourceContext="Microsoft.AspNetCore.Hosting.Internal.WebHost", RequestId="0HLR7ABCO715B:00000001", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Request starting HTTP/1.1 GET http://bc-wogitl-api.azurewebsites.net/api/v2/contracts/5/actions?top=100
    2019-11-14T08:07:25.387892361Z [08:07:25 INF] {EventId={Id=2}, SourceContext="Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler", RequestId="0HLR7ABCO715B:00000001", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Successfully validated the token.
    2019-11-14T08:07:25.388455764Z [08:07:25 INF] {EventId={Id=8}, SourceContext="Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler", RequestId="0HLR7ABCO715B:00000001", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} AuthenticationScheme: Bearer was successfully authenticated.
    2019-11-14T08:07:25.389035567Z [08:07:25 INF] {SourceContext="data-access", RequestId="e1802bd1-15ee-4eef-86c7-bbca97f76cc5", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Execute [dbo].[GetUserByExternalId] with externalId = 731c9380-0e3e-41d3-a495-c6810dcd3669
    2019-11-14T08:07:25.389506270Z [08:07:25 INF] {SourceContext="data-access", RequestId="e1802bd1-15ee-4eef-86c7-bbca97f76cc5", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Executing sproc [dbo].[GetUserByExternalId]
    2019-11-14T08:07:25.421886849Z [08:07:25 INF] {SourceContext="data-access", RequestId="e1802bd1-15ee-4eef-86c7-bbca97f76cc5", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Execute [dbo].[GetUserChainMappings] with id = 3
    2019-11-14T08:07:25.422502153Z [08:07:25 INF] {SourceContext="data-access", RequestId="e1802bd1-15ee-4eef-86c7-bbca97f76cc5", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Executing sproc [dbo].[GetUserChainMappings]
    2019-11-14T08:07:25.426918777Z [08:07:25 INF] {EventId={Id=1}, SourceContext="Microsoft.AspNetCore.Authorization.DefaultAuthorizationService", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", ActionName="Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API)", RequestId="e1802bd1-15ee-4eef-86c7-bbca97f76cc5", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Authorization was successful for user: 731c9380-0e3e-41d3-a495-c6810dcd3669.
    2019-11-14T08:07:25.427651981Z [08:07:25 INF] {EventId={Id=1}, SourceContext="Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", RequestId="e1802bd1-15ee-4eef-86c7-bbca97f76cc5", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Executing action method Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API) with arguments (["5", "100", ""]) - ModelState is Valid
    2019-11-14T08:07:25.428270285Z [08:07:25 INF] {SourceContext="app-builder", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", ActionName="Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API)", RequestId="e1802bd1-15ee-4eef-86c7-bbca97f76cc5", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} ContractActionsGet top = 100, skip = null, contractId = 5
    2019-11-14T08:07:25.428787588Z [08:07:25 INF] {SourceContext="data-access", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", ActionName="Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API)", RequestId="e1802bd1-15ee-4eef-86c7-bbca97f76cc5", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Execute [dbo].[GetContractsActionsNext] with contractId = 5, userId = 3, top = 100, skip = null
    2019-11-14T08:07:25.429306291Z [08:07:25 INF] {SourceContext="data-access", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", ActionName="Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API)", RequestId="e1802bd1-15ee-4eef-86c7-bbca97f76cc5", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Executing sproc [dbo].[GetContractActionsNext]
    2019-11-14T08:07:25.436124428Z [08:07:25 INF] {SourceContext="data-access", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", ActionName="Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API)", RequestId="e1802bd1-15ee-4eef-86c7-bbca97f76cc5", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Encountered entity not found in operation [dbo].[GetContractActionsNext], User 3 is not authorized to take this action.
    2019-11-14T08:07:25.437065134Z [08:07:25 INF] {EventId={Id=2}, SourceContext="Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker", ActionId="7cbcc31f-8f8b-4c94-8a19-2d589d30d249", RequestId="e1802bd1-15ee-4eef-86c7-bbca97f76cc5", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Executed action Microsoft.AppBuilder.API.Controllers.ContractsV2Controller.ContractActionsGet (Microsoft.AppBuilder.API) in 10.1997ms
    2019-11-14T08:07:25.438917944Z [08:07:25 INF] {ElapsedMilliseconds=60.6757, StatusCode=404, ContentType="application/json", EventId={Id=2}, SourceContext="Microsoft.AspNetCore.Hosting.Internal.WebHost", RequestId="e1802bd1-15ee-4eef-86c7-bbca97f76cc5", RequestPath="/api/v2/contracts/5/actions", ServiceName="appbuilder.api"} Request finished in 60.6757ms 404 application/json

    It might be an expected behavior, but what else we should do to make it work?

    Has anyone tried this method?



    • Edited by mesgar.net Friday, November 15, 2019 1:28 AM
    Thursday, November 14, 2019 8:29 AM

All replies

  • Hello mesgar,

    Can you please detail better what you are trying to achieve and if the official documentation here wasn't able to help you? 

    I believe that the article you followed can be outdated at the moment as many changes happened within Azure Blockchain ecosystem. See the many announcements done regarding blockchain since January here.

    Thank you!

    Monday, November 18, 2019 1:54 PM
    Moderator
  • Hi mesgar,

    When you calling the API, what's the status of the contract?
    The status must be "in transit" if device wants to set monitored data point. Otherwise device is not authorized to take any action. To put the contract in ”in transit“ status, "InitiatingCounterParty" need call function "TransferResponsibility" first.

    Hope it helps, let us know if you have any further questions.



    Microsoft Azure Blockchain Team

    Tuesday, November 19, 2019 1:35 AM
    Owner
  • Thank you for your feedback response. 
    Long story short we figured it out. Added admin and device role to API user, 
    created new contract and API call finally succeed with status code 200, returning following JSON,
    But no data inserted in database therefor nothing happens on the screen.
    ※Ran the troubleshooting PowerShell script and found this error: 
    Cannot insert duplicate key row in object 'dbo.Block' with unique index 'Block_BlockHash'. The duplicate key value is (0xa541b4d15c9dabeb7d2db4cdd6a952bce15f7a5ff6f11037d673313c2704ac1...

    {
        "nextLink": "/api/v2/contracts/6/actions?skip=1",
        "workflowFunctions": [
            {
                "id": 2,
                "name": "IngestTelemetry",
                "description": "...",
                "displayName": "Ingest Telemetry",
                "parameters": [
                    {
                        "id": 1,
                        "name": "humidity",
                        "description": "...",
                        "displayName": "Humidity",
                        "type": {
                            "id": 4,
                            "name": "int",
                            "applicationId": 0,
                            "elementType": null,
                            "elementTypeId": 0,
                            "enumValues": null
                        }
                    },
                    {
                        "id": 2,
                        "name": "temperature",
                        "description": "...",
                        "displayName": "Temperature",
                        "type": {
                            "id": 4,
                            "name": "int",
                            "applicationId": 0,
                            "elementType": null,
                            "elementTypeId": 0,
                            "enumValues": null
                        }
                    },
                    {
                        "id": 3,
                        "name": "timestamp",
                        "description": "...",
                        "displayName": "Timestamp",
                        "type": {
                            "id": 5,
                            "name": "time",
                            "applicationId": 0,
                            "elementType": null,
                            "elementTypeId": 0,
                            "enumValues": null
                        }
                    }
                ],
                "workflowId": 1
            }
        ]
    }
    Tuesday, November 19, 2019 4:03 AM
  • Hi mesgar,

    Just double checking if you are not blocked anymore? If so can you please mark your answer as answer so others can benefict from your solution?

    Thanks :)

    Thursday, November 21, 2019 11:48 AM
    Moderator
  • Hi there, 

    The API succeed but the problem still remains.

    Shouldn't it display the telemetry info on the screen?

    Friday, November 22, 2019 1:03 AM
  • Hi mesgar,

    Not sure about what sample and screen you are referring to? Please bring more clarity to your question.

    Thanks!

    Friday, November 22, 2019 11:46 AM
    Moderator
  • Hi, 

    Thanks for update.

    Since i'm not able to upload link or image here, 

    I opened a ticket below with screenshots for better understanding.

    github.com/Azure-Samples/blockchain/issues/214

    Friday, November 22, 2019 3:56 PM
  • Thanks mesgar we will follow-up with you there. In order to upload images to MSDN thread you need to validate your user.
    Monday, November 25, 2019 4:39 PM
    Moderator