3

I receive a error from my SharePoint Get-Item action when I try to use data from the Service Bus message triggering my Logic App (inner xml omitted):

Unable to process template language expressions in action 'Get_items' inputs at line '1' and column '1641': 'The template language function 'json' parameter is not valid. The provided value '<?xml version="1.0" encoding="utf-8"?> <Projektaufgabe id="b92d6817-694e-e611-80ca-005056a5e651" messagename="Update"> ... </Projektaufgabe>' cannot be parsed: 'Unexpected character encountered while parsing value: . Path '', line 0, position 0.'.

The decoded message xml looks okay even quoted in the error message.

The received queue message body seems okay - only the ContentType is empty: (ContentData truncated)

{
  "ContentData": "77u/PD94bWwgdmVyc2lvbj0iMS4wIiBl...=",
  "ContentType": "",
  "ContentTransferEncoding": "Base64",
  "Properties": {
    "DeliveryCount": "1",
    "EnqueuedSequenceNumber": "20000001",
    "EnqueuedTimeUtc": "2016-07-29T09:03:40Z",
    "ExpiresAtUtc": "2016-08-12T09:03:40Z",
    "LockedUntilUtc": "2016-07-29T09:04:10Z",
    "LockToken": "67796ed8-a9f0-4f6a-952b-ccf4eda00071",
    "MessageId": "f3ac2ce4e7b6417386611f6817bf5da1",
    "ScheduledEnqueueTimeUtc": "0001-01-01T00:00:00Z",
    "SequenceNumber": "31806672388304129",
    "Size": "1989",
    "State": "Active",
    "TimeToLive": "12096000000000"
  },
  "MessageId": "f3ac2ce4e7b6417386611f6817bf5da1",
  "To": null,
  "ReplyTo": null,
  "ReplyToSessionId": null,
  "Label": null,
  "ScheduledEnqueueTimeUtc": "0001-01-01T00:00:00Z",
  "SessionId": null,
  "CorrelationId": null,
  "TimeToLive": "12096000000000"

}

My parsing function for the SharePoint Get-Item OData filter looks like this:

@{json(base64ToString(triggerBody().ContentData)).Projektaufgabe.id}

I already tried to separate decoding and casting to string:

@{json(string(decodeBase64(triggerBody().ContentData))).Projektaufgabe.id}

Since it seems to be an issue decoding the message, I reckoned it wouldn't help much receiving a json message instead of xml from the Service Bus queue.

Filburt
  • 17,626
  • 12
  • 64
  • 115

1 Answers1

3

So from what I can see you are trying to convert an xml to json. You are very close - only issue is @json() expects either

  1. A string that is a valid JSON object
  2. An application/xml object to convert to JSON

Here, the @base64toString() is converting to a string, but you really need to let @json() know this is #2 and not #1, so changing expression to this should work:

@{json(xml(base64toBinary(triggerBody()[contentdata])))[foo]}

Let me know

jeffhollan
  • 3,139
  • 15
  • 18
  • I tried this and it still throws a wobbly over what is presumable the BOM at the start of the then decoded string. So instead of not being able to parse the xml string to json it complains it cannot parse the string to xml. I decided to bite the bullet and have a native json string sent to the queue from the start. I'll come back and tell how it turned out. – Filburt Jul 29 '16 at 15:24
  • Can you send me a full version of the base64 encoded string? Xml should handle BOM. You can email if you'd rather - jehollan[at]Microsoft.com – jeffhollan Jul 29 '16 at 15:27
  • Ahh I know. Change base64toString to base64toBinary that will preserve the BOM which XML should handle – jeffhollan Jul 29 '16 at 15:28
  • Using `base64ToBinary()` solved my issue - thanks a bunch, mate! – Filburt Jul 29 '16 at 15:49