csharp

Create a Contact in HubSpot using C#

In this article, we will learn about How to Create a Contact in HubSpot using C#.
In this blog, we will learn step by step using a console How to Create a Contact in HubSpot using C#.
Now Open Visual Studio and create the project as:
“Start” –> “All Programs”- “Microsoft Visual Studio 2017”.
“File” – “New Project” – ” Select Visual C# from left template” – “Console App(.Net Framework).Write the name of Project and Click Ok Button.

key Point:
After creating a project right click on your project and click on “Manage NuGet Packages..” and install “RestSharp” library.


After installation you can check your Refrence folder.RestSharp library store in “Referencefolder.

Before Create a Contact in HubSpot using C#.Learn about some basic knowledge of “RestSharp”.
RestSharp:It is generally used for create Web Services and Web request in .Net.It is an open-source HTTP client library that works with all kinds of DotNet technologies.

Finally Open “Form1.cs” page to write code for Create a Contact in HubSpot using C#.
[php]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Need to add this Namespaces
using RestSharp;

namespace Contact
{
class Program
{
static void Main(string[] args)
{
var emailAddress = "write here email";//like abcd@gmail.com
var hapikey = "write your hapi key";
var client = new RestClient("https://api.hubapi.com/");
var request = new RestRequest("contacts/v1/contact/createOrUpdate/email/{email}",Method.POST);
request.AddUrlSegment("email",emailAddress);
//request.AddUrlSegment("phonenumber",phoneNumber);
request.AddQueryParameter("hapikey",hapikey);
request.RequestFormat = DataFormat.Json;

request.AddBody(new
{
properties = new[]
{
new{property="firstname",value="Andrew"},
new{property="lastname",value="Flintoff"},
new{property="phone",value="555-123-2323"},
new{property="city",value="England"}

}
});
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
Console.ReadLine();
}
}
}

[/php]

Any question and suggestion related to this article please comment me. Thank you

Leave a Reply

Your email address will not be published.