Skip to main content

Notifications

Power Automate - Connector Development
Unanswered

How to read query parameters using custom connector in C#

(0) ShareShare
ReportReport
Posted on by 4

I have created a custom connector defining the below query parameters. Now, I need to fetch query parameter values and then transform it before sending the request to third-party API. As you can see below, I have defined these parameters under Query section.

AAW23_0-1712168500773.png

 

Now, I have written the below code in c#, but I am not able to fetch parameter values from JSON object. Now, if I define these parameters in the body section then I am able to fetch it. See below.

 

 private async Task<HttpResponseMessage> TransformRequestAndResponse()
    {
        HttpResponseMessage response;
        var contentAsString = await this.Context.Request.Content.ReadAsStringAsync().ConfigureAwait(false);      
        var contentAsJson = JObject.Parse(contentAsString);        
 
        // Fetch parameter values from the request payload. Below code highlighted in red isn't fetching the parameter values since these values are part of Query parameters. 
        var formIdvalue = (string)contentAsJson["formID"];
        var workspaceIdvalue = (string)contentAsJson["workspaceID"];
        var projecttitlevalue = (string)contentAsJson["projectTitle"];
        var requesterIdvalue = (string)contentAsJson["requesterID"];
        var requesterNamevalue = (string)contentAsJson["requesterName"];
        
         this.Context.Request.Content = CreateJsonContent(contentAsJson.ToString());

        // Sending the connector API request
        response = await this.Context.SendAsync(this.Context.Request, this.CancellationToken).ConfigureAwait(continueOnCapturedContext: false);
        
       // Manipulate the response data before returning it
        var responseContentAsString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
        var responseContentAsJson = JObject.Parse(responseContentAsString);
        response.Content = CreateJsonContent(responseContentAsJson.ToString());

        return response;
    }

 

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,495

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,822

Leaderboard

Featured topics