Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2018-09-19 09:25 AM
Hi Folks,
I'm trying to create a simple custom object with a button to launch a datafeed but I can't seem to get it to work at all after many hours scratching my head!
This is my code. Could someone please advise where I'm going wrong. (please ignore all the alerts as I tried to figure out where the code was getting to. I always see the "failed to launch feed!" alert.
Thanks
Neil.
<button type="button" ="trigger()">Create Finding</button>
<script type="text/javascript">
var authstr = '{"InstanceName":"50000","Username":"apisvintake","UserDomain":"","Password":"xxxxxx"}';
var authUrl = 'https://<server>/archer/api/core/security/login';
var feedUrl = 'https://<server>/archer/api/core/datafeed/execution';
var feedstr = '{"DataFeedGuid":"87BB24F5-A66F-498F-B7E6-00F586A74776","IsReferenceFeedsIncluded":false}';
function trigger() {
$.ajax
({
type: "POST",
url: authUrl,
contentType: "application/json",
dataType: "json",
data:authstr,
success: function (result) {
var stringresult = JSON.stringify(result);
var sesstok = 'Archer session-id=' + stringresult.substr(stringresult.search("SessionToken")+15,32);
//;
$.ajax
({
type: "POST",
url: feedUrl,
contentType: "application/json",
processData: false,
dataType: "json",
data : feedstr,
beforeSend : function( xhr ) {
xhr.setRequestHeader( "Authorization", sesstok );
xhr.setRequestHeader( "content-Type", "application/json" );
xhr.setRequestHeader( "Accept", "application/json,text/html,application/xhtml+xml,application/xml;q=.9,*/*;q=0.8" );
alert(sesstok);
},
success: function (runfeed) {
var feedresult = JSON.stringify(runfeed);
alert("Feed success");
},
error: function(errormsg) {
alert("failed to launch feed!");
alert(JSON.stringify(errormsg.responseXML));
}
});
},
error: function(errMsg) {
alert("outside func");
alert(JSON.stringify(errMsg.responseXML));
}
});
alert("button press finished");
};
</script>
2018-09-19 10:32 AM
Ahh, ok. Though I'd advised against this being the credentials are store in clear text in the browser and any curious user could use that information to log into Archer.
With that said
You need to add this to your two ajax calls, after lines 14 and 26
headers: {
'x-csrf-token': (window.sessionStorage) ? window.sessionStorage.getItem("x-csrf-token") : csrfToken = parent.parent.ArcherApp.globals['xCsrfToken']
},
Also some feedback, you can replace lines 5 and 6 with:
var baseURL = window.location.protocol + '//' + window.location.host + parent.parent.ArcherApp.globals['baseUrl'];
then adjust line 12 with
baseURL + '/api/core/security/login'
then the same for line 23 with
baseURL + '/api/core/datafeed/execution'
This would at least save you the pain of updating the custom object when moving the application from one instance to the next.
Advisory Consultant
2018-09-19 09:31 AM
Neil, why reinvent the wheel
https://community.rsa.com/docs/DOC-62020#comment-33915
Advisory Consultant
2018-09-19 09:36 AM
Thanks David. I saw that one, but didn't want to give the group of users that need to see the button the rights to see the datafeed manager. I even tried to add the authorization section into that one but that code was a real mess!!!
2018-09-19 10:32 AM
Ahh, ok. Though I'd advised against this being the credentials are store in clear text in the browser and any curious user could use that information to log into Archer.
With that said
You need to add this to your two ajax calls, after lines 14 and 26
headers: {
'x-csrf-token': (window.sessionStorage) ? window.sessionStorage.getItem("x-csrf-token") : csrfToken = parent.parent.ArcherApp.globals['xCsrfToken']
},
Also some feedback, you can replace lines 5 and 6 with:
var baseURL = window.location.protocol + '//' + window.location.host + parent.parent.ArcherApp.globals['baseUrl'];
then adjust line 12 with
baseURL + '/api/core/security/login'
then the same for line 23 with
baseURL + '/api/core/datafeed/execution'
This would at least save you the pain of updating the custom object when moving the application from one instance to the next.
Advisory Consultant
2018-09-19 11:07 AM
You Sir, are a genius!!!
Worked a treat. Thanks!
2018-09-19 11:18 AM
My pleasure Neil
Advisory Consultant