Skip to main content
Best answer

passing inputdata to an action formatting the output

  • March 16, 2023
  • 1 reply
  • 56 views

ado2000

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

 

Best answer by Benjamin da Silva Moreira

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

View original
Did this topic help you find an answer to your question?
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

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