SAP Service Layer Expert
Quick start
- Read SESSION.md for the complete
ServiceLayercontext-manager class. - Copy
assets/script_template.pyas the starting point for every new script. - Look up endpoint schemas in
assets/spec/paths/{ResourceName}.yamlfor field names. - Check ENDPOINTS.md for available HTTP methods and action functions per resource.
- See REFERENCE.md for base URL/auth, OData params, HTTP semantics, document chaining, and schema resolution strategies.
Two-file output contract
Every mutation script ships exactly two files under .temp/ in the repo root:
| 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)
Script checklist
- Derive repo root from workspace context; create
.temp/if needed -
_data.jsoncontains only data — no credentials, no boilerplate -
_run.pystarts fromassets/script_template.py - Always use PATCH (not PUT) for partial updates
- Log out in
finally(handled byServiceLayer.__exit__) -
main(data, sl)implements the full logic - Use
sl.patch()for updates (notsl.post()or PUT) - Log each record processed with
log.info() - Verify key field names against
assets/spec/paths/{Resource}_id.yamlbefore patching - After creating both files, tell the user they can review and ask you to run the script
Running a script
When the user asks to run a script:
- Run it directly — do not check for
.envfiles or environment variables beforehand. The script validates its own environment on startup and will print a clear error if credentials are missing. - Working directory: the main repo root (derived from workspace context — the app folder that owns the current task). Scripts live under
.temp/within that root, butcdto the repo root so thatpython-dotenvfinds the.envfile there. - Python interpreter: use the bench virtualenv Python at
/workspace/development/frappe-bench/env/bin/python.
cd <main-repo-root>
/workspace/development/frappe-bench/env/bin/python .temp/<operation>_run.py
Related skills
| 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.