πŸ”¬ Automating SAP B1 journal entries using JSON, Google Sheets, and GPT-4o

⚑ 392 views Β· πŸ”¬ Document Extraction & Analysis

Description

HOW IT WORKS:

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.

πŸ”Ή 1. Webhook Input Reception

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)

πŸ”Ή 2. SAP B1 Login

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).

πŸ”Ή 3. Dynamic Branching via Switch Node

Depending on the value of origen, one of the following branches is activated:

πŸ”Ή 4. Data Transformation via LLM

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.

πŸ”Ή 5. POST to SAP B1

Data is sent to {{SAP_URL}}/JournalEntries using the Service Layer’s POST method with the B1SESSION cookie attached. The body includes all JournalEntryLines.

πŸ”Ή 6. Logging Success & Errors

Each result (success or failure) is logged into a centralized Google Sheets log document:

SETUP STEPS:

1. Create Required Credentials:

3. Prepare Google Sheets:

Make sure the logging spreadsheet contains these columns:

workflow, method, url, json, status_code, message

EXTRA NOTES:

🧠 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

πŸ”— Nodes Used

Google Sheets, HTTP Request, Webhook, OpenAI

πŸ“₯ Import

Download workflow.json and import into n8n: Workflow menu β†’ Import from File

πŸ“– Importing guide Β· πŸ”‘ Credential setup