Skip to main content

Hi all,

 

i have this api request for my action

 

const options = {
  url: 'my-ap-urli',
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Cookie': `JSESSIONID=${bundle.authData.sessionKey}`
  },
  params: {
  },
  body:{
    "items": Â{
          "properties": {
          "Contact.name": bundle.inputData.contactName,
          "Contact.surname": bundle.inputData.contactLastName,
          "Contact.email": bundle.inputData.contactEmail
          }
        }]
  }
}

 

what I need is to add the dynamic fields that are present in the bundle input data.

How can I add the input data in my properties formatted in this way?

"Contact.key": value

Thanks

 

I think you could do it like this if understand your request correctly:

const contactProperties = Object.keys(bundle.inputData)
.filter(key => key.toLowerCase().startsWith('contact'))
.reduce((obj, key) => {
obj[key] = bundle.inputData[key];
return obj;
}, {});


let properties = {}
for (let [key, value] of Object.entries(contactProperties)) {
properties['Contact.' + key.replace(/[a-z]*([A-Z]{1}[a-z]*)/g, "$1")] = value
}

 

then assign body.items.properties = properties