cancel
Showing results for 
Search instead for 
Did you mean: 

How to connect to SAP B1 service layer using react native ?

xenios
Explorer
0 Kudos

Hello everybody,

We are trying to develop a react native application that will use SAP Business one service layer in order to perform some tasks. When i use the https://<ServerIP>:50000 for login i get a general network error. When i use the http://<ServerIP>:50001 i get successful login. Please see below a sample from my login to service layer function. Any idea what could be the issue? Please note we are using self signed certificate.

Thank you in advance.

const sapServiceLayerEndpoint = 'https://<server IP>:50000/b1s/v1';

const LoginServiceLayer = async (companyDB, userName, password) => {
try {
const response = await fetch(`${sapServiceLayerEndpoint}/Login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},

body: JSON.stringify({
CompanyDB: companyDB,
UserName: userName,
Password: password,
}),
});

// Check for a successful response
if (response.status === 200) {

return true;
} else {
console.error('Login failed. Unexpected response:', response.statusText);

return false;
}
} catch (error) {

return false;
}
};

export default LoginServiceLayer;

View Entire Topic
andy_bai
Advisor
Advisor
0 Kudos

I think you can get the error message from the development console of your browser by pressing F12.

BTW, you deploy your code onto a static server and visit your server to run your code?

If so, is your server a http server or https server?

And you also enabled the CORS in Service Layer?

 

thanks

xenios
Explorer
0 Kudos

Hi Andy,

Thank you for the reply.

Basically the application is not deployed.

Is a react native app that i run on Android studio emulator.

Yes, CORS is enabled on the service layer.