I get this error:
Uncaught Error: Class 'HubSpot\Client\Crm\Products\Model\PublicAssociationsForObject' not found
I copied this code from docs, but I edited some of it:
use \HubSpot\Factory;
use \HubSpot\Client\Crm\Products\ApiException;
use \HubSpot\Client\Crm\Products\Model\AssociationSpec;
use \HubSpot\Client\Crm\Products\Model\PublicAssociationsForObject;
use \HubSpot\Client\Crm\Associations\Model\PublicObjectId;
use \HubSpot\Client\Crm\Products\Model\SimplePublicObjectInputForCreate;
$hubspot = Factory::createWithAccessToken('pat-eu1-14f14ddd-8a5c-4eb3-b1f1-b13f1d36fb46');
$properties1 = [
'description' => 'Onboarding service for data product',
'hs_cost_of_goods_sold' => '600.00',
'hs_recurring_billing_period' => '12',
'hs_sku' => '191902',
'name' => 'Implementation Service ',
'price' => '6000.00'
];
$to1 = new PublicObjectId([
'id' => '101'
]);
$associationSpec1 = new AssociationSpec([
'association_category' => 'HUBSPOT_DEFINED',
'association_type_id' => 2
]);
$publicAssociationsForObject1 = new PublicAssociationsForObject([
'to' => $to1,
'types' => [$associationSpec1]
]);
$simplePublicObjectInputForCreate = new SimplePublicObjectInputForCreate([
'properties' => $properties1,
'associations' => [$publicAssociationsForObject1],
]);
try {
$apiResponse = $hubspot->crm()->products()->basicApi()->create($simplePublicObjectInputForCreate);
var_dump($apiResponse);
} catch (ApiException $e) {
echo "Exception when calling basic_api->create: ", $e->getMessage();
}
Please help
Hey, @mrabdennour Thanks for reaching out! I have a few clarifying questions, and I’d like to invite some of our community members to the conversation.
Questions:
Can you clarify your goal, please?
Is it to create a Product and associate the Product to an existing Contact?
Or are you attempting to create a Line Item from a Product and then associate it to an exiting Object, a Contact for example?
Hey, @skimura @tominal , do you have PHP-specific tips you can share with @mrabdennour ?
Thank you very much! — Jaycee
I have products in my website database, but I need to assosiate them with my contacts, how to do that?
@mrabdennour
Hi.
I think the direct cause is that ‘PublicAssociationsForObject’ is not included in the hubspot SDK.
I use ‘hubspot/api-client’ 9.4, but it not include class ‘PublicAssociationsForObject’.
→ ‘master branch’ has that class, but ‘9.4.0’ not include.
(check with ‘composer install’ and ‘direct download’)
→‘10.0.0-beta’ has that class.
git
<?php
/**
* PublicAssociationsForObject
*
* PHP version 8.1
*
* @category Class
* @package HubSpot\Client\Crm\Products
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
/**
* Products
*
* CRM objects such as companies, contacts, deals, line items, products, tickets, and quotes are standard objects in HubSpot’s CRM. These core building blocks support custom properties, store critical information, and play a central role in the HubSpot application. ## Supported Object Types This API provides access to collections of CRM objects, which return a map of property names to values. Each object type has its own set of default properties, which can be found by exploring the [CRM Object Properties API](https://developers.hubspot.com/docs/methods/crm-properties/crm-properties-overview). |Object Type |Properties returned by default | |--|--| | `companies` | `name`, `domain` | | `contacts` | `firstname`, `lastname`, `email` | | `deals` | `dealname`, `amount`, `closedate`, `pipeline`, `dealstage` | | `products` | `name`, `description`, `price` | | `tickets` | `content`, `hs_pipeline`, `hs_pipeline_stage`, `hs_ticket_category`, `hs_ticket_priority`, `subject` | Find a list of all properties for an object type using the [CRM Object Properties](https://developers.hubspot.com/docs/methods/crm-properties/get-properties) API. e.g. `GET https://api.hubapi.com/properties/v2/companies/properties`. Change the properties returned in the response using the `properties` array in the request body.
*
* The version of the OpenAPI document: v3
* Generated by: https://openapi-generator.tech
* Generator version: 7.19.0
This file has been truncated. show original
download with ( 9.4.0 )
If you want use this class, your should use ‘10.0.0-beta’.
Or you want to use stable version ( ex, 9.4.0 ),
how about this? (Not tested. )
* I don’t know ‘products’ can associate with ‘contacts’.
$hubspot = Factory::createWithAccessToken('...');
$properties1 = [
'description' => 'Onboarding service for data product',
'hs_cost_of_goods_sold' => '600.00',
'hs_recurring_billing_period' => '12',
'hs_sku' => '191902',
'name' => 'Implementation Service ',
'price' => '6000.00'
];
$toObjectType = '...';
$toObjectId = '101';
$associationTypeId = 2;
$simplePublicObject = new SimplePublicObjectInput();
$simplePublicObject->setProperties($properties1);
try {
$productCreateApiResponse = $hubspot->crm()->products()->basicApi()->create($simplePublicObject);
$productId = $apiResponse->getId();
$productAssocitaionCreateApiResponse = $hubspot->crm()->products()->associationsApi()->create(
$productId,
$toObjectType,
$toObjectId,
$associationTypeId,
);
var_dump($$productCreateApiResponse);
var_dump($productAssocitaionCreateApiResponse);
} catch (ApiException $e) {
echo "Exception when calling basic_api->create: ", $e->getMessage();
}
Thanks.
@Jaycee_Lewis
Thank you for mention.