cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
RussT
Level: Powered On

Custom API Connector - Retrieve response body of a 400 bad request message

Hi

I'm trying to surface the error messages my API provides when it has an issue with new POST request. My connector definition correctly validates the 200/400 responses but I can't make PowerApps surface the response body of the 400 message. If I force the "error response" into a 200 response, I can see the body but thats not a workable solution.

Any ideas on how to get access to the response body of a 400 message?

 

Thanks in advance - Russ

 

4 REPLIES 4
Community Support Team
Community Support Team

Re: Custom API Connector - Retrieve response body of a 400 bad request message

Hi @RussT,

 

Could you please share more details about the 400 response definition within the OpenAPI file?

If there is response body defined, the Custom connector  should be able to get the response through:

 

Connector.run().Response

Or

Connector.run().Result

The Response or Result here should be the value defined within the Response, in order to get the result.

You may also take a try with the method below:

ClearCollect(APIResponse, Connector.run())

which should be possible to hold the whole result into a local connection, when trying to run or call the connector.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
RussT
Level: Powered On

Re: Custom API Connector - Retrieve response body of a 400 bad request message

Hi Michael

 

I wasn't aware of the other methods you have shared. I will do some testing and see if they are usable. The swagger file is very large so I will attempt to distill it down to just the affected definition and retest if you feel that it should be passed through already. I will come back with my results and the swagger file if it is still not working for me

 

Thanks - Russell

RussT
Level: Powered On

Re: Custom API Connector - Retrieve response body of a 400 bad request message

Hi @v-micsh-msft

 

Unfortunately this is still broken and appears to be an issue in PowerApps. I've created a small basic application which you can use with a custom connector to easily reproduce the issue.


Custom Connector can be created form URI at https://customconnector.azurewebsites.net/swagger.json

There is a single Action "Get-Response" which takes a single query string parameter of 200 or 400. eg...
https://customconnector.azurewebsites.net/api/get-response?code=200 -> Generates a 200 OK response with a JSON body of 2 properties - status and message
https://customconnector.azurewebsites.net/api/get-response?code=400 -> Generates a 400 Bad Request response with a JSON body of 2 properties - status and errormessage

In my PowerApp, it doesn't matter if I assign the returned API call to either a variable or collection, the body of the 400 response is never surfaced to the app. The body of the 400 message does show correctly however in the PowerApp editor control plane when you hover over the "red x" icon.

The PowerApp code where the connector is called "CustomConnector"
Succeeds
Set(response,CustomConnector.GetResponse({code:200}))
ClearCollect(colResponse,CustomConnector.GetResponse({code:200}))
Fails
Set(response,CustomConnector.GetResponse({code:400}))
ClearCollect(colResponse,CustomConnector.GetResponse({code:400}))
In my particular use case, I submit a request for processing to the API. If the response fails due to some issue in the request, the API returns the appropriate 400 message with the reason in the resposne body. I wish to monitor for this situation and prompt the user to fix the reported issue (from the message body) and try again.
 
Hopefully this makes sense and small application can help repro the issue.
 
Russell
RussT
Level: Powered On

Re: Custom API Connector - Retrieve response body of a 400 bad request message

Hi Michael( @v-micsh-msft)

Any thoughts on this?

 

Thanks

Russell