How to send a specialized XML request in JavaScript - javascript

I'm fairly new with XML...
How would I send the following XML to "https://www.exampleserver.com" ?
<?xml version='1.0' encoding='UTF-8'?>
<methodCall>
<methodName>ContactService.add</methodName>
<params>
<param>
<value><string>privateKey</string></value>
</param>
<param>
<value><struct>
<member><name>FirstName</name>
<value><string>John</string></value>
</member>
<member><name>LastName</name>
<value><string>Doe</string></value>
</member>
<member><name>Email</name>
<value><string>there_he_go#itsjohndoe.com</string></value>
</member>
</struct></value>
</param>
</params>
</methodCall>

With client side scripting, you can only send the XML to the same domain as the one the web server is on, unfortunately. This is a security feature. However, you could send it to your own server and have your server send it.
To send it to your own server, you could do the following:
var xml = '' +
'<?xml version='1.0' encoding='UTF-8'?>' +
'<methodCall>' +
'<methodName>ContactService.add</methodName>' +
'<params>' +
' <param>' +
' <value><string>privateKey</string></value>' +
' </param>' +
' <param>' +
' <value><struct>' +
' <member><name>FirstName</name>' +
' <value><string>John</string></value>' +
' </member>' +
' <member><name>LastName</name>' +
' <value><string>Doe</string></value>' +
' </member>' +
' <member><name>Email</name>' +
' <value><string>there_he_go#itsjohndoe.com</string></value>' +
' </member>' +
' </struct></value>' +
' </param>' +
'</params>' +
'</methodCall>';
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST","https://www.yourdomain.com/thepage",true);
xmlhttp.send(escape(xml));

Related

How to create an epub from javascript?

I am trying to create en ePub using the JSZIP javascript library but the output (i.e. epub.epub file) is not usable/reable
The following code does not work :
// Create a new ZIP file
var zip = new JSZip();
// Set the metadata for the book
var metadata = '<?xml version="1.0"?>' +
'<package xmlns="http://www.idpf.org/2007/opf">' +
' <metadata>' +
' <dc:title>My Book</dc:title>' +
' <dc:author>John Smith</dc:author>' +
' </metadata>' +
' <manifest>' +
' <item id="text" href="text.txt" media-type="application/xhtml+xml"/>' +
' <item id="toc" href="toc.ncx" media-type="application/x-dtbncx+xml"/>' +
' </manifest>' +
' <spine>' +
' <itemref idref="text"/>' +
' </spine>' +
'</package>';
zip.file("content.opf", metadata);
// Set the table of contents for the book
var toc = '<?xml version="1.0"?>' +
'<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">' +
' <head>' +
' <meta name="dtb:uid" content="book-id"/>' +
' <meta name="dtb:depth" content="1"/>' +
' <meta name="dtb:totalPageCount" content="0"/>' +
' <meta name="dtb:maxPageNumber" content="0"/>' +
' </head>' +
' <docTitle>' +
' <text>My Book</text>' +
' </docTitle>' +
' <navMap>' +
' <navPoint id="navpoint-1" playOrder="1">' +
' <navLabel>' +
' <text>Chapter 1</text>' +
' </navLabel>' +
' <content src="text.txt#xpointer(/html/body/p[1])"/>' +
' </navPoint>' +
' <navPoint id="navpoint-2" playOrder="2">' +
' <navLabel>' +
' <text>Chapter 2</text>' +
' </navLabel>' +
' <content src="text.txt#xpointer(/html/body/p[5])"/>' +
' </navPoint>' +
' </navMap>' +
'</ncx>';
zip.file("toc.ncx", toc);
// Add the text of the book to the ZIP file
// Add the text of the book to the ZIP file
zip.file("text.txt", "Chapter 1\n\nThis is the text for chapter 1.\n\nChapter 2\n\nThis is the text for chapter 2.");
// Generate a downloadable EPUB file from the ZIP file
zip.generateAsync({ type: "blob" })
.then(function (blob) {
saveAs(blob, "epub.epub");
});
Could you please help me find a solution or redirect toward an existing library ?
I want to be able to use it within a chrome extension, I tried jEpub but it is blocked by chrome.
There are a number of issues with your EPUB generation which would suggest you haven't read through the OPF specification which can be found here: https://idpf.org/epub/30/spec/epub30-ocf.html
The (main) issues are:
Missing metadata file
Incorrect structure (best practice)
OPF file missing version package version
You're using the dc namespace without it being defined. Define it.
Missing required dc elements such as dc:identifier.
dc:author doesn't exist as an element. Use dc:creator instead
Your spine should declare toc="toc"
Pages should be of type .xhtml
You should also include a nav file
Here is a working version of your script:
var zip = new JSZip();
// Set the metadata for the book
var mimetype = 'application/epub+zip';
zip.file("mimetype", mimetype);
var container = '<?xml version="1.0"?>' +
'<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">' +
' <rootfiles>' +
' <rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml" />' +
' </rootfiles>' +
'</container>';
zip.file("META-INF/container.xml", container);
var metadata = '<?xml version="1.0"?>' +
'<package version="3.0" xml:lang="en" xmlns="http://www.idpf.org/2007/opf" unique-identifier="book-id">' +
' <metadata xmlns:dc="http://purl.org/dc/elements/1.1/">' +
' <dc:identifier id="book-id">urn:uuid:B9B412F2-CAAD-4A44-B91F-A375068478A0</dc:identifier>' +
' <meta refines="#book-id" property="identifier-type" scheme="xsd:string">uuid</meta>' +
' <meta property="dcterms:modified">2000-03-24T00:00:00Z</meta>' +
' <dc:language>en</dc:language>' +
' <dc:title>My Book</dc:title>' +
' <dc:creator>John Smith</dc:creator>' +
' </metadata>' +
' <manifest>' +
' <item id="text" href="text.xhtml" media-type="application/xhtml+xml"/>' +
' <item id="toc" href="../OEBPS/toc.ncx" media-type="application/x-dtbncx+xml"/>' +
' </manifest>' +
' <spine toc="toc">' +
' <itemref idref="text"/>' +
' </spine>' +
'</package>';
zip.file("OEBPS/content.opf", metadata);
// Set the table of contents for the book
var toc = '<?xml version="1.0"?>' +
'<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">' +
' <head>' +
' <meta name="dtb:uid" content="urn:uuid:B9B412F2-CAAD-4A44-B91F-A375068478A0"/>' +
' <meta name="dtb:depth" content="1"/>' +
' <meta name="dtb:totalPageCount" content="0"/>' +
' <meta name="dtb:maxPageNumber" content="0"/>' +
' </head>' +
' <docTitle>' +
' <text>My Book</text>' +
' </docTitle>' +
' <navMap>' +
' <navPoint id="navpoint-1" playOrder="1">' +
' <navLabel>' +
' <text>Chapter 1</text>' +
' </navLabel>' +
' <content src="text.xhtml#xpointer(/html/body/section[1])"/>' +
' </navPoint>' +
' <navPoint id="navpoint-2" playOrder="2">' +
' <navLabel>' +
' <text>Chapter 2</text>' +
' </navLabel>' +
' <content src="text.xhtml#xpointer(/html/body/section[2])"/>' +
' </navPoint>' +
' </navMap>' +
'</ncx>';
zip.file("OEBPS/toc.ncx", toc);
// Add the text of the book to the ZIP file
// Add the text of the book to the ZIP file
var text = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' +
'<!DOCTYPE html>' +
'<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">' +
' <head>' +
' <title>My Book</title>' +
' </head>' +
' <body>' +
' <section><h1>Chapter 1</h1>' +
' <p>This is the text for chapter 1.</p>' +
' </section>' +
' <section><h1>Chapter 2</h1>' +
' <p>This is the text for chapter 2.</p>' +
' </section>' +
' </body>' +
'</html>';
zip.file("OEBPS/text.xhtml", text);
// Generate a downloadable EPUB file from the ZIP file
zip.generateAsync({ type: "blob" }).then(function (blob) {
saveAs(blob, "epub.epub");
});
Ensure that you also run your generated EPUB against a validator to debug. Something like https://draft2digital.com/book/epubcheck/upload is good.

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;
}

MoveItem Invalid Request

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;
}

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.

Categories