Bad Request when posting a deal


#1

I’m trying to write a simple, one time import for hubspot. At the moment, just trying to update a single property, but it’s failing. Getting “Bad Request”, but I can’t figure out why. Code is as follows, with JSON below. Any ideas?

Private Sub UpdateDeal(dealId As Long, opportunity As ExcelOpportunity)
    Dim url As String = "https://api.hubapi.com/deals/v1/deal/" & dealId & "?hapikey=" & hapikey & "&portalId=" & portalid
    Dim req As WebRequest = WebRequest.Create(url)
    req.Method = "PUT"
    req.ContentType = "application/json"

    Dim update As New DealUpdate
    update.AddProperty("user_type", opportunity.User_type__c)
    Dim json As String = JsonConvert.SerializeObject(update)
    Dim jsonBytes As Byte()
    jsonBytes = System.Text.Encoding.Unicode.GetBytes(json)
    req.ContentLength = jsonBytes.Length

    Dim stream = req.GetRequestStream
    stream.Write(jsonBytes, 0, jsonBytes.Length)
    stream.Close()

    Dim response = req.GetResponse.GetResponseStream
    Dim reader As New StreamReader(response)
    Dim res = reader.ReadToEnd
    reader.Close()
    response.Close()

    Console.Write(res)
End Sub

{"properties":[{"name":"user_type","value":"T1"}]}

#2

Hi @James_Meyer

Are you able to log the body of that error response? There should be more details in the message in that response body.