APIs & Integrations

wmamani
Member

Create Deal in C#

SOLVE

Does anyone have an example on how to create a Deal in HubSpot using C#, RestSharp library?

0 Upvotes
1 Accepted solution
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Create Deal in C#

SOLVE

Welcome, @wmamani.

What about something like this?

var client = new RestClient("https://api.hubapi.com/deals/v1/deal?hapikey=redacted");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("undefined", "{\n  \"associations\": {\n    \"associatedCompanyIds\": [\n      263467842\n    ],\n    \"associatedVids\": [\n      100001\n    ]\n  },\n  \"properties\": [\n    {\n      \"name\": \"dealname\",\n      \"value\": \"C# Test Deal\"\n    },\n    {\n      \"name\": \"dealstage\",\n      \"value\": \"appointmentscheduled\"\n    },\n    {\n      \"name\": \"pipeline\",\n      \"value\": \"default\"\n    },\n    {\n      \"name\": \"closedate\",\n      \"value\": 1548349551000\n    },\n    {\n      \"name\": \"amount\",\n      \"value\": \"5000\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

I'm not familiar with C#, but I generated that through Postman's code snippets tool.

Isaac Takushi

Associate Certification Manager

View solution in original post

0 Upvotes
3 Replies 3
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Create Deal in C#

SOLVE

Welcome, @wmamani.

What about something like this?

var client = new RestClient("https://api.hubapi.com/deals/v1/deal?hapikey=redacted");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("undefined", "{\n  \"associations\": {\n    \"associatedCompanyIds\": [\n      263467842\n    ],\n    \"associatedVids\": [\n      100001\n    ]\n  },\n  \"properties\": [\n    {\n      \"name\": \"dealname\",\n      \"value\": \"C# Test Deal\"\n    },\n    {\n      \"name\": \"dealstage\",\n      \"value\": \"appointmentscheduled\"\n    },\n    {\n      \"name\": \"pipeline\",\n      \"value\": \"default\"\n    },\n    {\n      \"name\": \"closedate\",\n      \"value\": 1548349551000\n    },\n    {\n      \"name\": \"amount\",\n      \"value\": \"5000\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

I'm not familiar with C#, but I generated that through Postman's code snippets tool.

Isaac Takushi

Associate Certification Manager
0 Upvotes
wmamani
Member

Create Deal in C#

SOLVE
AKansal9
Participant

Create Deal in C#

SOLVE

Hello,

Did you use any of the c# nugget libraries? I looked they are all missing DealHubSpotAssociations

0 Upvotes