cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Blaired79
Regular Visitor

Extracting content from an object from Http request

Using When a HTTP request form Twillio which is triggered when an SMS is received, I want to extract the content of the SMS, from number, message content etc. The below screenshot is as far as I have got, how to I extract the content? Ultimately I am wanting to push this information in an email for example661A41C4-087C-4B7D-ABFE-0052E5242097.jpeg

1 ACCEPTED SOLUTION

Accepted Solutions
eliotcole
Super User
Super User

Not a problem, @Blaired79, this is why I pasted the codes into my previous responses, above, in the code boxes.

 

If you use as expressions (for example, with 'key' in the Switch) it should work.

 

I'll reword them slightly to make that clearer.

View solution in original post

8 REPLIES 8
mahoneypat
Dual Super User
Dual Super User

You need to add a Parse JSON step that uses your trigger output as the input, and then you hit the button called "Generate from sample" and paste in your json response (one time) as the example.  This will convert your JSON input to an array that you can use downstream in other steps.

Power Automate Flow How to: Parse JSON - YouTube

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about the Power Platform, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


eliotcole
Super User
Super User

@Blaired79 what would really help us out would be if you could put a screen shot of your flow (blank our sensitive data) in the original post for this thread.

 

Also, I've done this previously, and remember it's a bit of toil and trouble.

 

@mahoneypat, I didn't want to say anything, but I remember Twilio being a right pain, the SMS data is buried in an array of data. Whilst Adding the Parse JSON will help, it might not obviously result in the data for Blaired, but I do think it's a valid solution.

Piecemeal Solution

@Blaired79 , without seeing your flow, you can try this. Assuming that your Twilio instance is firing at an HTTP trigger in flow, then place a Filter action after it, like so:

filter array.jpg

From:

 

 

@triggerBody()?['$formdata']

 

 

Condition:

 

 

@or(equals(item()?['key'], 'From'),equals(item()?['key'], 'Body'))

 

 

Getting the Data From The Filter

After this, I would unfortunately need my flow to be working (it isn't, because my Twilio lapsed) to get the rest. This said, looking at my old flow, I think each array entry is a part of the text data, there are more elegant ways to do this, but I made this before I knew them ... also ... will need to see your flow to apply the elegance anyway. 😉

 

Either way, run an Apply to each action, which should run twice for the two matching entries that the Filter actions creates.

 

Inside that, place a Switch action, that runs on the 'key' key (😩) value, and make two cases:

  1. Body - If the 'key' is Body, then it will set the smsBodyVAR variable.
  2. From - If the 'key' is From, then it will set the txtFromVAR variable.

flow.jpg

 

After this Apply to each has run (which should be swift) then you'll have the values you need.

Thanks @eliotcole Twilio is a right pain as I have discovered the output isn't what Parse JSON and I get this error

The property ‘content’ must be of type JSON in the ‘ParseJson’ action inputs, but was of type ‘appli...

 

Below is what I have created so far and I've added your filter, which gives me the SMS body and the sending number.

Untitled 2.png

 

How do I turn these values into a variable that I can put in an email etc?

 

Untitled.png

 

I tried recreating your Power Automate but I did not have the 'key' value to use in the switch condition.




 

eliotcole
Super User
Super User

It's all good, @Blaired79. 🙂 

 

((( if you look at my flow, you can see that the Switch is inside the Apply to each which runs on the Body from the Filter action )))

 

You just need to run an Apply to each on the Filter body, that is where you can then take the values. 👍

 

If your Apply to each is literally called 'Apply to each' then using the following expression in the Switch 'On' field, will get the 'key':

On:

 

items('Apply_to_each')?['key']

 

Similarly, when defining either smsMsgVAR or smsFromNumVAR then use this expression to get the 'value':

 

items('Apply_to_each')?['value']

 

 

This just means that the expression looks at the current item in the loop, and in particular the 'value' field. Once you've run it once, Flow should automatically just label them key and value. 🙂

 

If this is your first time using expressions, just look at the two tabs on the pop up, you have Dynamic content, and Expression. Choose 'Expression' and enter the function in there. 🏆

Hi @eliotcole, thanks for replying so quickly.  It's the apply to each area that I am having issues with.

Blaired79_0-1636380688608.png

I've been trying to read the text for your formulas in your apply to each and switch but the image pixelates.  I think the sticking point for me the is getting key in the switch condition.

 

eliotcole
Super User
Super User

Not a problem, @Blaired79, this is why I pasted the codes into my previous responses, above, in the code boxes.

 

If you use as expressions (for example, with 'key' in the Switch) it should work.

 

I'll reword them slightly to make that clearer.

Blaired79
Regular Visitor

I finally got there @eliotcole, thanks again, especially for your patience 🙂

eliotcole
Super User
Super User

Don't give it a second thought, @Blaired79, mate, just happy to help!

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power automate tips 768x460 v2.png

Restore a Deleted Flow

Did you know that you could restore a deleted flow? Check out this helpful article.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (2,443)