cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tbelvin
Frequent Visitor

Get data from post request from Sharepoint HTTP request

We have a legacy API that is a POST method. In the body of the post, we have the following:

{
"headerParam": {
"user_Key": "our-in-house-user-key-goes-here",
"license_key": "our-in-house-license-key-goes-here"
},
"Transactions": null,
"SalesDateTime": null,
"state": "Washington",
"methodName": "GetInventoryTransfer",
"methodType": "GET",
"global_id": "WALLAB.ITJZ4"
}

 

This particular service is calling another 3rd party service - it is calling their "GET" on the method "GetInventoryTransfer". Our wrapper API is a POST (not sure if any of that matters).

 

We are trying to use this API in PowerApps.

 

Our flow looks like this:

FlowFlow

FLow showing POST body and Response bodyFLow showing POST body and Response body

The formula we use for the OnSelect for the PowerApp button that triggers this flow is:

ClearCollect(colResponse, GetInventoryItemByGlobalId.Run())

 

All the collection is getting back is the value "true". We I replace the collection with a regular variable such as:

Set(varResponse, GetInventoryItemByGlobalId.Run())

the value of varResponse is "true".

 

When I run the flow inside of the flow environment, I get the following output:

Flow3.PNG

The flow runs as expected and the body in the Outputs is the data I am trying to receive in my PowerApps app.

 

Any suggestions?

3 REPLIES 3
v-bacao-msft
Community Support
Community Support

Hi @tbelvin ,

 

You could consider using Parse JSON action.

Configure the Response Body JSON Schema in the Parse JSON Schema and configure the Response output body in the Content.

This way Dynamic Content generated by Parse JSON seems to be what you need.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

That sounds like a reasonable solution but I can't figure out how to code the Flow step. I am not able to find any examples of it either. 


@v-bacao-msft wrote:

Hi @tbelvin ,

 

You could consider using Parse JSON action.

Configure the Response Body JSON Schema in the Parse JSON Schema and configure the Response output body in the Content.

This way Dynamic Content generated by Parse JSON seems to be what you need.

 

Best Regards,


I have sucessfully achieved something similar using the technique Barry hase decribed, albeit without the Parse JSON (Data Operations) action but instead using the Select (Data Operations) action. 

 

I went into "somewhat" more detail in a blog I subsequently posted which may well be aligned with your specific requirements:

Leveraging Graph APIs in PowerApps & Flow – Photos

 

Of most relevance in the blog insofar as the steps Barry highlighted are the final 3 steps in my own flow:

Screen Shot 2019-04-11 at 07.08.30.png

 

The "Get items v2" is the equivalent of your HTTP wrapper API step, albeit that in my Flow that step is a GET request performed against a SharePoint HTTP REST API and not a POST. The could well be of relevance. Of equal relevance, I also include a Header in the request to return the output as JSON:

 

Screen Shot 2019-04-11 at 07.15.40.png

 

At this point you would need to run the Flow (within the Flow environment) in order to then subsequently generate a sample set of data (JSON) from the output of the HTTP request. 

 

For my own Flow the Body output ("JSON") from own SharePoint HTTP REST APP call was in essense too complex to use as a sample payload required for the Parse JSON action. 

 

Whilst I don't profess to be an expert insofar as having worked with this I type of development, I nonetheless supspect if the JSON returned for my own HTTP request had been less complex, inserting a Parse JSON action prior to the Select action may well have made it far easier to subsequently select the fields from Dynamic content variables generated / exposed from a Parse JSON step, to use as input into the Select action.

 

If so, the Parse JSON step would look as follows:

Screen Shot 2019-04-11 at 08.18.51.png

You would then click the Use sample payload to generate schema link and paste the JSON output from the pervious HTTP request step, following which the schema would be automatically generated.

 

That said, as noted, for my scenerio at least the sample JSON output generated from my own SharePoint HTTP REST API request was simply too complex for the Parse JSON action to automatically generate a valid schema. Consequently I used one of the many JSON formatters on the web such as this one, such that the JSON was thereafter transformed into something at least readable in order than I could then manually construct/code the fields I wanted to return to SharePoint as an array leveraging the Select data operations action, which then looked as follows:

Screen Shot 2019-04-11 at 08.30.40.png

Breaking this down further,

For the *From property, the exact code was:  

array(body('Get_items_v2')['value'])

 

For the *Map property Name property, the corrosponding code was:

@item()['name']

 

For the *Map property ContentType property (this being a complex type field), the corrosponding code was:

@item()['listItem']['contentType']['name']

etc...

 

Having now generated an array that PowerApps can understand, the final step in the Flow is to add as Response action in order to return the Output from the Select action in the Body property. However before you can add the Response action to the Flow, you once again need to provide a sample payload to generate the schema for the Response action by testing the Flow in the Flow environment, and copying the Body output of the Select action step to use as the sample payload to generate the schema:

Screen Shot 2019-04-11 at 08.53.30.png

 

Perhaps the most obvious difference between the content returned to PowerApps using this technique when compared to the screenshots you initially shared at least is that with this technique you can see that the schema for the Response actions returns the data to PowerApps as an array, whereas the Response schema per your initial attempt returned the data as an object.

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (1,248)