HubSpot / hubspot-api-php

HubSpot API PHP Client Libraries for V3 version of the API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Association between companies 1:many

criszacca opened this issue · comments

Hey guys, I'm trying to create a relationship between companies when one company will have many other companies.

I'm trying to do using this structure:

$spec = new HubSpot\Client\Crm\Companies\Model\AssociationSpec([
      'association_category' => 'HUBSPOT_DEFINED',
      'association_type_id' => '14'
  ]);

$hubspot->crm()->companies()->associationsApi()->create($this->getWLId($currentWl), 'company', $currentCustomer['id'], [$spec]);


I'm not receiving any error but when I check into the HubSpot panel only the last company still with the related information.

I'm using SDK version 9.4.0.

What I'm missing?

If someone else tries to do that. I was able to create the relation using this code:

 $body = [
            [
                'associationCategory' => 'HUBSPOT_DEFINED',
                'associationTypeId' => 1,
            ]
        ];

          return $hubspot->apiRequest([
              'method' => 'PUT',
              'path' => "/crm/v4/objects/contacts/$userId/associations/company/$companyId",
              'body' => $body,
          ]);
commented

One company to many contacts.
Workable example (9.4.0 version):

use HubSpot\Factory;
use HubSpot\Client\Crm\Associations\V4\Model\AssociationSpec;
use HubSpot\Client\Crm\Associations\V4\Model\BatchInputPublicAssociationMultiPost;
use HubSpot\Client\Crm\Associations\V4\Model\PublicAssociationMultiPost;
use HubSpot\Client\Crm\Associations\V4\Model\PublicObjectId;

$hubspot = Factory::createWithAccessToken('***');

$primaryAssociationType = new AssociationSpec([
    'association_category' => 'HUBSPOT_DEFINED',
    'association_type_id' => 2,
]);

$associationType = new AssociationSpec([
    'association_category' => 'HUBSPOT_DEFINED',
    'association_type_id' => 280,
]);

$input = new BatchInputPublicAssociationMultiPost([
    'inputs' => [
        new PublicAssociationMultiPost([
            'from' => new PublicObjectId(['id' => '9263529601']),
            'to' => new PublicObjectId(['id' => '312553']),
            'types' => [$primaryAssociationType],
        ]),
        new PublicAssociationMultiPost([
            'from' => new PublicObjectId(['id' => '9263529601']),
            'to' => new PublicObjectId(['id' => '309952']),
            'types' => [$associationType],
        ]),
        new PublicAssociationMultiPost([
            'from' => new PublicObjectId(['id' => '9263529601']),
            'to' => new PublicObjectId(['id' => '307907']),
            'types' => [$associationType],
        ]),
    ]
]);

$response = $hubspot->crm()->associations()->v4()->batchApi()->create('companies', 'contacts', $input);