简体   繁体   中英

Azure Logic Apps send JSON Message to ServiceBus

I want to send JSON to Azure ServiceBus from a Logic App, but I'm struggling with the correct formatting (I think). The Logic App gets information from a SharePoint Online list item, so I can access it within the Logic App as dynamic content. For this post, assume the JSON template looks like this:

{ Title: '', CreatedBy:'' }

Now in the Logic App designer, I set the Content Type to "text/plain" to ensure the encoding is handled (as described here ) and then added the template above to the "Content" field. It looks like this in Logic App designer (code view), which is what I expected:

"ContentData": "@{base64('{ Title: '', CreatedBy:'' }')}"

If I go back to designer and, between the single quotes for "Title", I add the field from my dynamic content, the designer (code view) looks like this:

"ContentData": "@{base64(concat('{ Title: '',triggerBody()?['Title'],'', CreatedBy:'' }'))}"

When I try to save, I get the following error:

Failed to save logic app MyLogicApp. The template validation failed: 'The template action 'Send_message' at line '1' and column '163728' is not valid: "Unable to parse template language expression 'base64(concat('{ Title: '',triggerBody()?['Title'],'', CreatedBy:'' }'))': expected token 'RightParenthesis' and actual 'Identifier'.".'.

I feel like the error tells me the problem but I can't quite figure it out. Can someone help me with the correct formatting please?

From the article I linked to above, I also tried this but got the same error:

"ContentData": "@{base64(concat('{ Title: '', string(triggerBody()?['Title']),'', CreatedBy:'' }'))}"

Edit: I forgot to add that I found this article that recommended adding the decodeBase64 when working with JSON and Logic Apps. Not sure if it's relevant though as I'm not parsing from ServiceBus.

Managed to find a solution with some trial and error. If was my dodgy formatting at fault so updating how I resolved in the hope someone else finds this useful.

The Logic App code view should look like this:

"ContentData": "@{base64('{ Title: {triggers().outputs.body.Title}, CreatedBy: {triggers().outputs.body.CreatedBy} }')}"

The Logic App designer view Content field should look like this:

{ Title: {triggers().outputs.body.Title}, CreatedBy: {triggers().outputs.body.CreatedBy} }

I'd love to post some citation or supporting articles but I've not been able to find any as yet - would appreciate if anyone has any useful resources on sending messages to Service Bus via Logic Apps to add them to this post. Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM