APIs & Integrations

highstreetdave
Participant

Examples of using HubSpot.Net to read and update a deal

Hi all,

 

I'm using the HubSpot wrapper in C#.Net. I can create a new contact or deal, but i am struggling to understand updating an existing deal. Does anyone know where I can find examples of reading and updating a deal using HubSpot.Net?

 

Many thanks,

 

Dave

0 Upvotes
7 Replies 7
CBN
Top Contributor

Examples of using HubSpot.Net to read and update a deal

I think this is the most up-to-date HubSpot.NET integration is this one: 

 

https://github.com/Chinchilla-Software-Com/HubSpot.NET

dennisedson
HubSpot Product Team
HubSpot Product Team

Examples of using HubSpot.Net to read and update a deal

Hey @highstreetdave ,

Welcome to the community!

I am not versed in the .net wrapper, but I wanted to tag a few people in who might be able to help.

 

@WernerD , @turner_bass , @gotmike ,

Do you all have any ideas here?

 

As an aside, I feel like I have seen a couple .net questions in the past few weeks.   @turner_bass , are you still maintaining the github repository?  Last commit was in Nov of last year.  If not, looks like you may have some traction and a few folks who could help you out 

(nudge nudge 😄)

 

Best,

d

0 Upvotes
gotmike
Top Contributor

Examples of using HubSpot.Net to read and update a deal

sure i'm happy to help. what code are u working with now?

 

how far have u gotten so far?

highstreetdave
Participant

Examples of using HubSpot.Net to read and update a deal

@gotmike Thanks for the reply. The short answer is that I have not got very far at all!

 

Cards on the table: I am actually writing the code in VB.Net, taking examples from C#.Net and translating them. The rest of the website is VB.Net so I have to stick with that, and I don't use C#.Net so I am struggling with the syntax. In addition, I have never worked with an API or HubSpot before, so I have a steep learning curve ahead. It also means that when things don't work I am not confident which of the new things I am learning has gone wrong.

 

The gist of the work is that we generate deals in HubSpot for simple products, but for our more complex products we step out into a configurator tool (in VB.Net) which puts togther the configured product and also calcualtes the exact price. I then want to push this price back into HubSpot to update the deal with the accurate price. I can pass the DealID as a parameter into my configurator, so I just need to use that when updating HubSpot

 

I can create  new deal, and that part works. In VB it looks like this:

Dim newdeal As DealHubSpotModel = hsapi.Deal.Create(New DealHubSpotModel() With {
      .Amount = 0.01,
      .Name = "DSTest5"
    })

 

What I am looking for now is the equivalent of SQL:

SELECT * FROM deals WHERE DealID = 12345;

UPDATE deals SET Amount = 1234.56 WHERE DEALID = 12345

 

I have started by trying to get the list of deals, but I can't get the syntax right. If I can find a C# example I can stick it into telerik's code converter to get the VB example. It is something like this in VB:

    Dim deals As List(Of DealHubSpotModel) = hsapi.Deal.List(Of DealHubSpotModel()(False))

But the above is wrong because I get an error "argument not specified for parameter 'include associations'", which is what the False is meant to be.

 

Obviously the above will become inefficient as we generate more and more deals, so I want to be able to find all deals by contact or date range as example filters, or better still just the single deal by ID.

 

So, that's where I am. Any help gratefully received!

 

 

 

0 Upvotes
highstreetdave
Participant

Examples of using HubSpot.Net to read and update a deal

Hi all,

 

I have worked it out. This is what I was looking for:

Dim SpecificDeal As DealHubSpotModel = hsapi.Deal.GetById(Of DealHubSpotModel)(1234567890)
SpecificDeal.Amount = 0.02
hsapi.Deal.Update(Of DealHubSpotModel)(SpecificDeal)

 

This is the first step of many, but I'm starting to get a handle on how these bits work.

Thanks for your pointers and help.

 

Many thanks,

 

Dave

 

highstreetdave
Participant

Examples of using HubSpot.Net to read and update a deal

Update:

 

I can now get the 10 most recent deals. This is tested and working in VB.Net:

Dim hsapi As New HubSpotApi("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")

    Dim DRRO As New DealRecentRequestOptions With {
      .Limit = 10
    }
    Dim recentdeals As DealRecentListHubSpotModel(Of DealHubSpotModel) = hsapi.Deal.RecentlyCreated(Of DealHubSpotModel)(DRRO)


    lblHS.Text = ""
    For i As Integer = 0 To 9
      lblHS.Text = lblHS.Text & i & ", " & recentdeals.Deals(i).Id & "### "
      If recentdeals.Deals(i).Id = 3012706620 Then
        lblDeal.Text = recentdeals.Deals(i).Name
      End If
    Next

It extracts deal information into recentdeals and then looks through and writes the Deal ID next to its index in the list. It also looks for a specific deal and gives me a piece of information from it (the name in this case).

 

That is fine, but now I want to be able to pull out a deal that may not be recent, by name or contact id. Is there an equivalent of DealRequestRecentOptions for a more generic search?

 

Many thanks,

 

Dave

0 Upvotes
gotmike
Top Contributor

Examples of using HubSpot.Net to read and update a deal

in the wrapper, here is example code to update a contact property...

https://github.com/hubspot-net/HubSpot.NET/blob/fb80df59396a856fed7271e2ce55e264cdecc8cd/HubSpot.NET...

 

i don't see code in there to update a deal.

 

we started this before that repo was very far along, so ended up rolling our own tools. i might have deal update code in ours somewhere, i'll have to look.

 

i see several old pull requests and not much going on in that repo so it might be abandoned. not sure.

0 Upvotes