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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to Make a Simple C...
Power Automate
Unanswered

How to Make a Simple Custom Connector With Custom C# Code?

(1) ShareShare
ReportReport
Posted on by 4,980 Moderator
Hello,

I want to learn how to create custom connectors that use the C# code component. I'm starting by trying to create a custom connector that doesn't really call any API, but instead just takes a single input like Name and then passes that Name parameter to the C# code to form & output a dynamic "Hello, {Name}" string.

So far even with chat gpt I'm having trouble. I've created the Request piece in the Definition stage with a required Name header / input. But I can't seem to get the C# code to properly pull that Name data in & add it to the string. How should the C# be set up? Do I have to also set up the Response in the Definition a certain way?
 
 
 
C# Code...
 
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
 
public class CustomScript : ScriptBase
{
    public override async Task<HttpResponseMessage> ExecuteAsync()
    {
        try
        {
            // Read the request body
            var requestBody = await this.Context.Request.Content.ReadAsStringAsync();
 
            // Parse the JSON content
            var json = JObject.Parse(requestBody);
            var name = json["Name"].ToString();
 
            // Create the greeting message
            var greeting = $"Hello, {name}";
 
            // Create the response
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent($"{{ \"Greeting\": \"{greeting}\" }}", Encoding.UTF8, "application/json")
            };
 
            return response;
        }
        catch (Exception ex)
        {
            // Log the exception and return an error response
            var errorResponse = new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = new StringContent($"{{ \"error\": \"{ex.Message}\" }}", Encoding.UTF8, "application/json")
            };
 
            return errorResponse;
        }
    }
}
 
 
 
 
Thank you for any help!
Categories:
I have the same question (0)

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 378

#2
Valantis Profile Picture

Valantis 329

#3
David_MA Profile Picture

David_MA 283 Super User 2026 Season 1

Last 30 days Overall leaderboard