💬 RevOps Discussions

PMcConnell
Member | Platinum Partner
Member | Platinum Partner

Create line items with associations in Workflows

SOLVE

Hi all, 

I am running into a strange problem and hoping someone can shed some light on it. 

I am trying to create a line item using Workflows.  This line item is to have an assocation to a deal. 
Below is a copy of my code with my parameters scrubbed. 

 

 const properties = {
  "name": "test name",
  "hs_product_id": product_id,
  "quantity": "1",
  "price": "100.00"
};
const SimplePublicObjectInputForCreate = { properties, associations: [{"to":{"id": deal_id},"types":[{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":20}]}] };

try {
  const apiResponse = await hubspotClient.crm.lineItems.basicApi.create(SimplePublicObjectInputForCreate);
  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)
}
  

 


I can run this code through the endpoints on the hubspot docs pages and it all works fine.  However, when running it in workflows, the line item gets created but not associated. 

I know the work around is just to run the associations api afterwards but I am wondering if I am using the line items api incorrectly. 

Any help is greatly appreciated.

Thanks,
Pauric

0 Upvotes
1 Accepted solution
JBeatty
Solution
Guide | Diamond Partner
Guide | Diamond Partner

Create line items with associations in Workflows

SOLVE

Hi @PMcConnell,

 

This looks like an error with the HubSpot API client, looking at the logs for the token the client simply isnt sending the associations portion of the body:

JBeatty_0-1685978349297.png

I would recommend using axios as a work around, that way it stays as a single api call, you could do that by doing the following:

const axios = require('axios').default;
exports.main = async (event, callback) => {
    const client = axios.create({
        baseURL: 'https://api.hubapi.com',
        headers: {
            accept: 'application/json',
            Authorization: `Bearer ${process.env.APPTOKEN}`
        }
    });

    const properties = {
        "name": "test name",
        "hs_product_id": 1579739513,
        "quantity": "1",
        "price": "100.00"
    };
    await client.post(`/crm/v3/objects/line_items`, 
        { properties, associations: [{ "to": { "id": event.object.objectId }, "types": [{ "associationCategory": "HUBSPOT_DEFINED", "associationTypeId": 20 }] }] });

}


Best,

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Joshua Beatty
Software Developer with Pearagon

Still have questions? Let's Talk

View solution in original post

2 Replies 2
JBeatty
Solution
Guide | Diamond Partner
Guide | Diamond Partner

Create line items with associations in Workflows

SOLVE

Hi @PMcConnell,

 

This looks like an error with the HubSpot API client, looking at the logs for the token the client simply isnt sending the associations portion of the body:

JBeatty_0-1685978349297.png

I would recommend using axios as a work around, that way it stays as a single api call, you could do that by doing the following:

const axios = require('axios').default;
exports.main = async (event, callback) => {
    const client = axios.create({
        baseURL: 'https://api.hubapi.com',
        headers: {
            accept: 'application/json',
            Authorization: `Bearer ${process.env.APPTOKEN}`
        }
    });

    const properties = {
        "name": "test name",
        "hs_product_id": 1579739513,
        "quantity": "1",
        "price": "100.00"
    };
    await client.post(`/crm/v3/objects/line_items`, 
        { properties, associations: [{ "to": { "id": event.object.objectId }, "types": [{ "associationCategory": "HUBSPOT_DEFINED", "associationTypeId": 20 }] }] });

}


Best,

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Joshua Beatty
Software Developer with Pearagon

Still have questions? Let's Talk

kvlschaefer
Community Manager
Community Manager

Create line items with associations in Workflows

SOLVE

Hi @PMcConnell,

 

Thanks for reaching out to the Community!

 

I wanted to invite our subject matter experts to see if they have insight.

Hi @louischausse@JBeatty@ChrisoKlepke - Do you have any advice for @PMcConnell?

Thank you!

 

Best,

Kristen


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !
0 Upvotes