How do I successfully call a REST API using a Microflow?
I’m receiving a cryptic “An error occurred, please contact your system administrator” error when trying to press a button on a page that calls a microflow that calls an API. I am simply trying to the equivalent of GET “https://newsapi.org/v2/everything?q=upskilling AND coronavirus&apikey=[mykey]” The API works in postman and it’s such a simple API it works in a browser as you just put the auth token in the URL as another parameter. I’ve tried this with this API and one other and neither seem to work. I’m sure I’m missing a simple setting? For testing purposes, I’ve tried both putting the entire call in a string in a single parameter in the Location field and I’ve tried parsing it and putting the API parameters as key value pairs under HTTP Headers. I’ve also tried messing with the proxy config as you can see below. Any other ideas appreciated!
You’re calling https://newsapi.org/v2/everything?q=upskilling AND coronavirus&apikey=[mykey]
This is not valid because of the spaces in your endpoint. You need to use urlEncode() function for your q parameter value. Like so:
'https://newsapi.org/v2/everything?q=' + urlEncode('upskilling AND coronavirus') + '&apikey=[mykey]'
Can you make sure the list of things for Execute a rest Call
As you said its working on postman , can u add a basic headers As Content-Type: application/json, those are available in postman headers we can keep as in mendix rest call.
Make sure to try the same URL as you trying in postman.
We can pass apikey in the URL as you made there won’t be any issue.
If still have the issue can you please provide information of headers. Hope this helps.
in call rest activity ,check parameter in location , URL location should not contains any unnecessary spaces, hope so it will be work. if URL is correct then need to select the apply import mapping option from the drop-down list for response handling In response tab and Select import mapping . thank you
In addition to the other answers, while debugging REST calls I find it useful to put the “REST Consume” log node up to TRACE so I can see all the requests and responses in the console. It helps to see what is going backwards and forwards, and if the messages are what I am expecting.
After trying a few things it appears I’m having a cert issue. I’ll see what I can find out and if I learn anything report back. I’ve tried adding a .cer file from a trusted site to my app config but no luck so far.
Just confirming for me this is a cert issue. Basically I needed to export all my certs from the browser then import them into the app.