nmarus / node-ews

A simple JSON wrapper for the Exchange Web Services (EWS) SOAP API.
MIT License
116 stars 52 forks source link

Multiple Tags of identical name to JSON-Conversion #65

Closed relief-melone closed 7 years ago

relief-melone commented 7 years ago

In the soap-Request for example if you do a findItem Request and specify your ItemShape your markup will look like this

IdOnly

So if you convert this to a json, it will not work, as you will specify the value FieldURI 3 times. Is there already a solution to this? I managed to name one key "t:FieldURI" and the other one "FieldURI" which will at least allow me to specify two Additional Properties. Would be great if you could help.

Greetings Chris

kcastrotech commented 7 years ago

The trick with node-soap (and therefore node-ews) is to make the value of the item you need multiple of an array.

Example from #47:

ToRecipients:{
        Mailbox:[
          {EmailAddress: "address1@example.com"},
          {EmailAddress: "address2@example.com"}
        ]
}

Note how the "Mailbox" has the array as this will create multiple "Mailbox" elements inside "ToRecipients" which is what we want. The resulting XML structure should look something like this:

<ToRecipients>
   <Mailbox>
      <EmailAddress>address1@example.com<EmailAddress/>
   </Mailbox>
   <Mailbox>
      <EmailAddress>address2@example.com<EmailAddress/>
   </Mailbox>
</ToRecipients>
kcastrotech commented 7 years ago

Issue #24 has some examples more specific to what you are asking:

'AdditionalProperties': {
    'FieldURI': [
        { 'attributes': { 'FieldURI': 'item:Subject'}},
        { 'attributes': { 'FieldURI': 'calendar:Start'}},
        { 'attributes': { 'FieldURI': 'calendar:End'}}
    ]
}
relief-melone commented 7 years ago

Thanks. That issue was ectually exactly what i was looking for. Just didn't sound like my problem when I browsed through the topics earlier.