Fix CORS Error in SapB1 HANA and SQL

Fix CORS Error in SAP Business One HANA and SQL


🖥️
Introduction

If you're working with SAP Business One (on either SQL Server or SAP HANA) and trying to integrate it with a web app or third-party tool, you may run into a CORS (Cross-Origin Resource Sharing) error when calling the Service Layer.

This is a common problem for frontend developers, especially when building Angular, React, or Node.js apps. In this guide, you’ll learn how to fix the CORS issue step-by-step — and this applies whether your backend is SQL or HANA.


⚠️ What Is the CORS Error?

CORS errors typically look like this:

Access to fetch at 'https://your-sap-server:50000/b1s/v1/BusinessPartners' from origin 'http://localhost:4200' has been blocked by CORS policy.

This happens because the SAP B1 Service Layer isn’t configured to accept calls from your app’s domain.


🛠️ Step-by-Step Fix for SAP B1 SQL and HANA

The process is almost identical for both platforms, with small differences in folder paths and services.


Step 1: Locate cors-configuration.xml

For SAP B1 HANA (Linux Server):

First, check that both services are accessible in your browser:

To locate the file on Linux:

cd /usr/sap/SAPBusinessOne/Gateway.Service/conf/gateway.xml

 

 

Sample XML Configuration:

<gatewaySettings port="60000">

  <authService host="127.0.0.1" port="60010"></authService>

  <systemLogging logEnabled="true" logLevel="DEBUG"></systemLogging>

  <corsStrategy enable="true">

    <MaxAge>3600</MaxAge>

    <HttpOnly>true</HttpOnly>

    <Secure>true</Secure>

    <AllowCredentials>true</AllowCredentials>

    <AllowHeaders>

      <Header>*</Header>

    </AllowHeaders>

    <AllowMethods>

      <Method>POST</Method>

      <Method>GET</Method>

      <Method>OPTIONS</Method>

    </AllowMethods>

    <AllowOrigins>

      <Origin>http://localhost:4200</Origin>

      <Origin>https://abc.cde.com:4404</Origin>

      <Origin>https://abc.cde.in</Origin>

    </AllowOrigins>

  </corsStrategy>

</gatewaySettings>


Step 2: Restart Gateway Service

Restart the Gateway service:

systemctl restart gateway.service


Step 3: Update Service Layer Headers

Go to the header config file:

cd /usr/sap/SAPBusinessOne/ServiceLayer/conf/b1s.conf

Add or verify the following headers:

content-type, accept, B1S-ReplaceCollectionsOnPatch, Access-Control-Allow-Origin, Cookie, Origin, B1S-CaseInsensitive, sameSite, Prefer


Step 4: Modify Apache Config

Edit the Apache load balancer config file:

/usr/sap/SAPBusinessOne/ServiceLayer/conf/httpd-b1s-lb.conf

Append this block to handle cookies:

<ifmodule mod_headers.c>

  Header edit Set-Cookie ^(.*)$ $1;Secure;SameSite=None

</ifmodule>


Step 5: Restart Services

For older versions:

cd /etc/init.d

./restart b1s

For newer versions (systemd):

systemctl restart b1s

systemctl restart gateway.service


Step 6: Test with Postman

Use Postman to make a login request:

POST to:

https://yourdomain.com:50000/b1s/v1/Login

Body (JSON):

{

  "CompanyDB": "Hana_Database_Name",

  "UserName": "user",

  "Password": "password",

  "DBInstance": "NDB@yourdomain.com:30015"

}

Also verify access from your web app hosted at https://yourdomain.com.


🔖 Suggested Post 

  1. Fix CORS Error in SAP Business One HANA and SQL
  2. How to Enable CORS in SAP B1 Service Layer
  3. Resolve CORS Policy Block in SAP Business One
  4. Complete Guide to CORS Configuration in SAP B1
  5. SAP Business One API Integration: CORS Error Fix
  6. How to Fix CORS Policy Errors in JavaScript and API Requests
  7. CORS Error Explained: How to Solve It for Your Website or Blog
  8. Top Ways to Bypass or Fix CORS Issues for Beginners
  9. CORS Policy Blocked My API – Here’s How I Fixed It
  10. Solve CORS Errors in Blogger and JavaScript Projects Easily




⚠️ Disclaimer

This blog is for educational use only. We recommend using genuine Microsoft Office products. Download and use responsibly.





✅ Conclusion

That’s it! By properly configuring the SAP B1 Gateway and Service Layer, you can resolve CORS errors and successfully integrate your web applications with SAP Business One — whether you're using HANA or SQL Server. Always test after each change and allow only trusted domains for security.

If your issue has been resolved, please subscribe, share, like, and comment.
If you have any query, you can ask us your query in the comments below — we’re happy to help!



Share on Google Plus

About Pawar Live Study

Search Your Query in Search Box.

0 Comments:

Post a Comment

pawarsolution