Association API magically comes up with wrong type

Once again baffling behavior which I’ve given up to find any reasonable explanation for… So I try to set an assocation from a company to another company with my own label. I’ve written some e2e tests, that confirm that this also works based on fresh test fixtures. However working with pre-existing companies this is the result when trying to create the association:

{"status":"error","message":"One or more associations are invalid","correlationId":"xxx (truncated...) ""","exceptionLine" => 458,"exceptionBody" => "{"status":"error","message":"One or more associations are invalid","correlationId":"xxx","context":{"INVALID_OBJECT_IDS":["2-123456=45678 is not valid"],"objectId":["45678"],"objectType":["2-123456"]}

2-123456 is the ID of a custom object. Note that it is NOT the type any of the both sides I want to set the association for. I have absolutely no idea how it comes up with that type here… The id 45678 is definetely the valid ID of a company…
For reference, here is the code where I try to set the association:

$associationSpec = new AssociationSpec( [ 'association_category' => 'USER_DEFINED', 'association_type_id' => $this->partnerCustomerCompanyAssociationId ]);$this->hubspotApiFactory->getAssociationBasicApi()->create( 'companies', $hubspotPartnerCompanyId, 'companies', $hubspotCustomerCompanyId, [$associationSpec]);

I believe the association ID you’re trying to use here:

$this->partnerCustomerCompanyAssociationId

is referring to a different association label, namely one between a company and a custom object. Because that error is what you receive when you put in an ID that doesn’t match the pairing you’ve selected in your objectType / toObjectType. I don’t know how you set it, but that’s where I’d look for the answer to this.

To confirm, I tried this in the HubSpot API documentation. 1) I selected contact to contact pairing with 2 random contact IDs. 2) I purposefully set the associationTypeId to one that’s used by a contact-to-custom object ID. Then 3) I get the same error you do, which refers to the CO ID that the pairing actually belongs to. See the screenshot below.

What does strike me as odd is that your CO ID that’s returned is exactly 2-123456. Makes me think like you’ve stumbled upon some internal Association ID used by HubSpot to refer to some dummy or reserved CO, that has the ID 123456?

Thanks for the answer but unfortunately that’s not it. I double checked the label. Also, weirdly enough, creating the association using the batch API and the same parameters works with pre-existing companies:

$this->hubspotApiFactory->getAssociationBatchApi()->create( 'company', 'company', new BatchInputPublicAssociationMultiPost([ 'inputs' => [ [ 'types' => [ [ 'associationCategory' => 'USER_DEFINED', 'associationTypeId' => $this->partnerCustomerCompanyAssociationId, ], ], 'from' => [ 'id' => $hubspotPartnerCompanyId, ], 'to' => [ 'id' => $hubspotCustomerCompanyId, ], ], ], ]));

I strongly suscpect a bug on Hubspots side. I’m just going to try and use the batch api to create single associations for now.

Update: I actually found that the ids for the labels were mixed up on staging, so it seems your explanation is very likely correct. Thanks for the hint!