Chris Dunn
Guest
|
Posted:
Tue Nov 08, 2005 1:58 am Post subject:
Webdav via javascript |
|
|
I am trying to create a calendar entry using the following javascript code
and i keep getting the "Error 400". Any help would be great...
<html>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function sendDAV(sURL)
{
// XML request string uses UTF-8 Apr 21st
var strReq = "<?xml version='1.0'
encoding='UTF-8'?><d:propertyupdate xmlns:d='DAV:'" +
" xmlns:a='urn:schemas:calendar:'" +
" xmlns:e='urn:schemas:httpmail:'" +
"
xmlns:dt='urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/'" +
" xmlns:h='urn:schemas:mailheader:'" +
" xmlns:f='http://schemas.microsoft.com/exchange/'>" +
" <d:set><d:prop>" +
"<a:dtstart>2005-11-7T20:00:00Z</a:dtstart>" +
"<a:dtend>2005-11-7T20:30:00Z</a:dtend>" +
"<a:meetingstatus>TENTATIVE</a:meetingstatus>" +
"<e:subject>My Appointment</e:subject>" +
// "<e:instancetype dt:dt='int'>0</e:instancetype>" +
"<e:location>Office</e:location>" +
"<d:contentclass>urn:content-classes:appointment</d:contentclass>"
+
"<f:outlookmessageclass>IPM.Appointment</f:outlookmessageclass>"
+
"</d:prop></d:set></d:propertyupdate>";
alert(strReq);
// create and send the XMLHTTP Request object
var xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
xmlReq.Open("PROPPATCH", sURL, false);
xmlReq.SetRequestHeader("Content-type", "text/xml");
xmlReq.SetRequestHeader("Translate", "t");
xmlReq.SetRequestHeader("Content-Length", strReq.length);
xmlReq.send(strReq);
// check HTTP status of request
if(xmlReq.status != "201") {
alert("Error: "+xmlReq.status+": "+xmlReq.statusText);
alert(xmlReq.responseXML);
}
else
alert("Success");
}
sendDAV("http://SERVERNAME/exchange/USERFOLDER/Calendar/dev.eml");
</SCRIPT>
</head>
<BODY>
</body>
</html>
|
|
Glen Scales [MVP]
Guest
|
Posted:
Wed Nov 09, 2005 9:10 am Post subject:
Re: Webdav via javascript |
|
|
I can see a few problems with your code first your not using a datatype with
the both you datetimes and you using translate t instead of translate f.
Here's a jscript sample that I know works okay
<SCRIPT LANGUAGE="JScript">
var myxml = "";
var xmlheader="";
var xmlCALvar="";
var strCalInfo="";
var strHeaderInfo="";
var strMailInfo="";
var strApptRequest="";
xmlheader = "xmlns:g=\"DAV:\" ";
xmlheader += "xmlns:e=\"http://schemas.microsoft.com/exchange/\" ";
xmlheader += "xmlns:mapi=\"http://schemas.microsoft.com/mapi/\" " ;
xmlheader += "xmlns:x=\"xml:\" xmlns:cal=\"urn:schemas:calendar:\" " ;
xmlheader += "xmlns:dt=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\" "
;
xmlheader += "xmlns:header=\"urn:schemas:mailheader:\" " ;
xmlheader += "xmlns:mail=\"urn:schemas:httpmail:\">";
strCalInfo = "<cal:location>Some Location</cal:location>" ;
strCalInfo += "<cal:dtstart
dt:dt=\"dateTime.tz\">2005-11-15T23:00:00.000Z</cal:dtstart>" ;
strCalInfo += "<cal:dtend
dt:dt=\"dateTime.tz\">2005-11-15T23:30:00.000Z</cal:dtend>" ;
strCalInfo += "<cal:instancetype dt:dt=\"int\">1</cal:instancetype>" ;
strCalInfo += "<cal:busystatus>OOF</cal:busystatus>" ;
strCalInfo += "<cal:meetingstatus>CONFIRMED</cal:meetingstatus>" ;
strCalInfo += "<cal:alldayevent dt:dt=\"boolean\">0</cal:alldayevent>" ;
strCalInfo += "<cal:responserequested
dt:dt=\"boolean\">0</cal:responserequested>" ;
strCalInfo += "<cal:reminderoffset dt:dt=\"int\">900</cal:reminderoffset>" ;
strHeaderInfo = "<header:to>youruser@domain.com</header:to>" ;
strMailInfo = "<mail:subject>Appointment (testing)</mail:subject>" ;
strMailInfo += "<mail:htmldescription>Testing 1 2 3</mail:htmldescription>"
;
strApptRequest = "<?xml version=\"1.0\"?>" ;
strApptRequest += "<g:propertyupdate " + xmlheader + "<g:set><g:prop>" ;
strApptRequest +=
"<g:contentclass>urn:content-classes:appointment</g:contentclass>" ;
strApptRequest +=
"<e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass>" ;
strApptRequest += strMailInfo + strCalInfo + strHeaderInfo ;
strApptRequest += "<mapi:finvited dt:dt=\"boolean\">1</mapi:finvited>" ;
strApptRequest += "<mapi:apptstateflags
dt:dt=\"int\">0</mapi:apptstateflags>" ;
strApptRequest += "</g:prop></g:set></g:propertyupdate>";
window.alert(strApptRequest);
var XMLreq = new ActiveXObject("Microsoft.XMLHTTP");
XMLreq.open("PROPPATCH",
"http://servername/exchange/user/calendar/apptblah.eml", false);
XMLreq.setRequestHeader("Content-Type", "text/xml;");
XMLreq.setRequestHeader("Translate", "f");
XMLreq.send(strApptRequest);
window.alert(XMLreq.responsetext)
if ((XMLreq.Status >= 200) && (XMLreq.Status < 300)) {
//alert("Success! " & "Results = " & XMLreq.Status & ": \n" +
XMLreq.statusText);
}
else if (XMLreq.Status == 401) {
// alert("You don't have permission to do the job! Please check your
permissions on this item.");
}
else {
//alert("Request Failed. Results = " & XMLreq.Status & ": \n" +
XMLreq.statusText);
}
</SCRIPT>
Cheers
Glen
"Chris Dunn" <ChrisDunn@discussions.microsoft.com> wrote in message
news:F24E0154-ED91-47CA-8848-35FECB934FAE@microsoft.com...
| Quote: | I am trying to create a calendar entry using the following javascript code
and i keep getting the "Error 400". Any help would be great...
html
HEAD
SCRIPT LANGUAGE="JavaScript"
function sendDAV(sURL)
{
// XML request string uses UTF-8 Apr 21st
var strReq = "<?xml version='1.0'
encoding='UTF-8'?><d:propertyupdate xmlns:d='DAV:'" +
" xmlns:a='urn:schemas:calendar:'" +
" xmlns:e='urn:schemas:httpmail:'" +
"
xmlns:dt='urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/'" +
" xmlns:h='urn:schemas:mailheader:'" +
"
xmlns:f='http://schemas.microsoft.com/exchange/'>" +
" <d:set><d:prop>" +
"<a:dtstart>2005-11-7T20:00:00Z</a:dtstart>" +
"<a:dtend>2005-11-7T20:30:00Z</a:dtend>" +
"<a:meetingstatus>TENTATIVE</a:meetingstatus>" +
"<e:subject>My Appointment</e:subject>" +
// "<e:instancetype dt:dt='int'>0</e:instancetype>" +
"<e:location>Office</e:location>" +
"<d:contentclass>urn:content-classes:appointment</d:contentclass>"
+
"<f:outlookmessageclass>IPM.Appointment</f:outlookmessageclass>"
+
"</d:prop></d:set></d:propertyupdate>";
alert(strReq);
// create and send the XMLHTTP Request object
var xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
xmlReq.Open("PROPPATCH", sURL, false);
xmlReq.SetRequestHeader("Content-type", "text/xml");
xmlReq.SetRequestHeader("Translate", "t");
xmlReq.SetRequestHeader("Content-Length", strReq.length);
xmlReq.send(strReq);
// check HTTP status of request
if(xmlReq.status != "201") {
alert("Error: "+xmlReq.status+": "+xmlReq.statusText);
alert(xmlReq.responseXML);
}
else
alert("Success");
}
sendDAV("http://SERVERNAME/exchange/USERFOLDER/Calendar/dev.eml");
/SCRIPT
/head
BODY
/body
/html
|
|
|