Error via API when creating a Deal

Hi,

We’re using HubSpot’s V3 API to create a deal, but hit a strange error when we do it via Code.

We target this URI: (POST) https://api.hubapi.com/crm/v3/objects/deals (and yes, we pass the hapikey

This is the payload we send:

{
 "properties": {
 "dealname": "Test2",
 "pipeline": "{A GUID HERE}",
 "dealstage": "{A GUID HERE}",
 "createdate": "2021-08-07T16:50:06.678Z",
 "closedate": "2022-12-07T16:50:06.678Z",
 "lead_obtained": null,
 "dealtype": "New Site",
 "hubspot_owner_id": null,
 "number_of_users": null,
 "deal_currency_code": null,
 "region": "Africa",
 "account_managed_by": null,
 "amount": "999.00"
 }
}

We use a C# nuget package called flURL for all of our requests to Hubspot, and they all work fine, however we’re not sure why we keep hitting this strange error. From what I gather, it seems like HubSpot cannot deserialize the data we’re sending them.

This is the error received when we make the request via code:

Invalid input JSON on line 1, column 1: Cannot construct instance of `com.hubspot.inbounddb.publicobject.core.v2.SimplePublicObjectInput$Json` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('
{
 "properties": {
 "dealname": "Test2",
 "pipeline": "{A GUID HERE}",
 "dealstage": "{A GUID HERE}",
 "createdate": "2021-08-07T16:50:06.678Z",
 "closedate": "2022-12-07T16:50:06.678Z",
 "lead_obtained": null,
 "dealtype": "New Site",
 "hubspot_owner_id": null,
 "number_of_users": null,
 "deal_currency_code": null,
 "account_managed_by": null,
 "amount": "999.00"
 }
}')

However, when we post this via Postman, it works as expected, even though they requests and payloads look identical.

If you take a look at the payload returned in the error, you’ll note that it looks identical to what we send.

Do you have any insight as to why we could be seeing this error?

Thank you.

@gotmike , any thoughts on this issue?

i’m not familiar with flURL.

but i’d try a native call to see if u run into the same issue.

also, i see in the response there’s a `v2` but u say ur using the `v3` api. are u sure ur hitting the same endpoints?

Hi @gotmike,

Thank you for your response.

Since I was able to demonstrate a successful call via RestSharp (C# REST Client), I’m confident that the payload and parameters we’re sending is correct. I’ve also confirmed that our versioning is onpoint, using v3. Why we’re being sent an error message that includes info about v2 is beyond me.

Hi @RBotha-sp ,
Please try this below code and source property is read only, so you can’t create and update this property.
˂?php
$post_json = ‘{
“associations”: {
“associatedCompanyIds”: [
8954037
],
“associatedVids”: [
27136
]
},
“properties”: [
{
“value”: “Tim’s Newer Deal”,
“name”: “dealname”
},
{
“value”: “appointmentscheduled”,
“name”: “dealstage”
},
{
“value”: “default”,
“name”: “pipeline”
},
{
“value”: “24”,
“name”: “hubspot_owner_id”
},
{
“value”: 1409443200000,
“name”: “closedate”
},
{
“value”: “60000”,
“name”: “amount”
},
{
“value”: “newbusiness”,
“name”: “dealtype”
}
]
}’;
$hapikey = “demo”;
$endpoint = ‘https://api.hubapi.com/deals/v1/deal?hapikey=’ . $hapikey;
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $post_json);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/json’));
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch);
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errors = curl_error($ch);
@curl_close($ch);
echo "curl Errors: " . $curl_errors;
echo "\nStatus code: " . $status_code;
echo "\nResponse: " . $response;
?>

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regards.

Hi @webdew

Thank you for your response.
I looks like your code uses the v1 implementation of the specific API. We’re deprecating as much of HubSpot’s v1 API as we can at this stage, but I’m sure that would work.

About 99% of all our calls to the HubSpot API run through flURL and works brilliantly and as expected. We’re just being sent this strange error when we use v3 correctly (as far as 2 different devs can see).

As expected, the fault was on our side.

I want to leave this here for anyone else experiencing the same error - so they know for sure it is the data being sent and not HubSpot.

From the error, it can be understood that HubSpot is trying to deserialize the string into an object, but fails to do so. Now, even though (in our case) the JSON looks perfect when inspected. Which makes it easy for one to reason “the payload looks just fine”.

However, in the use case of flURL, when you send in an already serialized object, make sure you don’t RE-serialize it. Visual Studio will show that it “looks” fine when inspected, however, simply making sure of the above sorted our issue out.