Deals values need to be inside 'properties' array
The deal properties need to be inside the 'properties' array when creating/updating the deals, otherwise, we get an error from Hubspot:
$options['json'] = ['properties' => $deal];
Changes in two functions below in "hubspot-php/src/Resources/Deals.php" fixes this as said above.
` function create(array $deal) { $endpoint = "https://api.hubapi.com/deals/v1/deal"; $options['json'] = ['properties' => $deal]; return $this->client->request('post', $endpoint, $options); }
function update($id, array $deal)
{
$endpoint = "https://api.hubapi.com/deals/v1/deal/{$id}";
$options['json'] = ['properties' => $deal];
return $this->client->request('put', $endpoint, $options);
}
`
You can pass it into the function like that.
That's how it is documented in the API docs at hubspot:
- https://developers.hubspot.com/docs/methods/deals/create_deal
- https://developers.hubspot.com/docs/methods/deals/update_deal
That is somewhat incorrect @ryanwinchester. yes you could pass in the array like below. It requires an overall properties value with the json request in it like below. This is the only way I could get it to work (notice double properties):
[
'properties' => {
"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"
}
]
}
]
Same here. I was getting errors as well without the properties index. I forked the repo and added this fix, and things worked:

You're saying this won't work?
- Create: https://github.com/ryanwinchester/hubspot-php/blob/master/tests/integration/Resources/DealsTest.php#L31
- Update: https://github.com/ryanwinchester/hubspot-php/blob/master/tests/integration/Resources/DealsTest.php#L103
@ryanwinchester The documentation on the Hubspot API for creating deals, specifically, was very bad up until last month. The doc showed that, when creating a deal, all you would be able to pass was the fields and values, like you would for a Contact.
So, developers would assume that the SDK's API would add that array inside the 'properties' array when sending to Hubspot like we would for creating Contacts and Companies. And that's what I assumed as well. Consequently, I kept getting an error because my fields and values were not inside the 'properties' array, which I was expecting the SDK to do.
We weren't aware that we could pass in the associations as well in that call (associating a deal with a contact etc.). So, you're right, the SDK is fine, Hubspot just needed to update their documentation, which they have done now and when we would have to pass in the values inside the 'properties' array.