Rest call to same instance from service portal widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2019 10:36 AM
Hi,
I have a custom widget to upload documents by selecting the table name and task number. This is done using REST POST method as shown below. This works fine as a logged in user. I am trying to achieve the same but as a different user. I did try using "'Authorization':'Basic '+btoa('username'+':'+'password')" in the header section of the below client controller script in widget, but nothing is happeing when I do this. Any ideas on how to do it?
$scope.uploadFiles = function() {
$scope.fd = new FormData();
$scope.files.forEach(function(file){
$scope.fd.set('files', file);
var request = {
method: 'POST',
url: 'https://instancename.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id='+c.data.rec_sysid+'&file_name='+file.name,
data: $scope.fd.get('files'),
headers: {
'Content-Type': file.type,
'Accept':'application/json',
}
};
console.log('HTTP request:',request);
// SEND THE FILES.
$http(request)
.success(function (d) {
// On success code here
})
.error(function (err) {
// On error code here
});
});
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2019 12:54 PM
HI,
Can you try this:
headers: {
'Content-Type': file.type,
'Accept':'application/json',
'Authorization': 'Basic user:password'
}
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2019 09:25 AM
Hi, actually it worked with "'Authorization':'Basic '+btoa('username'+':'+'password')". I was using an incorrect username.
However, instead of just adding the attachment to the incident as this account, it is actually logging me in as the user account. Do you know if that can be prevented?