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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

API calling from C# Using Connection

(0) ShareShare
ReportReport
Posted on by 2
Hello everyone,
I'm relatively new to the Dynamics world and currently facing a challenge. I've created a new custom connector with OAuth 2.0 and successfully added some connections to it. Now, my goal is to execute an action of the custom connector using C# code. Is this possible, and if so, how can I achieve it?
After successfully calling the API and obtaining the response, my next step is to send this response to a PowerApps Component Framework (PCF) component to display the data. Any guidance or assistance on how to proceed would be greatly appreciated.
Thank you!
I have the same question (0)
  • Verified answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at
    Hi ,

    Yes you can call the custom connector using C# as shown in below code snippet:
     
    
        static async Task CallConnector(string accessToken)
        {
            // Construct HTTP request
            var request = new HttpRequestMessage
            {
                Method = HttpMethod.Post,
                RequestUri = new Uri("https://URLofyourconnector/action"),
                Headers =
                {
                    { "Authorization", $"Bearer {accessToken}" },
                    { "Accept", "application/json" },
                    // Add other required headers if needed
                },
            };
    
            var response = await httpClient.SendAsync(request);
            if (response.IsSuccessStatusCode)
            {
                // Process successful response
                var responseBody = await response.Content.ReadAsStringAsync();
                Console.WriteLine($"Response: {responseBody}");
            }
            else
            {
                Console.WriteLine($"Error: {response.StatusCode}");
            }
        }
    Now, to pass this response to PCF control, You need to setup a bound parameter and from C# code set that bound parameter. But PCF Control need to refresh manually to get the record.
     
    But I would suggest if you want to use response in PCF control then directly call the action inside PCF control.
     
    Thank You,
    Pradeep Rai.
     
    Please mark as Verified, if my suggestion help you to resolve the query.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 96 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans