This workflow automates the creation of Journal Entries in SAP Business One (SAP B1). Depending on the source of the input data, it dynamically transforms and sends accounting records in the appropriate format using the Service Layer API.
It supports three input types:
Each transaction is logged to Google Sheets for traceability.
A Webhook node waits for a POST request containing accounting data and metadata:
The origen field determines the data source (JSON, GoogleSheets, or Manual)
The sap_url, username, password, and companydb are used to connect to SAP B1
Payload can be a JSON list or tabular data (e.g., from Google Sheets)
Credentials are securely injected from the request body.
A login request is sent to SAP B1's Service Layer to retrieve a valid session cookie (B1SESSION).
Depending on the value of origen, one of the following branches is activated:
JSON: Sends the JSON payload directly to SAP after restructuring
GoogleSheets: Loads rows, builds JSON, and merges context
Manual: Transforms data via OpenAI LLM prompt and generates SAP-compatible format
In Manual and GoogleSheets flows, the workflow uses an OpenAI node to:
Parse line entries and convert them to JournalEntryLines[]
Format the final JSON structure required by SAP
LLM prompts are carefully crafted to return only clean JSON — no code blocks, comments, or explanations.
Data is sent to {{SAP_URL}}/JournalEntries using the Service Layer's POST method with the B1SESSION cookie attached.
The body includes all JournalEntryLines.
Each result (success or failure) is logged into a centralized Google Sheets log document:
✅ Success: Includes HTTP status, source URL, and JSON payload
❌ Failure: Logs the error code and message for review and traceability
Google Sheets OAuth2 API (to log all responses and fetch data)
OpenAI API Key (used with the LangChain OpenAI node)
SAP Service Layer login data is passed securely via body parameters.
SAP_USER, SAP_PASSWORD, SAP_COMPANY_DB
SAP_URL
📄 Sheet 1: For source entries (e.g., for GoogleSheets origin)
🧾 Sheet 2: For logging execution results
Make sure the logging spreadsheet contains these columns:
workflow, method, url, json, status_code, message
🧠 Uses OpenAI GPT-4o for natural language transformation of accounting rows
🧩 Modular logic with error-handling for all branches
📁 Can be reused across multiple accounting integrations by changing the data source