nmarus / node-ews

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

How to add exchange version in header #19

Closed omerson closed 8 years ago

omerson commented 8 years ago

How to add exchange version into request header

For example:

RequestServerVersion: {
    attributes: {
        Version: "Exchange2013"
    }
}
nmarus commented 8 years ago

I'll preface this with I haven't tested this across multiple versions of exchange, so ymmv. But... the way I understand SOAP and the way node-ews is written, you should not need this as long as the WSDL file is being downloaded from the EWS API of the server you are connecting to.

node-ews automatically downloads the WSDL and XSD files when attempting to connect connect to the specific EWS API the first time. This exposes all the SOAP functions for that specific version of Exchange and you need to only pass items that would be in the SOAP body. See my comments in #18 on this and how to take a EWS SOAP query to a node-ews JSON query as well as the examples at the bottom of the README that were added in the last few days and see if that works. It seems to be a bit buggy in older version of exchange in the way Microsoft formats the WSDL file as noted in #18.

kcastrotech commented 8 years ago

Some EWS operations do require the server version to be set in the header such as ConvertId (https://msdn.microsoft.com/en-us/library/office/bb799665(v=exchg.150).aspx) and unless there is a way to pass the headers through node-ews that I'm missing, then the way I am currently using is to add:

          client.addSoapHeader({'t:RequestServerVersion': {
            attributes: {
                Version: "Exchange2013"
            }
          }});

To the ews.js file in the run function just after it defines the security plugin so it looks like this:

          // define security plugin
          client.setSecurity(authProfile);
          client.addSoapHeader({'t:RequestServerVersion': {
            attributes: {
                Version: "Exchange2013"
            }
          }});

          // run ews soap function
          client[ewsFunction](ewsArgs, (err, result) => {
            if(err) reject(err);
            else resolve(result);
          });
nmarus commented 8 years ago

This ability has been added to 2.1.4. README.md updated to show example under "Advanced".