MoveItem Invalid Request - javascript

I'm trying to delete an item using the EWS MoveItem XML request. I'm sending this request to the makeEwsRequestAsync function:
function getMoveItemRequest(id, changeKey) {
var result =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">' +
'<soap:Header>' +
'<RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
'</soap:Header>' +
'<soap:Body>' +
'<MoveItem xmlns="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">' +
'<ToFolderId>' +
'<t:DistinguishedFolderId Id="deleteditems" />' +
'</ToFolderId>' +
'<ItemIds>' +
'<t:ItemId Id="' + id + '" ChangeKey="' + changeKey + '" />' +
'</ItemIds>' +
'</MoveItem>' +
'</soap:Body>' +
'</soap:Envelope>';
return result;
}
I'm getting the item id from the message like this:
Office.context.mailbox.item.itemId
I'm getting changekey like this:
var mailbox = Office.context.mailbox;
var soapToGetItemData = getItemDataRequest(mailbox.item.itemId);
Office.context.mailbox.makeEwsRequestAsync(soapToGetItemData, function(result) {
var response = $.parseXML(result.value);
var responseString = result.value;
// TODO: May want to reconsider the logic for getting the ChangeKey
var indexOfChangeKey = responseString.indexOf("ChangeKey=\"");
var substringAfterChangeKey = responseString.substring(indexOfChangeKey + 11);
var indexOfQuotes = substringAfterChangeKey.indexOf("\"");
var changeKey = substringAfterChangeKey.substring(0, indexOfQuotes);
Here is the getItemDataRequest function:
function getItemDataRequest(itemId) {
var soapToGetItemData = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"' +
' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <soap:Header>' +
' <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
' </soap:Header>' +
' <soap:Body>' +
' <GetItem' +
' xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"' +
' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <ItemShape>' +
' <t:BaseShape>IdOnly</t:BaseShape>' +
' <t:AdditionalProperties>' +
' <t:FieldURI FieldURI="item:Attachments" /> ' +
' </t:AdditionalProperties> ' +
' </ItemShape>' +
' <ItemIds>' +
' <t:ItemId Id="' + itemId + '"/>' +
' </ItemIds>' +
' </GetItem>' +
' </soap:Body>' +
'</soap:Envelope>';
return soapToGetItemData;
}
Yet, I'm getting an invalid response from this (the XML that is returned has "<faultstring xml:lang="en-US">The request is invalid." in it.)
Any ideas what's going on?
Thanks!

Needed to use http instead of https in the request.
function getMoveItemRequest(id, changeKey) {
var result =
'<?xml version="1.0" encoding="utf-8"?> ' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' +
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> ' +
'<soap:Header> ' +
'<t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" /> ' +
'</soap:Header> ' +
'<soap:Body> ' +
'<MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" ' +
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> ' +
'<ToFolderId> ' +
'<t:DistinguishedFolderId Id="deleteditems"/> ' +
'</ToFolderId> ' +
'<ItemIds> ' +
'<t:ItemId Id="' + id + '" ChangeKey="' + changeKey + '"/> ' +
'</ItemIds> ' +
'</MoveItem> ' +
'</soap:Body> ' +
'</soap:Envelope> ';
return result;
}

Related

Format Dynamic Generated XML for Axios

Axios returning binary data instead of XML
Hey all, I asked this question earlier and got further with my research into what its doing. however I am having a issue with Axios in particular in sending out a dynamicly generated XML response.
The XML request I am generating is essentially this:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://projectorpsa.com/DataContracts/Shared/Common/"
xmlns:pws="http://projectorpsa.com/PwsProjectorServices/" xmlns:req="http://projectorpsa.com/DataContracts/Requests/" xmlns:sch="http://projectorpsa.com/DataContracts/Shared/Scheduling/">
<soapenv:Header />
<soapenv:Body>
<pws:PwsGetProject>
<pws:serviceRequest>
<req:SessionTicket>BZZ=</req:SessionTicket>
<sch:Mode>R</sch:Mode>
<sch:ProjectIdentities>
<com:PwsProjectRef><com:ProjectCode>201268</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>201268</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-01</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-02</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-03</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-04</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-05</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-06</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-07</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-01</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-02</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-03</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-04</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-05</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-06</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-07</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-08</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-09</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-10</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103103</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103110-01</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103110-02</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103110-03</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-01</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-02</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-03</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-04</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-05</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-06</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-07</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-08</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-09</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-10</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210966</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-01</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-02</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-03</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-04</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-05</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-06</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-07</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2201146</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>ARCH - 3708608015</com:ProjectCode></com:PwsProjectRef>
</sch:ProjectIdentities>
</pws:serviceRequest>
</pws:PwsGetProject>
</soapenv:Body>
</soapenv:Envelope>
which I generate through a for Loop:
//xmlCode Example: XMLCode: `<com:PwsProjectRef><com:ProjectCode>${e.ProjectCode[0]}</com:ProjectCode></com:PwsProjectRef>`
for(let i = 0; i < idArray.length; i++){
if (i === 0){
genXML = idArray[i].XMLCode + "\n";
}
if (i === idArray.length - 1){
genXML = genXML + " " + idArray[i].XMLCode;
}
else{
genXML = genXML + " " + idArray[i].XMLCode + "\n"
}
}
which Axios is generating as:
data: '<?xml version="1.0" encoding="UTF-8"?>\n' +
' <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://projectorpsa.com/DataContracts/Shared/Common/" \n' +
' xmlns:pws="http://projectorpsa.com/PwsProjectorServices/" xmlns:req="http://projectorpsa.com/DataContracts/Requests/" xmlns:sch="http://projectorpsa.com/DataContracts/Shared/Scheduling/">\n' +
' <soapenv:Header />\n' +
' <soapenv:Body>\n' +
' <pws:PwsGetProject>\n' +
' <pws:serviceRequest>\n' +
' <req:SessionTicket>BZ</req:SessionTicket>\n' +
' <sch:Mode>R</sch:Mode>\n' +
' <sch:ProjectIdentities>\n' +
' <com:PwsProjectRef><com:ProjectCode>201268</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>201268</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210115-01</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210115-02</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210115-03</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210115-04</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210115-05</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210115-06</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210115-07</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-01</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-02</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-03</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-04</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-05</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-06</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-07</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-08</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-09</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-10</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103103</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103110-01</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103110-02</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2103110-03</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210378-01</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210378-02</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210378-03</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210378-04</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210378-05</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210378-06</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210378-07</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210378-08</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210378-09</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210378-10</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>210966</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>211245-01</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>211245-02</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>211245-03</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>211245-04</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>211245-05</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>211245-06</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>211245-07</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2201146</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2201147</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>220340-01</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2205110</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>220967-01</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>220967-02</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>220967-03</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>220967-04</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>220967-05</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>220967-06</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>220991</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>2210125</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>677800-10593</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>677900-10594</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3707607943</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3707682075</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3707736194</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3707756855</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708308023</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708308024</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708324520</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708387896</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708387898</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708398379</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708437324</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708437327</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708437328</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708478136</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708510538</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708510540</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708567478</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708587301</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708608015</com:ProjectCode></com:PwsProjectRef>\n' +
' '... 231 more characters
},
the issue i'm having is that Axios is returning what appears to be hex/binary data back from this call:
data: '\x1F�\b\x00\x00\x00\x00\x00\x04\x00��\x07`\x1CI�%&/m�{\x7FJ�J��t�\b�`\x13$ؐ#\x10������\x1DiG#)�*��eVe]f\x16#�흼��{���{���;�N\'���?\\fd\x01l��J�ɞ!���\x1F?~|\x1F?"\x1E7�N��yY���ݢ\\6���>�����ݻ�t�/�fL�7U�\x1AW��]�r7�7�~tD�?�f�G�_^5���˺��|ھʛU�l\x14�\x05��o�z�d�i��K/�\x1BU�:�/�i�\x00(}\x1E\x00[���z�\r\x03{��
�I�l�l�6w
when I should be getting XML back. However, in that for loop, if I remove the else statement:
for(let i = 0; i < idArray.length; i++){
if (i === 0){
genXML = idArray[i].XMLCode + "\n";
}
if (i === idArray.length - 1){
genXML = genXML + " " + idArray[i].XMLCode;
}
}
which generates:
data: '<?xml version="1.0" encoding="UTF-8"?>\n' +
' <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://projectorpsa.com/DataContracts/Shared/Common/" \n' +
' xmlns:pws="http://projectorpsa.com/PwsProjectorServices/" xmlns:req="http://projectorpsa.com/DataContracts/Requests/" xmlns:sch="http://projectorpsa.com/DataContracts/Shared/Scheduling/">\n' +
' <soapenv:Header />\n' +
' <soapenv:Body>\n' +
' <pws:PwsGetProject>\n' +
' <pws:serviceRequest>\n' +
' <req:SessionTicket>B</req:SessionTicket>\n' +
' <sch:Mode>R</sch:Mode>\n' +
' <sch:ProjectIdentities>\n' +
' <com:PwsProjectRef><com:ProjectCode>201268</com:ProjectCode></com:PwsProjectRef>\n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708608015</com:ProjectCode></com:PwsProjectRef>\n' +
' </sch:ProjectIdentities>\n' +
' </pws:serviceRequest>\n' +
' </pws:PwsGetProject>\n' +
' </soapenv:Body>\n' +
' </soapenv:Envelope>\n'
},
it works perfectly, generating the XML I need back. So I'm presuming my issue is with how that else statement is being formulated. Even though it all appears to look good and well. I'm at a loss as to why axios is doing this. In the above post I mentioned that other libraries are working fine with this, but I can't get Axios to do it. Hoping someone might have a idea!
Thank you for the help!
Can you try this SOAP calculator service?
I test with curl and axios
Axios post program not return with \n.
It can decide your SOAP server issue or axios program issue.
curl demo
curl --location --request POST 'http://www.dneonline.com/calculator.asmx' \
--header 'Content-Type: text/xml; charset=utf-8' \
--header 'SOAPAction: http://tempuri.org/Add' \
--data-raw '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<intA>100</intA>
<intB>100</intB>
</Add>
</soap:Body>
</soap:Envelope>
'
response
$ curl --location --request POST 'http://www.dneonline.com/calculator.asmx' \
> --header 'Content-Type: text/xml; charset=utf-8' \
> --header 'SOAPAction: http://tempuri.org/Add' \
> --data-raw '<?xml version="1.0" encoding="utf-8"?>
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
> <soap:Body>
> <Add xmlns="http://tempuri.org/">
> <intA>100</intA>
> <intB>100</intB>
> </Add>
> </soap:Body>
> </soap:Envelope>
> '
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><AddResponse xmlns="http://tempuri.org/"><AddResult>200</AddResult></AddResponse></soap:Body></soap:Envelope>
axios code
const axios = require("axios");
const getAdd = async () => {
try {
const response = await axios.post(
'http://www.dneonline.com/calculator.asmx',
'<?xml version="1.0" encoding="utf-8"?>\n<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">\n <soap:Body>\n <Add xmlns="http://tempuri.org/">\n <intA>100</intA>\n <intB>100</intB>\n </Add>\n </soap:Body>\n</soap:Envelope>\n',
{
headers: {
'Content-Type': 'text/xml; charset=utf-8',
'SOAPAction': 'http://tempuri.org/Add'
}
}
);
console.log(response.data);
} catch (err) {
// Handle Error Here
console.error(err);
}
};
getAdd();
response
$ node add.js
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><AddResponse xmlns="http://tempuri.org/"><AddResult>200</AddResult></AddResponse></soap:Body></soap:Envelope>
Both no return \n in XML returned data.
If you test with my axios code(add calculator) with no '\n' value.
It means not a axios issue, it may be your SOAP server issue.

Why do I always get ErrorInvalidRequest for DeleteItem EWS Operation?

I'm trying to use the EWS DeleteItem operation, and here's how I'm calling it:
var mailbox = Office.context.mailbox;
var item = Office.cast.item.toItemRead(mailbox.item);
var requestResponse = mailbox.makeEwsRequestAsync(getDeleteItemRequest(item.itemId), callback2);
Here is my getDeleteItemRequest function:
function getDeleteItemRequest(id) {
var result = '<?xml version="1.0" encoding="utf-8"?> ' +
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"> ' +
'<soap:Body> ' +
'<DeleteItem DeleteType="HardDelete" xmlns="https://schemas.microsoft.com/exchange/services/2006/messages"> ' +
'<ItemIds> ' +
'<t:ItemId Id="' + id + '" /> ' +
'</ItemIds> ' +
'</DeleteItem> ' +
'</soap:Body> ' +
'</soap:Envelope>';
return result;
}
But, I always get back ErrorInvalidRequest and the item is never deleted.
It is Exchange 2013 that I'm using. Why is this failing to delete the item?
Thanks!
DeleteItem isn't allowed in an Addin, only a subset of EWS Request are they are listed in https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/web-services. You can use MoveItem or set a specific retention tag on the Item as an alternative.
In you request the XML schema definitions are wrong Microsoft did a mass update on the documentation and broke most EWS request (the changed http to https in the schema declaration which the server won't accept) so your request
function getMoveItemRequest(id, changeKey) {
var result =
'<?xml version="1.0" encoding="utf-8"?> ' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' +
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> ' +
'<soap:Header> ' +
'<t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" /> ' +
'</soap:Header> ' +
'<soap:Body> ' +
'<MoveItem xmlns="https://schemas.microsoft.com/exchange/services/2006/messages" ' +
'xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"> ' +
'<ToFolderId> ' +
'<t:DistinguishedFolderId Id="deleteditems"/> ' +
'</ToFolderId> ' +
'<ItemIds> ' +
'<t:ItemId Id="' + id + '" ChangeKey="' + changeKey + '"/> ' +
'</ItemIds> ' +
'</MoveItem> ' +
'</soap:Body> ' +
'</soap:Envelope> ';
return result;
}
should be
function getMoveItemRequest(id, changeKey) {
var result =
'<?xml version="1.0" encoding="utf-8"?> ' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' +
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> ' +
'<soap:Header> ' +
'<t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" /> ' +
'</soap:Header> ' +
'<soap:Body> ' +
'<MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" ' +
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> ' +
'<ToFolderId> ' +
'<t:DistinguishedFolderId Id="deleteditems"/> ' +
'</ToFolderId> ' +
'<ItemIds> ' +
'<t:ItemId Id="' + id + '" ChangeKey="' + changeKey + '"/> ' +
'</ItemIds> ' +
'</MoveItem> ' +
'</soap:Body> ' +
'</soap:Envelope> ';
return result;
}

Putting the variable into the a href tag

i am having issue with assigning the variable into the URL
This is the code
var value = i+1;
var customPopup = 'Latitude: ' + data.Table[i].Latitude + '</br>Longitude: ' + data.Table[i].Longitude
+ '</br>Station: ' + data.Table[i].StationID + ' </br>Box: ' + data.Table[i].BoxID + '</br>Timestamp: ' + data.Table[i].LocationSend + "<br><a target='_blank' href='/Home/History?DeviceID= ' style='color: #000000'>Click Here For Location History</a></br>";
String literals might help (using backticks ``):
var value = i+1;
var customPopup = 'Latitude: ' + data.Table[i].Latitude +
'<br/>Longitude: ' + data.Table[i].Longitude +
'<br/>Station: ' + data.Table[i].StationID +
'<br/>Box: ' + data.Table[i].BoxID +
'<br/>Timestamp: ' + data.Table[i].LocationSend +
`<br/><a target='_blank' href='/Home/History?DeviceID=${value}' style='color: #000000'>Click Here For Location History</a><br/>`;

Adding link message in a SOAP instruction

I am actually writing a SOAP command (from javascript) for an Outlook Add-In that sends a mail (to run on an Exchange Server). In the mail, I want to include 2 hyperlinks in 2 different lines. As of now, the code is as follows;
{
var soapNotificationItem = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"' +
' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <soap:Header>' +
' <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
' </soap:Header>' +
' <soap:Body>' +
' <m:CreateItem MessageDisposition="SendAndSaveCopy">' +
' <m:Items>' +
'<t:Message>'+
'<t:Subject>Notification email</t:Subject>'+
'<t:Body BodyType="HTML">' + MyMessage + '</t:Body>' +
' <t:ExtendedProperty>' +
' <t:ExtendedFieldURI PropertyTag="16367" PropertyType="SystemTime" />'+
'<t:Value>2014-01-02T21:09:52.000</t:Value>'+
'</t:ExtendedProperty>'+
'<t:ToRecipients>' + MyMailAdd + '</t:ToRecipients>' +
'</t:Message>'+
' </m:Items>' +
' </m:CreateItem>' +
' </soap:Body>' +
'</soap:Envelope>';
mailbox.makeEwsRequestAsync(soapNotificationItem, soapNotificationItemCallback);
}
As you can see, I have my parameter MyMessage, which I am constructing separately, as represented in the below example;
MyMessage = "www.mylink1.com" + "
" + "www.mylink2.com"
Any Idea how I make hyperlinks out of the 2 links with a line break in between. The
does not work either.
Finally I managed to find a solution to the issue. By specifying the Body type to HTML <t:Body BodyType="HTML">, I have been able to add simple HTML.
To simplify, the HTML construction follows the below format, though in my case, I was reading the data from a XML file, looping and concatenating the message to be displayed.
var link1 = "www.test.com"
var MyMessage = "<strong>Click on link :</strong>: " + Link1 + "";
Then coming to the SOAP part, it remains as is;
{
var soapNotificationItem = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"' +
' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <soap:Header>' +
' <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
' </soap:Header>' +
' <soap:Body>' +
' <m:CreateItem MessageDisposition="SendAndSaveCopy">' +
' <m:Items>' +
'<t:Message>'+
'<t:Subject>Notification email</t:Subject>'+
'<t:Body BodyType="HTML">' + MyMessage + '</t:Body>' +
' <t:ExtendedProperty>' +
' <t:ExtendedFieldURI PropertyTag="16367" PropertyType="SystemTime" />'+
'<t:Value>2014-01-02T21:09:52.000</t:Value>'+
'</t:ExtendedProperty>'+
'<t:ToRecipients>' + MyMailAdd + '</t:ToRecipients>' +
'</t:Message>'+
' </m:Items>' +
' </m:CreateItem>' +
' </soap:Body>' +
'</soap:Envelope>';
mailbox.makeEwsRequestAsync(soapNotificationItem, soapNotificationItemCallback);
}
NOTE: for the link to appear correctly in Office365, do add the # in front of the link.

Print ".00" When The Result Is A Whole Number?

I want to try and print ".00" after the variables cache.todayHigh and cache.todayLow are whole numbers.
if (ddimgtooltip.showTips) {
// update tooltip
tip = 'High ' + strings.baro_info + ': ' + cache.todayHigh + ' ' + data.pressunit + ' ' + strings.at + ' ' + data.TpressTH +
' <br> ' + strings.minimum_info + ' ' + strings.baro_info + ': ' + cache.todayLow + ' ' + data.pressunit + ' ' + strings.at + ' ' + data.TpressTL;
if (cache.trendVal !== -9999) {
tip += '<br>' + strings.baro_trend_info + ': ' + baroTrend(cache.trendVal, data.pressunit, true) + ' ' +
(cache.trendValRnd > 0 ? '' : '') + cache.trendValRnd + ' ' + data.pressunit + '/hr';
}
$('#imgtip5_txt').html(tip);
}
e.g. 1017 hPa to 1017.00 hPa.
Is this possible?
Thanks,
William
Try this,
var yvalue = '1702 hpa';
var num = yvalue.replace(/[^0-9]+/ig,"");
value = Number(num).toFixed(2);
var fvalue= value +' '+yvalue.split(' ')[1]
console.log(fvalue);

Categories