web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / CORS failed to fetch e...
Power Automate
Unanswered

CORS failed to fetch error with custom HTTP connector with Basic auth

(0) ShareShare
ReportReport
Posted on by 250

Trying to access a 3rd party REST API. It fails with the built-in HTTP connector. Thus creating my own connector and it still fails. Here is the screenshot showing you the def of the connector in the Swagger editor with the curl and result to the right.  Could all this be due to Microsoft not having properly initialized the JavaScript fetch() API credentials options like so:

 

'To send credentials in fetch, we need to add the option credentials: "include", like this:'

fetch('http://another.com', { credentials: "include" });

 source: https://javascript.info/fetch-crossorigin

Screenshot:
swagger_editor_CORS_error.JPG

Categories:
I have the same question (0)
  • iso Profile Picture
    250 on at

    FYI this curl works as intended. So what is the Microsoft JavaScript doing under the covers???
    curl_working.JPG

  • iso Profile Picture
    250 on at

    For those searching, I found out why all this nonsense behavior is happening... but I'll wait before posting the reason until Microsoft gets off theirs a$$es and actually provides some well needed support re this. Why?  Because this concerns one of the most basic user interaction with the UI and it should have been explained and highlighted and documented wide and clear with an easy to find link so that a basic search would find it, all of which are not the case today.  And that is unacceptable considering the amount of time wasted at guessing why (hint) what looks like an editor textbox does not actually behave like an editor.

  • kamenastra Profile Picture
    6 on at

    Please @iso , please share the solution. I've been searching for 2 days and no luck. Much appreciated!

  • iso Profile Picture
    250 on at

    Fine... Microsoft should be paying us for doing all the beta testing and providing support to each other. 

     

    1_ if the GET request uses the header Content-Type: application/x-www-form-urlencoded, then you have to URL encode manually the following fields (assuming this is the URL to GET the token):  app key, app secret, and other request params that are joined by '&' , in other words, in the curl screenshot above, everything that follows --data-urlencode, you should URL encode manually using the encodeUriComponent() function like so:

     

    add a Compose action to your flow and type in the Expressions tab that shows up in the dialog to the side :  encodeUriComponent( 'app_key' ), where 'app_key' is a string of characters typically provided by the REST API author; so if you have 4 such params, then you would need 4 Compose actions, and so on.  If using variables for app_key etc instead of typing the string literal, then make sure you click on Dynamic content and select the variable in the list that contains the value you want to pass to the encodeUriComponent() function.  The flow UI is picky when it comes to typing everything straigth into an action textbox versus using the Dynamic context and/or Expression tabs in the edit dialog that pops up after clicking inside a textbox.

     

    2_ the textboxes you see in the UI for the HTTP action apparently are not meant to be used as if you were in an editor; for ex, to enter the Body of the request, if you type in app_key=encodeUriComponent('your_app_key')&app_secret=encodeUriComponent('your_app_secret')&.... and so on, it won't work; apparently, Power Automate Cloud expects you to type the first half, ie 'app_key=' and then go to the Dynamic Content tab of the dialog that opens up when you click inside a textbox and from there scroll down until you find the output of your previous compose actions and add these outputs using the GUI; at least for me, my first reflex was to type everything in and it simply refused to work.

     

    http_post_token_req_Screenshot 2022-05-04 142030.png

     

    And that's it. As you can see from the screenshot above, once you click on each Compose output, it appears as a purple widget inside the textbox. 

  • kamenastra Profile Picture
    6 on at

    Thank you VERY much @iso . Worked in a flow for me so that's awesome. Still figuring out how to get it to work in a custom connector though. Thanks again!!

  • iso Profile Picture
    250 on at

    You're welcome. Please click the 'Accept as Solution' button.  😁

  • siriusalsahim Profile Picture
    8 on at

    In your custom connector, replace 

    consumes:
    -application/x-www-form-urlencoded

     

    by 

     

    consumes:
    - multipart/form-data

  • sRnA Profile Picture
    2 on at

    Hello @sirisalsahim, Can you elobarate more on your answer what do you mean by Consumes where is that Consumes in Custom Connectors 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard