Use dojo.xhrpost to create automatically a workitem
Hello,
I can create a workitem as the following article describes:
https://jazz.net/library/article/782/
Instead of opening a new workitem, I wish to create a workitem with a post html request. I can create it with "curl" command (https://jazz.net/wiki/bin/view/Main/ResourceOrientedWorkItemAPIv2).
So I want to know if it's possible to excute a post request with the dojo function, xhrpost, or another function.
Thank you in advance
Best regards
David
I can create a workitem as the following article describes:
https://jazz.net/library/article/782/
Instead of opening a new workitem, I wish to create a workitem with a post html request. I can create it with "curl" command (https://jazz.net/wiki/bin/view/Main/ResourceOrientedWorkItemAPIv2).
So I want to know if it's possible to excute a post request with the dojo function, xhrpost, or another function.
Thank you in advance
Best regards
David
5 answers
You can do most things with XHR POSTs that you can do with any other HTTP client. Though for security, the browser restricts you to only making POSTs to the current hostname you're on (that the page was originally loaded from). So you won't be able to do it from another page on another host. Other than that you can put anything in the body and add whatever headers you need. The browser will automate some things for you, like Accept and Accept-Encoding headers (gzip support), cookies, and authentication.
Before to it in a pluggin, I have tried to custom attribut script (Calculated Values).
I trie with the following source code:
dojo.provide("org.example.workitems.providers.postrequest");
-------------------------
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("org.example.workitems.providers.postrequest", null, {
getValue: function(attributeId, workItem, configuration) {
var xhrArgs = {
url: "https://<my server>/ccm/oslc/workitems/522/rtc_cm:com.ibm.team.scm.svn.linkType.workItem.s",
postData: dojo.toJson({"rdf:resource":"http://www.david.com","oslc_cm:label":"add a new comment"}),
handleAs: "json",
// headers:
}
dojo.xhrPost(xhrArgs);
return "system impact";
}
});
})();
--------------------------
This source code doesn't work. Do you think that it can work ?
What is different to execute dojo code source througth a plugin and to execute dojo code source throught custom attribut ?
I trie with the following source code:
dojo.provide("org.example.workitems.providers.postrequest");
-------------------------
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("org.example.workitems.providers.postrequest", null, {
getValue: function(attributeId, workItem, configuration) {
var xhrArgs = {
url: "https://<my server>/ccm/oslc/workitems/522/rtc_cm:com.ibm.team.scm.svn.linkType.workItem.s",
postData: dojo.toJson({"rdf:resource":"http://www.david.com","oslc_cm:label":"add a new comment"}),
handleAs: "json",
// headers:
}
dojo.xhrPost(xhrArgs);
return "system impact";
}
});
})();
--------------------------
This source code doesn't work. Do you think that it can work ?
What is different to execute dojo code source througth a plugin and to execute dojo code source throught custom attribut ?
David,
So it didn't work within the javascript API? you had to write a eclipse plugin?
Thanks,
Binoy
So it didn't work within the javascript API? you had to write a eclipse plugin?
Thanks,
Binoy
Comments
Hello Binoy,
Yes, extending RTC using its APIs requires an Eclipse plugin.
Please, see this article: https://jazz.net/library/article/784/