Issues with CRM API V4 documentation for batch association deletion endpoint

I noticed two issues with the documentation for the CRM API (V4) endpoint /crm/v4/associations/{fromObjectType}/{toObjectType}/batch/archive.

When I send test API requests in-browser via the interactive documentation interface it works, but the Node.js code generated has multiple issues when migrated to a local Node environment.

Issue 1

The Node.js code generated by the interactive docs contains an invalid, undefined reference on the Hubspot API client object. In particular, this line of code throws the error visible here. By removing .batch.read from this line of code, the error is resolved. So the correct line reads

const apiResponse = await hubspotClient.crm.associations.batchApi.archive(fromObjectType, toObjectType, BatchInputPublicAssociationMultiArchive);

Issue 2

After resolving issue 1, running the code returns an error from the API that reads Invalid input JSON on line 1, column 19. Some required fields were not set: [id] (full error here). Since this input was generated by the docs and is supposed to be its own “source of truth,” it’s difficult for me to determine what exactly is wrong with it. It appears that the input data structure expected by the API endpoint does not match the input data structure generated by the interactive docs (visible here in the variable BatchInputPublicAssociationMultiArchive).

Steps to reproduce:

  1. Create a sample API request via the interactive docs for the endpoint /crm/v4/associations/{fromObjectType}/{toObjectType}/batch/archive
  2. Copy and paste the Node.js code generated on the right-hand side to a local JS script in a Node.js environment
  3. Modify the code wrapping it in an async function and ensuring that theHubspot app token/object reference IDs are correct
  4. Ensure the latest version of the Hubspot API client Node package is installed
  5. Run script

For reference, here is my local Node.js code:

const hubspot = require('@hubspot/api-client');
const hubspotClient = new hubspot.Client({
 "accessToken": "OBSCURED_FOR_SECURITY"
});

main();

async function main() {
 const BatchInputPublicAssociationMultiArchive = { inputs: [{"_from":{"id":"80424"},"to":[{"id":"16022770563"}]}] };
 const fromObjectType = "contacts";
 const toObjectType = "companies";

 try {
 const apiResponse = await hubspotClient.crm.associations.batchApi.archive(fromObjectType, toObjectType, BatchInputPublicAssociationMultiArchive);

 console.log(JSON.stringify(apiResponse, null, 2));
 } catch (e) {
 e.message === 'HTTP request failed'
 ? console.error(JSON.stringify(e.response, null, 2))
 : console.error(e)
 }
}

Hello @BradySheridan
1
The Node.js code generated by the interactive docs does indeed contain an invalid reference to the .batch.read method. This method does not exist on the hubspotClient.crm.associations.batchApi object, so the code will not work as expected. The correct line of code should be:

const apiResponse = await hubspotClient.crm.associations.batchApi.archive(fromObjectType, toObjectType, BatchInputPublicAssociationMultiArchive);

The input data structure generated by the interactive docs is missing the id field for the _from object. This field is required by the API endpoint, so the request will fail if it is not present. The correct input data structure should be:

{
 "inputs": [
 {
 "_from": {
 "id": "80424"
 },
 "to": [
 {
 "id": "16022770563"
 }
 ]
 }
 ]
}

update your code with this corrected data structure for the BatchInputPublicAssociationMultiArchive object.

It looks like the Node.js code in the documentation of endpoint /crm/v4/associations/{fromObjectType}/{toObjectType}/batch/archive has been updated since this post was created.

See the code as of 6/20/2023:

And the code as of 6/22/2023:

Using

const apiResponse = await hubspotClient.crm.associations.v4.batchApi.archive(fromObjectType, toObjectType, BatchInputPublicAssociationMultiArchive);

with the automatically generated input structure

const BatchInputPublicAssociationMultiArchive = {
 "inputs": [
 {
 "_from": {
 "id": "81729"
 },
 "to": [
 {
 "id": "16004868498"
 }
 ]
 }
 ]
 };

works as expected.

Marking as resolved!