Expert guidance for writing correct, runnable Python scripts that interact with SAP Business One Service Layer REST API. Use when creating, reading, updating, or deleting SAP B1 data via the Service Layer, producing two-file output contracts (_data.json + _run.py), writing OData query strings, understanding PATCH vs PUT semantics, or looking up endpoint schemas from the bundled OpenAPI spec.
ServiceLayer context-manager class.assets/script_template.py as the starting point for every new script.assets/spec/paths/{ResourceName}.yaml for field names.Every mutation script ships exactly two files under in the repo root:
.temp/| File | Contents |
|---|---|
.temp/<operation>_data.json | Records to create/update/delete — no credentials |
.temp/<operation>_run.py | assets/script_template.py with main() filled in |
Naming: snake_case, verb first — patch_business_partners, create_sales_order.
# Example main()
def main(data: list, sl: ServiceLayer) -> None:
for record in data:
card_code = record.pop("CardCode")
sl.patch(f"BusinessPartners('{card_code}')", record)
log.info("Patched %s", card_code)
.temp/ if needed_data.json contains only data — no credentials, no boilerplate_run.py starts from assets/script_template.pyfinally (handled by ServiceLayer.__exit__)main(data, sl) implements the full logicsl.patch() for updates (not sl.post() or PUT)log.info()assets/spec/paths/{Resource}_id.yaml before patchingWhen the user asks to run a script:
.env files or environment variables beforehand. The script validates its own environment on startup and will print a clear error if credentials are missing..temp/ within that root, but cd to the repo root so that python-dotenv finds the .env file there./workspace/development/frappe-bench/env/bin/python.cd <main-repo-root>
/workspace/development/frappe-bench/env/bin/python .temp/<operation>_run.py
| Skill | When to use |
|---|---|
sap-schema-expert | Look up DB column names, table structure, and encoded values |
sap-di-api-expert | COM-based automation and read/write via DI API |
sap-dtw-expert | Bulk import/export via Data Transfer Workbench TSV files |
See REFERENCE.md for schema resolution strategies and ⚠️ property name / DB column mapping pitfalls.