1

I have a logic app which is triggered by new messages on a Service Bus subscription. The message is a json object, like the following:

{
    "PublisherName": "XXX",
    "PublisherKey": "XXX",
    "Identifier": "XXX",
    "Value": {
        // ...
    }
}

How can I do an http request, using the publisher key as a header, the identifier as a query parameter, and the value as the body?

Andrew Williamson
  • 8,299
  • 3
  • 34
  • 62

2 Answers2

2

Typically, your service bus message from your subscription will be base64 encoded.

Try the following in code view:

        "queries": {
          "Identifier": "@json(base64ToString(triggerBody()?['ContentData'])).Identifier"
        }
        "headers": {
          "PublisherKey": "@json(base64ToString(triggerBody()?['ContentData'])).PublisherKey"
        }
zurebe-pieter
  • 3,246
  • 21
  • 38
  • I have seen similar suggestions to this before, although the designer wouldn't let me enter it so I thought it was incorrect. I guess I have to enter this manually in the JSON file. What does the question-mark syntax mean? `triggerBody()?['ContentData']` – Andrew Williamson Apr 19 '18 at 19:51
  • 1
    The code view is indeed one option, but you can also enter it into the expression editor. The question mark operator lets you reference null properties of an object without a runtime error. See https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language – zurebe-pieter Apr 20 '18 at 08:11
  • I finally got around to trying it out, but it didn't work - `InvalidTemplate. Unable to process template language expressions in action 'Foo' ... : 'The template language function 'json' parameter is not valid.`. What is it not liking about that syntax? (And I did put in the missing comma) – Andrew Williamson May 07 '18 at 21:31
  • It looks like the message content includes a content type as well - `The provided value '@string3http://schemas.microsoft.com/2003/10/Serialization/�4{"PublisherName":"XXX","PublisherKey":"XXX","Identifier":"XXX","Value":{"Id":0,"TrackerId":0,"ScopedId":0,"DateRecorded":"2018-05-07T21:35:34Z","DatePublished":"2018-05-07T21:36:13.2875849Z","Location":{"Latitude":0,"Longitude":0,"Accuracy":0,"Source":"Satellite"},"AnalogInputValues":[{"Number":6,"Value":16.0},{"Number":1,"Value":229.0}],"CounterInputValues":[],"DigitalInputValues":[{"Number":0,"Value":true}]}}' cannot be parsed` – Andrew Williamson May 07 '18 at 21:42
  • I have added a [separate question for this issue](https://stackoverflow.com/q/50223133/2363967). Hopefully, once this is answered I will be able to come back and verify that your solution works. – Andrew Williamson May 07 '18 at 22:08
1

Try the following

"httpAction": {
    "type": "Http",
    "inputs": {
        "body": "@triggerBody().Value",
        "method": "POST",
        "uri": "http://endpoint.com",
        "queries": {
          "Identifier": "@triggerBody().Identifier"
        }
        "headers": {
          "PublisherKey": "@triggerBody().PublisherKey"
        }
    }
}
Szymon Wylezol
  • 1,446
  • 9
  • 10