Skip to Content
0
Apr 16, 2020 at 02:15 PM

Error while calling S/4HANA OData service externally

94 Views

I am trying to call the API get method to fetch the csrf token using ajax call, as mentioned below. But i am getting the security error.

Whereas it is working fine with POSTMAN with same authorization and header parameters .

Can you please help in finding the issue and fixing it.

  • Populated the API url in variable
GLOBAL.step({ Custom:function(ev, sc, st){
	var rootData = sc.data;
	ctx.workflow('PostJE_WF','562130e2-db0c-462f-8fc2-8dca926f3314');// Custom
	
	var geturl ='http://<HOST>:<PORT>/sap/opu/odata/sap/<service>/<entity>';
	API.GET(geturl, sc);
	ctx.log('csrf token fetched');
	sc.endStep();//end Scenario
	return;}});
  • Calling the Get method function.
var API ={GET:function(url, sc){
		var response;
		var rootData = sc.data;
		ctx.ajax.call({method:e.ajax.method.get,
			url: url,//contentType:e.ajax.content.json, 
			contentType:e.ajax.content.xml,headers:{'Authorization':'Basic '+ ctx.base64.encode('USERNAMEVALUE'+':'+'PASSWORDVALUE'),'Content-Type':'application/atom+xml','x-csrf-token':'fetch','Accept':'application/json'},
			ignoreClientCertificate: true,
			success:function(res,status, xhr){
				
				sc.endStep();return;},
			error:function(res,status, xhr){
				
				sc.endStep();return;}});}
  • Getting error in response

Thanks

Vijay