Best answer

passing inputdata to an action formatting the output

  • 16 March 2023
  • 1 reply
  • 33 views

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

 

icon

Best answer by Benjamin da Silva Moreira 17 March 2023, 16:14

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Userlevel 1

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