How do I successfully call a REST API using a Microflow?

0
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!  
asked
7 answers
1

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]'

 

answered
0

Hi Kevin,

Can you make sure the list of things for Execute a rest Call

  1. 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.
  2. Make sure to try the same URL as you trying in postman.
  3. 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. 

    Thank you.
answered
0

Hi Kevin Densmore,

You can call the REST Service in the following way. If you are doing it using import mapping.

  1. You need to paste the same location URL from where you have copied the JSON Snippet, In general tab by clicking on edit option.
  2.  And need to select the Apply import mapping option from the drop-down list for response handling In Response tab.
  3. And then need to select the Import-mapping which you have created for Importing. 

In this way you can call the REST service.

Hope this will help you. Thank you. 

answered
0

Hi Kevin Densmore,

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 

answered
0

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.

answered
0

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.

answered
0

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.

answered