Blog

How to integrate SAP B1 (Business One) into WordPress Gravity Forms

We built Shift8 GravitySAP because a client needed Gravity Forms submissions to land directly in SAP Business One. Off-the-shelf “connectors” wanted a monthly fee, pushed data through third-party relays, or stopped at a generic webhook. That was not good enough for strict ERP rules, audit trails, and on-prem Service Layer setups. So we wrote the integration as a WordPress plugin, used Gravity Forms’ Add-On framework for clean per-form feeds, and open sourced the whole thing.

This post is a will walk you through how to use the plugin as well as some interesting technical challenges we came across with putting it together.


What the plugin does

  • Adds a global connection screen for your SAP Business One Service Layer endpoint and credentials.
  • Adds a per-form “SAP Integration” settings panel where you enable the feed, pick Business Partner type, and map fields.
  • On submission, the plugin validates field lengths and formats, logs into the Service Layer, and creates a Business Partner in SAP B1.
  • Optionally creates a Sales Quotation linked to the new Business Partner if you enable it.
  • Writes clear Entry Notes and debug logs so you can trace success or failure.

Prerequisites

  • WordPress with Gravity Forms installed.
  • Access to an SAP Business One Service Layer endpoint. Example base URL:
    https://your-sap-server:50000/b1s/v1/
  • An SAP B1 user with permission to create Business Partners (and Sales Quotations if you use that feature).
  • Proper numbering series configured for Business Partners in SAP B1.

Install and connect Gravity Forms to SAP B1 (Business One)

  1. Install the plugin from the WordPress directory and activate it.
  2. Open Shift8 → Gravity SAP and enter your Service Layer settings.
Gravity Forms SAP Business One integration settings page.

Recommended settings on this screen:

  • SAP Service Layer Endpoint: full https://…/b1s/v1/ URL.
  • Company Database: your target DB name.
  • SSL Certificate Verification: keep enabled for production. Only disable temporarily when testing self-signed certs.
  • Debug Logging: enable while you set things up. Turn off later if you prefer quieter logs.

Click Save Changes, then Test SAP Connection. If credentials or TLS are wrong, you will see a useful error. Fix those before moving on.


Map a form to SAP

Open the Gravity Form you want to integrate and go to Settings → SAP Integration.

Gravity Forms SAP integration settings screen.

Work top-to-bottom on this screen:

  • Enable SAP Integration: check it.
  • Feed Name: a short label you will recognize later.
  • Business Partner Type: Customer, Vendor, or Lead.
  • Business Partner Code Prefix: matches your SAP B1 configuration if you use prefixed series.
  • Create Sales Quotation: enable if you want a quotation right after BP creation.
  • Business Partner Field Mapping: map your Gravity Forms fields to SAP fields. The UI shows SAP limits so you can stay inside length caps.

Save. Submit a test entry on the front end. Then open the entry and check Notes for the SAP result. If enabled, verify the new Business Partner (and optional Quotation) in SAP B1.


How it works under the hood

1) Service Layer login
The plugin posts JSON credentials to /Login, receives a SessionId and cookies such as B1SESSION and ROUTEID, and reuses them for subsequent calls.

function s8_sap_login( $endpoint, $company_db, $username, $password ) {
  $resp = wp_safe_remote_post( rtrim($endpoint,'/').'/Login', [
    'headers' => ['Content-Type'=>'application/json'],
    'timeout' => 20,
    'body'    => wp_json_encode([
      'CompanyDB'=>$company_db, 'UserName'=>$username, 'Password'=>$password
    ]),
  ]);
  // Handle HTTP errors and return ['session_id'=>..., 'cookies'=> 'B1SESSION=...; ROUTEID=...']
}

2) Create the Business Partner
After mapping and validation, the plugin posts to /BusinessPartners with the cookie header.

function s8_sap_create_bp( $endpoint, $cookies, array $bp ) {
  return wp_safe_remote_post( rtrim($endpoint,'/').'/BusinessPartners', [
    'headers' => ['Content-Type'=>'application/json', 'Cookie'=>$cookies],
    'timeout' => 20,
    'body'    => wp_json_encode($bp),
  ]);
}

3) Validation that saves time
SAP B1 enforces strict limits. The plugin checks common ones first so you get a clear message in WordPress instead of a cryptic 400 from SAP.

if ( strlen($bp['CardName']) > 100 )  return new WP_Error('bad_cardname','CardName max 100');
if ( ! empty($bp['EmailAddress']) && ! is_email($bp['EmailAddress']) )
  return new WP_Error('bad_email','Invalid EmailAddress');
if ( ! empty($addr['City']) && strlen($addr['City']) > 25 )
  return new WP_Error('bad_city','City max 25');

4) Entry Notes and logs
Each submission writes a success or fail note:

[ SAP ] Business Partner created: OK

or

[ SAP ] Create failed: CardName length exceeds limit

Debug logging (when enabled) also writes to error_log() with codes and timestamps, but redacts secrets.

The plugin wraps this logic inside the Gravity Forms Add-On framework so you do not need to write code to use it.


A quick end-to-end example

  1. Connect in Shift8 → Gravity SAP, test the connection.
  2. In Forms → Your Form → Settings → SAP Integration:
    • Enable the feed.
    • Choose Customer.
    • Map Business Partner Name to your “First and Last Name Combined” field.
    • Map Email Address, Telephone fields, and at least one Address.
    • Optionally enable Create Sales Quotation.
  3. Submit a front-end test entry.
  4. Check Entries → Notes for a success message.
  5. Confirm the new BP in SAP B1. If you see a validation error, adjust the form field lengths or mapping and resubmit.

What to do when things fail

  • Login error on “Test SAP Connection”: confirm the URL ends with /b1s/v1/, verify TLS, and check firewall allowlists.
  • 400 with field message: shorten inputs or enforce max lengths in Gravity Forms rules. The per-field SAP limits are shown in the UI.
  • Missing number series: configure series in SAP B1. Run the plugin’s numbering test again.
  • Self-signed certs in dev: either import a proper cert on the SAP host or disable SSL verification only while testing. Keep SSL verification on for production.

Security notes

  • Credentials are stored encrypted with WordPress salts.
  • Only administrators can view and change plugin settings.
  • All requests use wp_safe_remote_* with timeouts.
  • The plugin never logs passwords or raw session cookies.
  • Keep WordPress and Gravity Forms up to date. Restrict admin access. Rotate SAP credentials per your policy.

Why we open sourced this

Enterprise integrations often end up as subscription connectors with little transparency and a per-site tax. We wanted teams to own the last mile, keep data inside their stack, and pass audits with readable logs. Open source makes that possible. If you need custom fields or a different SAP object, you can extend the plugin rather than wait on a vendor backlog. Alternatively you can just check out the Github repo for Shift8 GravitySAP and submit your own PR.


Tips from real deployments

  • Normalize addresses at the form level. Use separate fields for street, city, province or state, postal code, and 2-letter country code.
  • Keep phone lengths conservative. SAP often caps Telephone fields at 20 characters. Strip formatting if needed.
  • Throttle tests. If your Service Layer is behind a VPN or WAF, run a few test submissions rather than dozens at once.
  • Use a staging SAP user for setup and testing. Switch to production credentials once your mappings and tests are stable