APIs & Integrations

JStenbaek
Contributor

Custom code action, create line item on a deal

SOLVE

Hi All 

 

I would like to create a new line item on a deal using the custom code actions in a workflow, I am new to JS.Node but have tried this without any luck, any one that can see what I am doing wrong?

 

var request = require("request");

exports.main = (event,) => {

var options = {
  method: 'POST',
  url: 'https://api.hubapi.com/crm/v3/objects/line_items',
  qs: {hapikey: process.env.APIKEY},
  headers: {accept: 'application/json', 'content-type': 'application/json'},
  body: {
    properties: {
      name: '1 year implementation consultation',
      hs_product_id: '191902',
      quantity: '2',
      price: '6000.00'
    }
     },
  associations: 
        { contactIds: [],
          companyIds: [],
          dealIds: [event.object.objectId],
          ownerIds: [] },
  json: true
};

request(options, function (error, response, body) {
    if (error) throw new Error(error);
      });
}
0 Upvotes
1 Accepted solution
louischausse
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Custom code action, create line item on a deal

SOLVE

@JStenbaek it seems that the callback is missing at line 3:

exports.main = (event, callback) => {

 Also, it seems that in line 13 you are referring to the product id that there is in the sample code in the documentation. Since this product probably doesn't exist in your portal you will probably end up with an error. You need to change this for an actual product id in your HubSpot product library. You can find this in Settings > Products & Quotes:

      hs_product_id: '191902',

Start by fixing this and let me know where it leads you and I could keep continue to help you.

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

View solution in original post

6 Replies 6
louischausse
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Custom code action, create line item on a deal

SOLVE

@JStenbaek it seems that the callback is missing at line 3:

exports.main = (event, callback) => {

 Also, it seems that in line 13 you are referring to the product id that there is in the sample code in the documentation. Since this product probably doesn't exist in your portal you will probably end up with an error. You need to change this for an actual product id in your HubSpot product library. You can find this in Settings > Products & Quotes:

      hs_product_id: '191902',

Start by fixing this and let me know where it leads you and I could keep continue to help you.

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

Custom code action, create line item on a deal

SOLVE

Thanks for the help this is the error massage.Screenshot 2021-06-02 at 09.49.23.png

0 Upvotes
louischausse
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Custom code action, create line item on a deal

SOLVE

Hello @JStenbaek,

 

On line 3 you have a red alert, what does it have to say?

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

Custom code action, create line item on a deal

SOLVE

 

No Error massage! but the line item is not created on the deal

Screenshot 2021-06-01 at 21.10.08.pngScreenshot 2021-06-01 at 21.09.14.pngScreenshot 2021-06-01 at 21.09.05.pngScreenshot 2021-06-01 at 21.08.46.png

0 Upvotes
louischausse
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Custom code action, create line item on a deal

SOLVE

@JStenbaek happy to help

 

yes if you can share the error or any other output that would help.

 

Please send also a screenshot of your configuration of the custom code action in your workflow

Thanks

Louis Chaussé from Auxilio HubSpot Solutions Partner Signature
Louis Chaussé from Auxilio HubSpot Solutions Partner Meeting link
dennisedson
HubSpot Product Team
HubSpot Product Team

Custom code action, create line item on a deal

SOLVE

@JStenbaek ,

Are you receiving any errors?

@louischausse might be able to help as I believe he works with node 😀

0 Upvotes