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

Community site session details

Session Id : JKiWut1aQYzeMXc6dltwHb
Power Automate - Using Connectors
Unanswered

Custom connector encoding URL parameters

Like (0) ShareShare
ReportReport
Posted on 24 Aug 2022 14:05:37 by

Hi, hoping someone can help here.

 

I have built a custom connector, all works fine providing I don't provide multiple values for an array parameter.

 

The original URL could look like:

 

http://example.com/api/v2/events?processId=10,20,30

 

I've defined the Custom Connector definition using Swagger, below is a snippet of what has been defined for this action:

 

paths:
  /events:
    get:
      tags:
      - Events
      description: Get a list of events filtered by Query Parameters
      summary: Search for events
      operationId: GetEvents
      deprecated: false
      produces:
        - application/json
      parameters:
        - $ref: '#/parameters/processId'
      responses:
        200:
          $ref: '#/responses/EventCollectionOk'
        400:
          $ref: '#/responses/BadRequest'
        404:
          $ref: '#/responses/NotFound'
parameters:
  processId:
    name: processId
    in: query
    type: array
    collectionFormat: csv
    items:
      type: integer
 
When I go to test, I'm getting a InternalServerError back from the API. Looking at the request URL it appears to be encoding the "," like so:
 
 
The following error is then seen in the response body:
 
{
"type": "NumberFormatException",
"message": "An exception has been raised by the application.",
"messageKey": "rest.exceptions.Exception",
"diagnostic": "For input string: \"10,20,30\""
}
 
Using Postman, I can replicate this behaviour, but if I change the "processId" value to "10,20,30" it works fine.
 
Is there a way to prevent the custom connector encoding request URL? There's another 100+ query parameters that also are in the same situation, I've tried to change the items type to "string" / "number" with no change in behaviour.
 
When its used in a flow, the same behaviour is experienced, I'm guessing anyway as that also sees an internal server error, but if I don't use multiple parameter values in the query parameters, it works fine.
 
Thanks đꙂ
  • SJacobs Profile Picture
    71 on 09 Jun 2023 at 17:49:33
    Re: Custom connector encoding URL parameters

    @mapedad :This works perfectly!  Thanks for posting the solution.

     

    A note to others who find this solution.  I first understood the issue by looking at the actual request (see screenshot below) using the Testing feature in power automate custom connector, where a query parameter called "$expand" was url encoded to become "%24expand".  Each time I send the request, the $expand parameter was ignored, and I now know that it became unrecognizable after url encoding.

     

    After adding the custom code, the $expand parameter worked as expected.  However, I noticed that in the response with the testing area (see screenshot below), it looks like it's still URL encoded, leading me to believe it was not working.  The response turned out to be correct, so the testing "request" is shown as it exists without the additional custom code.

     

     

     

    SJacobs_0-1686332508866.png

     

  • mapedad Profile Picture
    6 Most Valuable Professional on 04 Jun 2023 at 17:34:17
    Re: Custom connector encoding URL parameters

    Hello folks!

    I encountered the same issue where the Custom connector always encoded the escape characters into the URL. To address this, I implemented a simple workaround by using custom code within the connector. Here's how you can do it:

    public class Script : ScriptBase
    {
     public override async Task<HttpResponseMessage> ExecuteAsync()
     {
     // get current request Uri
     var strRequestUri = this.Context.Request.RequestUri.AbsoluteUri;
     var strRequestUriDecode = (HttpUtility.UrlDecode(strRequestUri));
     this.Context.Request.RequestUri = new Uri(strRequestUriDecode);
    
     HttpResponseMessage response = await this.Context.SendAsync(this.Context.Request, this.CancellationToken).ConfigureAwait(continueOnCapturedContext: false);
     return response;
     }
    }

    Hope it helps!

  • brand0n Profile Picture
    4 on 09 Mar 2023 at 20:18:35
    Re: Custom connector encoding URL parameters

    Bumping this. I'm having a similar issue:
    Setting up a custom connector, I need to add a token to the query, and the token involves the '%' character, which is automatically URL encoded. This encoding then sends the request to the incorrect place, so the connection isn't ever made.

    I found x-ms-skip-url-encoding and tried integrating this, with and without x-ms-paths. However, it does not seem to stop the url encoding from happening.

    If there is a way to stop this url encoding please reply, microsoft! There are ways with Swagger (allowReserved: true WOULD work, but it isn't supported??) I can even edit the Swagger UI code and get the code to POST to my webhook. I can 'execute' the code within that test area, and it works fine, but the editor doesn't let me save my Swagger code because it doesn't like what I had to do to get Swagger to send the string '?token=XXX%234%XXXXXXX' without it encoding the reserved characters.

    Please take a look at this! It seems like a really simple thing, it could just be allowed in the parameters section of the custom connector, where you can choose 'string, date, binary, byte' etc. where if in the 'query' it will turn the 'allowReserved' for that parameter to 'true'. 


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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 2

Featured topics

Loading complete