0

Example POST URL (with display properties):

https://api.hubapi.com/crm-objects/v1/objects/line_items/batch-read?hapikey=demo&properties=name&properties=quantity&properties=price

Example POST BODY:

{
  "ids": [
    9845651,
    9867373
  ]
}

Node syntax

var request = require("request-promise");
const { ids } = req.body;

    console.log("ids::", ids);

    const result = await request({
      method: "POST",
      url: `https://api.hubapi.com/crm-objects/v1/objects/line_items/batch-read`,
      qs: {
        hapikey: "demo",
        properties="name"
      },
     
      body: {
        ids,
      },
      json: true,
    });

The problem is, can not set the qs display properties, I need to collect name, quantity, price properties information, how to set them on node syntax? my following syntax not working

 properties=["name","quantity","price"]
shamim
  • 6,640
  • 20
  • 85
  • 151
  • I guess this is wrong `properties="name"`, you have define it inside an object so it must be like `properties: "name"`. Can you check it once? – Ashishssoni Apr 22 '21 at 10:52
  • I need more than one property informations, as I describe on question, I need properties:["name","quantity","price"] – shamim Apr 22 '21 at 10:55
  • I mean will this works? `properties: ["name","quantity","price"]`, you can define equal to (=) in the key and value pairs, you have to define is as `key:value` when defining inside an object. – Ashishssoni Apr 22 '21 at 10:58
  • thanks for the syntax issue, I replace the symbol = with : but it's not working, I don't know why it's not working, base URL work on postman – shamim Apr 22 '21 at 11:01
  • is `properties: "name"` this working? i mean if you send a single property are you getting the response? – Ashishssoni Apr 22 '21 at 11:10
  • Yes, I get the response for the single properties: "name" – shamim Apr 22 '21 at 11:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/231453/discussion-between-red-and-shamim). – Ashishssoni Apr 22 '21 at 11:16

1 Answers1

0

You can do this instead of properties=["name","quantity","price"]

const properties = ['name', 'quantity', 'price']

const qs = ['hapikey=demo&']
properties.forEach((key) => {
  qs.push('properties=' + key + '&')
})
console.log(qs.join(''))
//this gives: hapikey=demo&properties=name&properties=quantity&properties=price&

And later

const result = await request({
  method: 'POST',
  url: `https://api.hubapi.com/crm-objects/v1/objects/line_items/batch-read`,
  qs: `${qs.join('')}`,
  body: { ids },
  json: true,
})

So it will give querystring as hapikey=demo&properties=name&properties=quantity&properties=price

Ashishssoni
  • 729
  • 4
  • 14