top of page
Writer's pictureJon Russell

ChatGPT and C# to create custom custom connectors

Updated: Oct 11

tl:dr: I find C# code hard to write, I have used a custom GPT to help me build Power Platform custom connectors that execute C# code. Scroll to here if you just want the step by step guide.


You can download the custom connector solutions from my GitHub repo here.




Good morning


I have been wrestling with this one and whether to write and share this. First off I am a major overthinker, I have always been this way. It’s in my DNA, yes I try not to give a f*ck most of the time. But I’ve come to realise and recognise it’s who I am and it’s not about to change anytime soon.


For the majority of the time it is ok. Overthinking helps me clarify my position in certain circumstances and helps me connect with solutions I am building and clients that I am working with.


I have a ChatGPT plus subscription and I create Custom GPTs to help me and I have ADHD and I struggle to focus on things on a daily basis. I can procrastinate wildly especially on things that I am not passionate about.


I hate cooking, always have done. The choices before me confuse the hell out of me and I struggle to complete basic cooking tasks.


I have a custom GPT for that. A recipe designer that I throw it the ingredients and it comes back to me with a descriptive step by step guide on what to cook.


I am always writing things that are too wordy, I can go off on tangents, so I have a custom GPT for that, it’s called “Tangent Detector” and I use it for my writing when I need to make sure I am focussing on the theme at hand.


I also am not a good coder, I have tried to get there with recent forays into Python and React, but I struggle as I just don’t connect with the language being used. I have custom GPTs for that, that explain to me in step by step guides how to write code in these languages and they try to help me learn, I’m still tweaking these to get me past that “passionate desirability barrier”.


Where are we going with this?


Well, “I” have used ChatGPT and C# to create custom custom connectors. They do a variety of different tasks. All of them apart from 1 don’t use API calls, they use custom C#.


And guess what I SUCK at C#. So….. I have a custom GPT for that, it helps me write C# custom connectors and goes through the connectors code step by step to help me understand what is going on.


I had been tossing and turning as to whether to write this post and share the custom connectors.


I am in a WhatsApp group and I asked them about this and I got some very insightful answers.


Ben Clist said:


“Almost nobody is writing a full piece of code from scratch without some kind of help. Whether that’s boiler plate, a post on a community board found via search, a YouTube video or any of the regex generators (because fuck trying to understand that fully). You using AI is no different, it doesn’t devalue the end result.
I’m sure you’re still learning on the way and that’s how you teach yourself. I taught myself to code from those sorts of materials hacking things together and gradually learning more about how it works. I’m sure it would be more efficient these days with AI.
Aside from that, I’m big into custom connectors and I’d never thought to use the C# functionality to create these kind of tool libraries (usually offload to Azure functions), this is a super cool idea!!”

Nati Turtledove, when I was questioning whether to post this, said:


“Definitely do! Custom connectors are really underrepresented in community content especially using C#”

And


“Def share them! I already see 3 I’d love to test out in a project I’m working on!”

Ben Clist continued


“All developers stand on the shoulders of someone else - in my books gpt is just another resource just like stackoverflow. If it works and it’s robust, you nailed it.”


“Sometimes I wonder if people felt like this when Search Engines became the norm.
It’s awesome you’re sharing this experience Jon, I feel like even from myself when something isn’t quite working or I don’t know where to start, ChatGPT is always my go to.
For me it always felt quite ‘dirty’ but it’s nice to hear people share a similar experience.
I personally don’t think there’s anything to feel bad about anymore. I think software that makes us better and more efficient in our job should be encouraged more than anything else.”

And finally from the ALM god himself Parvez Ghumra:


“I absolutely agree with the comments above. And this is coming from a "pro coder turning low coder". Nobody writes code from scratch, unless you're writing it in binary. Professional software developers are forever using frameworks, libraries, packages etc. This is not cheating. In fact, I'd go as far as saying code reuse is something that good Devs should be striving towards as it reduces maintenance overheads.
Besides, writing the C# code for a custom connector is one very small part of it. There's a lot more work you've put into this yourself to package it up as as a connector so it can be consumed from a Power App, Power Automate etc. If you decide to share it under the Independent Publisher Connector program, there's even more work to get it through the process for that.
You're doing yours a disservice if you undermine everything that goes into the process of building a connector”

That’s the “you’re not overthinking checkbox ticked”. So here goes.


C# Custom Connectors


I thought about different ideas for custom connectors. Things that I have wanted to do in the past but had not worked out to do using other methods.


My list:


* Calculate age from date of birth.

* Calculate days between 2 dates.

* Currency Converter.

* Distance between two coordinates.

* Generate a random text string.

* Number to text converter.

* Text Reversal.

* Validate Email Address.


How to create a Custom C# connector.


Go to https://make.powerapps.com.


In the left hand navigation, click More and then find Custom Connectors.


A screenshot showing how to access custom connectors in Power Platform
Custom Connectors in Power Platform

Click on +New custom connector then Create from blank.


Give the connector a name and then click continue.


Upload an image and give your connector a description, this needs to be longer than 30 characters.


A screenshot showing the General Information page of the custom connector setup.
Custom Connector - General Information

In the URL field just put in “home”. We won’t actually be calling an API we will be using a JSON body to inject the values of the variables we need to the custom

C# code.


Click Security to go to that section, and leave it as No Authentication.


A screenshot showing the security settings page of the custom connector setup
Custom Connector - Security Settings

Next, click on Definition and click New Action, give it a name, description and operation ID. The operation ID cannot have any spaces.


A screenshot showing the add new action part of the Definition custom connector setup
Custom Connector - Add New Action

Scroll down to the Request section and click Import from sample.


Click the POST radio button. In the URL put https://home/.


Then, and this bit is important, add a JSON body which refers to the parameters you want to inject into the custom code.


For example for the Number to Text custom connector I wrote


{
     “num”: 1
}
A screenshot of creating the JSON body schema for the Request Definition section of the custom connector setup.
Custom Connector - Request Definition

Click Import.


Next get your custom C# code and click on the Code part of the breadcrumb, slide the Code Disabled slider over to yes to use custom code and then click the Operations drop down and choose the action you just created and then paste the C# code into the code space below.


Finally, give the custom connector a name. The name must be less than 30 characters.


Then click Create Connector.


A screenshot showing the code component of the custom connector
Custom Connector - Code

Once created click Test, create a connection and then put in the value of the JSON "num" object you created above and click Test Operation:


A screenshot showing the Test screen on the Custom Connector configuration
Custom Connector - Test

You should get an HTTP 200 response along with the result of whatever your custom connector is trying to do.


A screenshot of the response coming back from the custom connector test
Custom Connector - Response

Custom GPT


I have created the Custom GPT for anyone to use.



As always, if you have any questions please get in contact - jon@jondoesflow.com

481 views0 comments

Recent Posts

See All

Subscribe Form

©2019 by Jon Does Flow. Proudly created with Wix.com

bottom of page