APIs & Integrations

louischausse
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Adding a property to a property group that you just create using HubSpot API and Node.js

SOLVE

Hey ​! I'm creating a property group and properties to nest in it using API and I got the error "Property group doesn't exist" when trying to create the first property as, in fact, I just created it within the same program. Does HubSpot API need a delay or something between the creation of a group and the time we can post properties in it?

 

Here's the code:

 

//=================================================================//
//   Creating properties required for the integration   //
//=================================================================//

// Creating the property group

const createGroup = async (accessToken) => {
  console.log('Creating a property group to nest all the properties required to integrate  to HubSpot');

const headers = {
  Authorization: `Bearer ${accessToken}`,
  'Content-Type': 'application/json'
};

const propertyGroup = {
  headers: headers,
  method: 'POST',
  uri: 'https://api.hubapi.com/properties/v1/contacts/groups',
  body: {
      name: 'name',
      displayName: 'This is the name'
  },
  json: true // Automatically stringifies the body to JSON
};

request(propertyGroup)
  .then(function (parsedBody) {
    console.log(parsedBody);
  })
  .catch(function (err) {
     console.log(err);
  });
};

// Creating the properties

const createProperty = async (accessToken) => {
  console.log('Creating a property');

const headers = {
  Authorization: `Bearer ${accessToken}`,
  'Content-Type': 'application/json'
};

const program = {
  headers: headers,
  method: 'POST',
  uri: 'https://api.hubapi.com/properties/v1/contacts/properties',
  body: {
      name: 'programs',
      label: 'Programs',
      description: 'programs in which the contact is enrolled',
      groupName: 'name',
      type: 'enumeration',
      fieldType:'select',
      options: ['french', 'english']
  },
  json: true // Automatically stringifies the body to JSON
};

request(program)
  .then(function (parsedBody) {
    console.log(parsedBody);
  })
  .catch(function (err) {
     console.log(err);
  });
};
Louis Chaussé from Auxilio HubSpot Solutions Partner Signature
Louis Chaussé from Auxilio HubSpot Solutions Partner Meeting link
1 Accepted solution
louischausse
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Adding a property to a property group that you just create using HubSpot API and Node.js

SOLVE

I tried to add a delay and it helps.

 

If you use node.js like me you should use the delay module. It worked just fine for me

 

https://www.npmjs.com/package/delay

Louis Chaussé from Auxilio HubSpot Solutions Partner Signature
Louis Chaussé from Auxilio HubSpot Solutions Partner Meeting link

View solution in original post

1 Reply 1
louischausse
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Adding a property to a property group that you just create using HubSpot API and Node.js

SOLVE

I tried to add a delay and it helps.

 

If you use node.js like me you should use the delay module. It worked just fine for me

 

https://www.npmjs.com/package/delay

Louis Chaussé from Auxilio HubSpot Solutions Partner Signature
Louis Chaussé from Auxilio HubSpot Solutions Partner Meeting link