### JavaScript/Node.js SAP Service Layer Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/quick-start.md This comprehensive example demonstrates how to set up a connection, authenticate, and perform common operations with the SAP Service Layer. It includes functions for login, logout, getting company info, listing customers, and creating sales orders. Use this as a starting point for your Node.js applications. ```javascript const https = require('https'); const config = { hostname: 'localhost', port: 50000, basePath: '/b1s/v2' }; let sessionId = null; // Helper function for requests async function request(method, path, body = null) { return new Promise((resolve, reject) => { const options = { hostname: config.hostname, port: config.port, path: config.basePath + path, method: method, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, rejectUnauthorized: false // Dev only! }; if (sessionId) { options.headers.Cookie = `B1SESSION=${sessionId}`; } const req = https.request(options, (res) => { let data = ''; res.on('data', chunk => data += chunk); res.on('end', () => { try { resolve({ status: res.statusCode, data: JSON.parse(data) }); } catch (e) { resolve({ status: res.statusCode, data: data }); } }); }); req.on('error', reject); if (body) req.write(JSON.stringify(body)); req.end(); }); } // Login async function login(username, password, company) { const res = await request('POST', '/Login', { UserName: username, Password: password, CompanyDB: company, Language: 1 }); if (res.status === 200) { sessionId = res.data.SessionID; console.log('✅ Logged in:', res.data.UserID); } else { throw new Error('Login failed'); } } // Logout async function logout() { await request('POST', '/Logout'); sessionId = null; console.log('✅ Logged out'); } // Get company info async function getCompanyInfo() { const res = await request('POST', '/CompanyService_GetCompanyInfo', {}); return res.data; } // List customers async function getCustomers(limit = 50) { const res = await request('GET', `/BusinessPartners?$filter=CardType eq 'cCustomer'&$top=${limit}`); return res.data.value; } // Create sales order async function createOrder(cardCode, items) { const res = await request('POST', '/SalesOrders', { CardCode: cardCode, DocDate: new Date().toISOString().split('T')[0], Lines: items }); return res.data; } // Usage (async () => { try { await login('manager', '1234', 'SBODemoUS'); const company = await getCompanyInfo(); console.log('Company:', company.CompanyName); const customers = await getCustomers(5); console.log('Customers:', customers.length); const order = await createOrder('C00001', [{ ItemCode: 'A00001', Quantity: 10, UnitPrice: 99.99, WarehouseCode: '01' }]); console.log('Order created:', order.DocumentNumber); await logout(); } catch (error) { console.error('Error:', error.message); } })(); ``` -------------------------------- ### HTTP Request Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md An example of a GET request including common required and optional headers. ```http GET /b1s/v2/CompanyService_GetCompanyInfo HTTP/1.1 Host: localhost:50000 Content-Type: application/json Accept: application/json Cookie: B1SESSION=e30e77d8-2b7d-4f7e-ab12-3c4d5e6f7a8b User-Agent: MyClient/1.0 ``` -------------------------------- ### Query and Filtering Examples Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Examples demonstrating how to query and filter data for various business objects. ```APIDOC ## Query and Filtering Examples ### Example 1: List Open Sales Orders for Specific Customer ``` GET /b1s/v2/SalesOrders? $filter=CardCode eq 'C00001' and DocStatus eq 'O' &$select=DocumentNumber,DocDate,Total &$orderby=DocDate desc ``` ### Example 2: Find Items Below Reorder Point ``` GET /b1s/v2/Items? $filter=InStock lt ReorderPoint and InventoryItem eq true &$select=ItemCode,ItemName,InStock,ReorderPoint &$top=50 ``` ### Example 3: Get Recent Approval Requests ``` POST /b1s/v2/ApprovalRequestsService_GetApprovalRequestList { "DocumentType": "SalesOrder", "Status": "Pending" } ``` ### Example 4: Retrieve Business Partner Contact Info ``` GET /b1s/v2/BusinessPartners? $filter=CardType eq 'cCustomer' and Active eq true &$select=CardCode,CardName,Phone,Email,City &$expand=BPAddresses &$top=20 ``` ``` -------------------------------- ### URL Structure Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/endpoints.md Illustrates the base URL pattern for SAP Service Layer OData endpoints and provides examples for GET and POST requests. ```text https://:/b1s/v2/{ServiceName}_{OperationName} ``` ```text GET https://localhost:50000/b1s/v2/CompanyService_GetCompanyInfo POST https://localhost:50000/b1s/v2/SalesOrdersService_GetSalesOrderList ``` -------------------------------- ### OData Pagination Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Example of using $top and $skip parameters for paginating results, retrieving a specific number of records starting from a certain position. ```odata $top=50&$skip=100 ``` -------------------------------- ### Example SAP Service Layer API Calls Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/overview.md Illustrates example GET and POST requests to specific SAP Service Layer API endpoints. ```http GET /b1s/v2/AccountCategoryService_GetCategoryList ``` ```http POST /b1s/v2/CompanyService_GetCompanyInfo ``` -------------------------------- ### Get Company Information Response Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Example response structure for retrieving company information, detailing fields like company name, database, currency, fiscal year, and bank accounts. ```json { "CompanyName": "My Company", "CompanyDB": "SBODemoUS", "LogoFile": "logo.bmp", "LogoFileSize": 5000, "CurrencyCode": "USD", "FiscalYear": 2024, "AccumulatedDepreciation": true, "InterimClosingPeriod": 3, "BankAccounts": [ { "BankAccountID": "1", "BankName": "First Bank", "AccountNumber": "123456789", "AccountCurrency": "USD" } ] } ``` -------------------------------- ### Example JSON Response for Change Log Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md This is an example of the JSON structure returned when querying for system changes. ```json { "value": [ { "LogID": 1001, "ObjectType": "SalesOrder", "ObjectKey": "50001", "Operation": "Update", "CreatedBy": "manager", "CreatedDate": "2024-06-30T14:30:00Z", "FieldName": "DocStatus", "OldValue": "Draft", "NewValue": "Open" } ] } ``` -------------------------------- ### Example Connection URLs Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md These are example URLs for connecting to the SAP Service Layer. Ensure you replace placeholders with your actual server details. ```text https://localhost:50000/b1s/v2/ ``` ```text https://sap-server.example.com:50000/b1s/v2/ ``` ```text https://192.168.1.100:50000/b1s/v2/ ``` -------------------------------- ### 404 Not Found - Resource Not Found Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/errors.md An example of a 'Not Found' error when a requested resource does not exist. Verify the resource ID and endpoint path. ```json { "error": { "code": "RESOURCE_NOT_FOUND", "message": { "lang": "en-us", "value": "Sales order with ID 99999 not found" } } } ``` -------------------------------- ### Create Pattern Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/README.md Example of how to create a new record, such as a Sales Order. ```APIDOC ## Create Pattern ### Description Shows the structure for creating a new record, using Sales Orders as an example. ### Method POST ### Endpoint /b1s/v2/{ServiceName} ### Request Body - **CardCode** (string) - Required - The business partner code. - **DocDate** (string) - Required - The document date in YYYY-MM-DD format. - **Lines** (array) - Required - An array of line items for the document. ### Request Example ```json { "CardCode": "C00001", "DocDate": "2024-06-30", "Lines": [ // ... line item details ... ] } ``` ``` -------------------------------- ### OData Count Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Example of using the $count parameter to retrieve the total number of records that match the query. ```odata $count=true ``` -------------------------------- ### Query Sales Orders with Filters Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/README.md Example of a GET request to retrieve sales orders based on specific criteria like document status and card code. Use $select to specify returned fields and $orderby for sorting. ```http GET /b1s/v2/SalesOrders? $filter=DocStatus eq 'O' and CardCode eq 'C00001' &$select=DocumentNumber,DocDate,Total &$orderby=DocDate desc &$top=50 ``` -------------------------------- ### OData Expand Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Example of using the $expand parameter to include related records in the response. ```odata $expand=Items,Activities ``` -------------------------------- ### OData Select Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Example of using the $select parameter to retrieve only specific columns. ```odata $select=ID,Name,Email ``` -------------------------------- ### OData Filter Examples Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Examples demonstrating how to filter data using various operators like 'eq', 'gt', 'startswith', and 'contains'. ```odata $filter=Name eq 'John' ``` ```odata $filter=Amount gt 1000 and Status eq 'Open' ``` ```odata $filter=startswith(Code, 'A') ``` -------------------------------- ### OData Batch Request Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Demonstrates how to group multiple OData operations into a single batch request for efficiency. ```http POST /b1s/v2/$batch HTTP/1.1 --batch_boundary Content-Type: application/http GET /b1s/v2/BusinessPartners(1) HTTP/1.1 --batch_boundary Content-Type: application/http POST /b1s/v2/SalesOrders HTTP/1.1 Content-Type: application/json {...} --batch_boundary-- ``` -------------------------------- ### Sales Order Response Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Example JSON response structure for listing sales orders, including document details and status. ```json { "@odata.context": "https://localhost:50000/b1s/v2/$metadata#SalesOrders", "value": [ { "DocumentEntry": 1, "DocumentNumber": 50001, "DocumentDate": "2024-06-30", "CustomerCode": "C00001", "CustomerName": "ACME Corp", "Total": 5000.00, "DocStatus": "O" } ] } ``` -------------------------------- ### Decimal Data Type Examples Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Examples of decimal data for numbers with configurable precision, used for monetary values and percentages. ```json "Amount": 1234.56 "UnitPrice": 99.99 "Discount": 0.10 ``` -------------------------------- ### String Data Type Examples Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Examples of string data used for text fields like names, descriptions, and codes. ```json "Name": "John Smith" "Description": "This is a description" "Code": "ABC123" ``` -------------------------------- ### OData Orderby Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Example of using the $orderby parameter to sort results by one or more fields in ascending or descending order. ```odata $orderby=Name asc,CreatedDate desc ``` -------------------------------- ### Query Pattern Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/README.md Example of how to query data using filters, selections, ordering, and top limits. ```APIDOC ## Query Pattern ### Description Demonstrates how to query data from a service, including filtering, selecting specific fields, ordering results, and limiting the number of records returned. ### Method GET ### Endpoint /b1s/v2/{ServiceName} ### Parameters #### Query Parameters - **$filter** (string) - Optional - Filters the results based on specified conditions. - **$select** (string) - Optional - Specifies which fields to include in the response. - **$orderby** (string) - Optional - Orders the results by one or more fields. - **$top** (integer) - Optional - Limits the number of records returned. ### Request Example ``` GET /b1s/v2/SalesOrders? $filter=DocStatus eq 'O' and CardCode eq 'C00001' &$select=DocumentNumber,DocDate,Total &$orderby=DocDate desc &$top=50 ``` ``` -------------------------------- ### Integer Data Type Examples Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Examples of integer data for whole numbers, including negative values, used for identifiers and quantities. ```json "ID": 1 "Quantity": 100 "LineNumber": -5 ``` -------------------------------- ### CompanyService_GetCompanyInfo Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/endpoints.md Retrieves company-wide configuration and settings. This operation provides details about the company's setup. ```APIDOC ## POST /b1s/v2/CompanyService_GetCompanyInfo ### Description Retrieves company-wide configuration and settings. ### Method POST ### Endpoint /b1s/v2/CompanyService_GetCompanyInfo ### Parameters ### Request Body ### Request Example ### Response #### Success Response (200) #### Response Example ``` -------------------------------- ### Action Pattern Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/README.md Example of how to invoke an action on a specific document, like cancelling a Sales Order. ```APIDOC ## Action Pattern ### Description Demonstrates how to invoke an action on a specific document, such as cancelling a Sales Order. ### Method POST ### Endpoint /b1s/v2/{ServiceName}_CancelDocument ### Request Body - **DocumentEntry** (integer) - Required - The entry number of the document to act upon. - **Memo** (string) - Optional - A memo or reason for the action. ### Request Example ```json { "DocumentEntry": 1, "Memo": "Cancellation reason" } ``` ``` -------------------------------- ### Percentage Data Type Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Represents percentages as decimal values between 0 and 100. Examples include discount percentages, tax rates, and commission percentages. ```json { "DiscountPercent": 10.50, "TaxRate": 19.00, "CommissionPercent": 5.25 } ``` -------------------------------- ### Create Customer Invoice Response (JSON) Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Example response upon successful creation of a customer invoice. It includes the DocumentEntry and DocumentNumber for reference. ```json { "@odata.context": "https://localhost:50000/b1s/v2/$metadata#Invoices/$entity", "DocumentEntry": 10, "DocumentNumber": 20001, "DocStatus": "O", "DocumentLines": [ { "LineNumber": 1, "ItemCode": "A00001", "Quantity": 5, "UnitPrice": 99.99, "TaxAmount": 95.00, "LineTotal": 594.95 } ], "DocumentTotal": 594.95 } ``` -------------------------------- ### Price List Type Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md An example of the Price List Type complex structure, used for sales and purchase pricing details. ```json { "PriceListID": 1, "PriceListName": "Retail", "Currency": "USD", "UnitPrice": 99.99, "DiscountPercent": 10.0, "DiscountAmount": 10.00, "FinalPrice": 89.99, "ValidFrom": "2024-01-01", "ValidTo": "2024-12-31", "IsActive": true } ``` -------------------------------- ### User-Defined Fields (UDF) Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Illustrates the structure for custom fields defined by users. Field names are prefixed with 'U_' and types vary based on configuration. ```json { "U_CustomField1": "Value", "U_CustomNumber": 123, "U_CustomDate": "2024-06-30", "U_CustomCheck": true } ``` -------------------------------- ### Date Data Type Examples Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Examples of Date data in ISO 8601 format, used for document dates and validity periods. ```json "DocumentDate": "2024-06-30" "DeliveryDate": "2024-07-15" "ExpiryDate": "2025-06-30" ``` -------------------------------- ### Address Type Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md An example of the Address Type complex structure, used in business partner and sales/purchase documents. ```json { "AddressType": "bo_BillTo", "StreetNo": "123", "StreetName": "Main Street", "Building": "Building A", "ZipCode": "12345", "City": "New York", "State": "NY", "Country": "US", "County": "New York", "Block": "Block 1", "Nullable": false } ``` -------------------------------- ### CashDiscountsService - Query Cash Discounts Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/endpoints.md Use POST to query cash discounts. GET is available for listing them. Supports create, update, and delete operations. ```http POST /b1s/v2/CashDiscountsService_GetList ``` -------------------------------- ### Item Master Data Response Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Example JSON response structure for a retrieved item master record, including details like item code, name, pricing, and inventory status. ```JSON { "value": [ { "ItemCode": "A00001", "ItemName": "Product 1", "ItemType": "itItem", "BasePrice": 99.99, "UnitOfMeasure": "PC", "Inventory": true, "SalesItem": true, "PurchaseItem": true, "InStock": 500.00, "ReorderPoint": 100.00, "ItemClass": "F", "WarehouseDetails": [ { "WarehouseCode": "01", "Quantity": 500.00, "InStock": 500.00 } ] } ] } ``` -------------------------------- ### DateTime Data Type Examples Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Examples of DateTime data in ISO 8601 format with timezone information, used for creation and modification timestamps. ```json "CreatedDate": "2024-06-30T14:30:00Z" "LastModifiedDate": "2024-06-30T14:30:00Z" "PostingDate": "2024-06-30T00:00:00Z" ``` -------------------------------- ### Example Response for Pending Approval Requests Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md This is an example response structure for pending approval requests, showing details like ApproverId, DocumentType, Status, and dates. ```json { "value": [ { "ApproverId": 1, "DocumentType": "SalesOrder", "DocumentKey": "50001", "Status": "Pending", "RequestDate": "2024-06-30", "DueDate": "2024-07-03" } ] } ``` -------------------------------- ### OData Resource Paths Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/quick-start.md Examples of OData resource paths for querying and invoking actions on various SAP Service Layer entities. ```text GET /b1s/v2/SalesOrders GET /b1s/v2/SalesOrders(1) POST /b1s/v2/SalesOrders_CancelDocument GET /b1s/v2/BusinessPartners?$filter=CardType eq 'cCustomer' ``` -------------------------------- ### Create Sales Order Response Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Example JSON response upon successful creation of a sales order, including its entry, number, and status. ```json { "@odata.context": "https://localhost:50000/b1s/v2/$metadata#SalesOrders/$entity", "DocumentEntry": 2, "DocumentNumber": 50002, "DocStatus": "O" } ``` -------------------------------- ### Configure HTTP Proxy Agent Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Use this snippet to configure an HTTP proxy for requests. Ensure the 'http-proxy-agent' module is installed. ```javascript const httpProxy = require('http-proxy-agent'); const httpsProxy = require('https-proxy-agent'); const agent = new httpsProxy('http://proxy.company.com:3128'); ``` -------------------------------- ### 403 Forbidden - Insufficient Permissions Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/errors.md Demonstrates a 'Forbidden' error when the authenticated user lacks the necessary permissions. Contact an administrator to resolve permission issues. ```json { "error": { "code": "INSUFFICIENT_PERMISSIONS", "message": { "lang": "en-us", "value": "User does not have permission to create sales orders" } } } ``` -------------------------------- ### Get Customer List with Filters Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/quick-start.md Retrieves a list of customers with specified filters for type, active status, and selected fields. Includes pagination. ```bash curl -X GET "https://localhost:50000/b1s/v2/BusinessPartners? $filter=CardType eq 'cCustomer' and Active eq true &$select=CardCode,CardName,Phone,Email &$top=50" \ -H "Cookie: B1SESSION=$SESSION_ID" ``` -------------------------------- ### EntityCollection Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Standard OData response structure for collections of multiple records. Includes metadata and the array of entities. ```json { "@odata.context": "https://localhost:50000/b1s/v2/$metadata#Items", "value": [ { /* Item 1 */ }, { /* Item 2 */ }, { /* Item 3 */ } ], "@odata.count": 150 } ``` -------------------------------- ### Empty Response Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Represents an OData response when no data is found or applicable. The 'value' property is null. ```json { "@odata.context": "https://localhost:50000/b1s/v2/$metadata#Edm.String", "value": null } ``` -------------------------------- ### POST Request Body Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/endpoints.md POST requests for actions typically require a JSON payload. Ensure all properties and nested objects are correctly formatted. ```json { "PropertyName1": "value1", "PropertyName2": 123, "ComplexProperty": { "NestedProperty": "value" } } ``` -------------------------------- ### List Sales Orders with Filtering Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Retrieve a list of sales orders using query parameters for filtering, sorting, and pagination. Example uses $filter, $orderby, and $top. ```http $filter=DocStatus eq 'O'&$orderby=DocDate desc&$top=50&$skip=0 ``` -------------------------------- ### AccountCategoryService - Query Account Categories Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/endpoints.md Use POST to query account categories. GET is available for retrieving a list. ```http POST /b1s/v2/AccountCategoryService_GetCategoryList ``` -------------------------------- ### JSON NULL Handling Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Demonstrates the use of null for optional fields in JSON requests and responses. Null indicates a field is not set or has no value. ```json { "OptionalField": null, "RequiredField": "value" } ``` -------------------------------- ### Get Company Information Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/quick-start.md Make a basic API call to retrieve company information using the obtained SessionID. This confirms a successful connection. ```bash curl -X POST https://localhost:50000/b1s/v2/CompanyService_GetCompanyInfo \ -H "Content-Type: application/json" \ -H "Cookie: B1SESSION=e30e77d8-2b7d-4f7e-ab12-3c4d5e6f7a8b" \ -d '{}' ``` -------------------------------- ### 400 Bad Request - Missing Required Field Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/errors.md Illustrates a 'Bad Request' error due to a missing required field. Ensure all mandatory fields are present in the request. ```json { "error": { "code": "MISSING_REQUIRED_FIELD", "message": { "lang": "en-us", "value": "Field 'DocumentDate' is required" } } } ``` -------------------------------- ### Quantity with Unit Data Type Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Used for inventory items, this type includes a quantity and its unit of measure. Common units are PC (Piece), BOX (Box), KG (Kilogram), LTR (Liter), M (Meter), HR (Hour), and DAY (Day). ```json { "Quantity": 100, "UnitOfMeasure": "PC", "UnitOfMeasureGroupCode": "TIME" } ``` -------------------------------- ### Get Company Information Request Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Use this snippet to retrieve complete company information, including settings, banking details, and configuration. The request body is empty. ```json {} ``` -------------------------------- ### AccountsService - Create Opening Balance Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/endpoints.md Use POST to create an opening balance for accounts, requiring GL accounts and an opening balance date. ```http POST /b1s/v2/AccountsService_CreateOpenBalance ``` -------------------------------- ### Filtering Type Specifications Examples Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Examples of using type-specific operators in $filter expressions for various data types. ```odata Code eq 'A0001' ``` ```odata Quantity gt 100 ``` ```odata Amount le 1000.50 ``` ```odata IsActive eq true ``` ```odata CreatedDate gt 2024-01-01 ``` ```odata DocumentDate eq 2024-06-30 ``` -------------------------------- ### Boolean Data Type Examples Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Examples of boolean data representing true or false values for flags and status indicators. ```json "IsActive": true "IsPrinted": false "IsApproved": true ``` -------------------------------- ### Retrieve System Changes with Filters Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Use this endpoint to retrieve a list of all system changes. You can filter by object type and creator, and order the results by creation date. The `$top` parameter limits the number of results. ```http GET /b1s/v2/ChangeLogsService_GetList $filter=ObjectType eq 'SalesOrder' and CreatedBy eq 'manager' &$orderby=CreatedDate desc&$top=100 ``` -------------------------------- ### Dimension Type Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md An example of the Dimension Type complex structure, used for tracking document dimensions like profit centers. ```json { "DimensionID": "ProfitCenter", "DimensionValue": "PC-001", "DimensionName": "Profit Center 1" } ``` -------------------------------- ### Python Client Configuration Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Configuration dictionary for the Python client library. Set 'verify_ssl' to True in production environments. ```python config = { 'service_url': 'https://localhost:50000/b1s/v2/', 'username': 'manager', 'password': '1234', 'company': 'SBODemoUS', 'verify_ssl': True } ``` -------------------------------- ### Tax Information Type Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md An example of the Tax Information Type complex structure, used in document line items for tax calculations. ```json { "TaxID": 1, "TaxCode": "VAT", "TaxRate": 19.0, "TaxAmount": 190.00, "TaxableAmount": 1000.00, "TaxType": "Output" } ``` -------------------------------- ### AccountsService_CreateOpenBalance Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/endpoints.md Creates an opening balance for accounts, including GL accounts and an opening balance date. ```APIDOC ## POST /b1s/v2/AccountsService_CreateOpenBalance ### Description Create opening balance for accounts with GL accounts and opening balance date. ### Method POST ### Endpoint /b1s/v2/AccountsService_CreateOpenBalance ``` -------------------------------- ### Enable Gzip Compression Header Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Includes the 'Accept-Encoding' header to request compressed responses from the server, reducing bandwidth usage. ```plaintext Accept-Encoding: gzip, deflate ``` -------------------------------- ### Create Order Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Creates a new sales order with specified customer, date, lines, and other details. ```APIDOC ## POST /b1s/v2/SalesOrders ### Description Create new sales order. ### Method POST ### Endpoint /b1s/v2/SalesOrders ### Parameters #### Request Body - **CardCode** (string) - Required - Customer code. - **DocDate** (date) - Required - Document date. - **DeliveryDate** (date) - Optional - Expected delivery date. - **Lines** (array) - Required - Line items (min 1). - **ItemCode** (string) - Required - Item code. - **Quantity** (number) - Required - Quantity of the item. - **UnitPrice** (number) - Required - Unit price of the item. - **WarehouseCode** (string) - Required - Code of the warehouse. - **Comments** (string) - Optional - Order comments. - **DocCurrency** (string) - Optional - Currency code. ### Request Example { "CardCode": "C00001", "DocDate": "2024-06-30", "DeliveryDate": "2024-07-15", "Lines": [ { "ItemCode": "A00001", "Quantity": 10, "UnitPrice": 99.99, "WarehouseCode": "01" } ], "Comments": "Expedite delivery", "DocCurrency": "USD" } ### Response #### Success Response (201 Created) - **@odata.context** (string) - Metadata context URL. - **DocumentEntry** (integer) - Unique identifier for the newly created document. - **DocumentNumber** (integer) - The sales order number. - **DocStatus** (string) - The status of the document (e.g., 'O' for Open). #### Response Example { "@odata.context": "https://localhost:50000/b1s/v2/$metadata#SalesOrders/$entity", "DocumentEntry": 2, "DocumentNumber": 50002, "DocStatus": "O" } ``` -------------------------------- ### Create New Customer Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/quick-start.md Creates a new customer record in the system with the provided details. ```APIDOC ## POST /b1s/v2/BusinessPartners ### Description Creates a new business partner record, specifically a customer, with the provided details including CardCode, CardName, CardType, Phone, and Email. ### Method POST ### Endpoint /b1s/v2/BusinessPartners ### Parameters #### Request Body - **CardCode** (string) - Required - The unique code for the business partner. - **CardName** (string) - Required - The name of the business partner. - **CardType** (string) - Required - The type of business partner (e.g., 'cCustomer'). - **Phone** (string) - Optional - The phone number of the business partner. - **Email** (string) - Optional - The email address of the business partner. ### Request Example ```json { "CardCode": "C99999", "CardName": "New Customer Inc", "CardType": "cCustomer", "Phone": "+1-555-0123", "Email": "contact@newcust.com" } ``` ### Request Example (curl) ```bash curl -X POST https://localhost:50000/b1s/v2/BusinessPartners \ -H "Content-Type: application/json" \ -H "Cookie: B1SESSION=$SESSION_ID" \ -d '{ "CardCode": "C99999", "CardName": "New Customer Inc", "CardType": "cCustomer", "Phone": "+1-555-0123", "Email": "contact@newcust.com" }' ``` ``` -------------------------------- ### Get Pending Approvals Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/quick-start.md Retrieves a list of open approval requests that are pending action. ```APIDOC ## POST /b1s/v2/ApprovalRequestsService_GetOpenApprovalRequestList ### Description Fetches a list of all open approval requests that are currently awaiting action or review. ### Method POST ### Endpoint /b1s/v2/ApprovalRequestsService_GetOpenApprovalRequestList ### Parameters #### Request Body This endpoint does not require any specific parameters in the request body; an empty JSON object is sent. ### Request Example ```json {} ``` ### Request Example (curl) ```bash curl -X POST https://localhost:50000/b1s/v2/ApprovalRequestsService_GetOpenApprovalRequestList \ -H "Content-Type: application/json" \ -H "Cookie: B1SESSION=$SESSION_ID" \ -d '{}' ``` ``` -------------------------------- ### Color Data Type Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/data-types.md Represents color using either an RGB hex code or a named color. ```json { "ColorCode": "FF0000", "ColorName": "Red" } ``` -------------------------------- ### Create Sales Order Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/quick-start.md Create a new sales order by sending a POST request with the necessary order details, including customer code, date, and line items. The SessionID must be provided in the Cookie header. ```bash curl -X POST https://localhost:50000/b1s/v2/SalesOrders \ -H "Content-Type: application/json" \ -H "Cookie: B1SESSION=e30e77d8-2b7d-4f7e-ab12-3c4d5e6f7a8b" \ -d '{ "CardCode": "C00001", "DocDate": "2024-06-30", "Lines": [ { "ItemCode": "A00001", "Quantity": 10, "UnitPrice": 99.99, "WarehouseCode": "01" } ] }' ``` -------------------------------- ### Configure Connection Pooling Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Sets up a persistent connection pool using Node.js 'https.Agent' for improved performance by reusing connections. ```javascript const agent = new https.Agent({ keepAlive: true, maxSockets: 50, maxFreeSockets: 10, timeout: 60000 }); ``` -------------------------------- ### BankChargesAllocationCodesService - Query Bank Charge Codes Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/endpoints.md Use POST to query bank charge codes. GET is available for retrieving them. ```http POST /b1s/v2/BankChargesAllocationCodesService_GetList ``` -------------------------------- ### GeneralLedgerService - Query GL Accounts Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/endpoints.md Use POST to query General Ledger accounts. GET is available for retrieving a list. ```http POST /b1s/v2/GeneralLedgerService_GetList ``` -------------------------------- ### List Open Orders for a Customer Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/quick-start.md Retrieves a list of open sales orders for a specific customer, ordered by document date in descending order. ```bash curl -X GET "https://localhost:50000/b1s/v2/SalesOrders? $filter=CardCode eq 'C00001' and DocStatus eq 'O' &$orderby=DocDate desc" \ -H "Cookie: B1SESSION=$SESSION_ID" ``` -------------------------------- ### Get Pending Approvals Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/quick-start.md Retrieves a list of open approval requests. This is an action that requires a POST request with an empty JSON body. ```bash curl -X POST https://localhost:50000/b1s/v2/ApprovalRequestsService_GetOpenApprovalRequestList \ -H "Content-Type: application/json" \ -H "Cookie: B1SESSION=$SESSION_ID" \ -d '{}' ``` -------------------------------- ### Staging Environment Configuration Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Configuration object for the staging environment, using a staging server URL and info logging. ```javascript const stagingConfig = { serviceUrl: 'https://staging-sap.example.com:50000/b1s/v2/', ssl: { rejectUnauthorized: true }, timeout: 30000, logging: 'info' }; ``` -------------------------------- ### 401 Unauthorized - Invalid Session Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/errors.md Shows an 'Unauthorized' error indicating an invalid or expired session. Re-authenticate to obtain a new session ID. ```json { "error": { "code": "INVALID_SESSION", "message": { "lang": "en-us", "value": "Session has expired. Please login again." } } } ``` -------------------------------- ### Get Item Inventory Levels Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/quick-start.md Retrieves inventory levels for items that are marked as inventory items. Selects specific fields and limits the results. ```bash curl -X GET "https://localhost:50000/b1s/v2/Items? $filter=InventoryItem eq true &$select=ItemCode,ItemName,InStock,ReorderPoint &$top=100" \ -H "Cookie: B1SESSION=$SESSION_ID" ``` -------------------------------- ### Create New Customer Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/quick-start.md Creates a new customer record in the SAP system. Requires Content-Type and Cookie headers, and a JSON payload with customer details. ```bash curl -X POST https://localhost:50000/b1s/v2/BusinessPartners \ -H "Content-Type: application/json" \ -H "Cookie: B1SESSION=$SESSION_ID" \ -d '{ "CardCode": "C99999", "CardName": "New Customer Inc", "CardType": "cCustomer", "Phone": "+1-555-0123", "Email": "contact@newcust.com" }' ``` -------------------------------- ### Test Filter Syntax Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/quick-start.md Use simple filters first, then progressively complex ones. Ensure correct operators like 'eq' are used instead of '='. ```plaintext Good: CardType eq 'cCustomer' Good: Active eq true and CardType eq 'cCustomer' Bad: CardType = 'cCustomer' (use eq, not =) Bad: CardType 'cCustomer' (missing operator) ``` -------------------------------- ### 405 Method Not Allowed Example Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/errors.md Illustrates a 'Method Not Allowed' error when an unsupported HTTP method is used on an endpoint. Consult the API documentation for correct methods. ```json { "error": { "code": "METHOD_NOT_ALLOWED", "message": { "lang": "en-us", "value": "PUT method not supported on this resource" } } } ``` -------------------------------- ### CompanyService_GetCompanyInfo Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Retrieves complete company information including settings, banking details, and configuration. ```APIDOC ## POST /b1s/v2/CompanyService_GetCompanyInfo ### Description Retrieves complete company information including settings, banking details, and configuration. ### Method POST ### Endpoint /b1s/v2/CompanyService_GetCompanyInfo ### Request Example ```json {} ``` ### Response #### Success Response (200) - **CompanyName** (string) - Company legal name - **CompanyDB** (string) - Database name - **LogoFile** (string) - Logo filename - **CurrencyCode** (string) - Default currency (USD, EUR, etc.) - **FiscalYear** (integer) - Current fiscal year - **BankAccounts** (array) - Configured bank accounts #### Response Example ```json { "CompanyName": "My Company", "CompanyDB": "SBODemoUS", "LogoFile": "logo.bmp", "LogoFileSize": 5000, "CurrencyCode": "USD", "FiscalYear": 2024, "AccumulatedDepreciation": true, "InterimClosingPeriod": 3, "BankAccounts": [ { "BankAccountID": "1", "BankName": "First Bank", "AccountNumber": "123456789", "AccountCurrency": "USD" } ] } ``` ``` -------------------------------- ### Create Item Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Create a new item in the system. Requires essential details like ItemCode, ItemName, and ItemType, with optional fields for pricing, classification, and inventory tracking. ```APIDOC ## POST /b1s/v2/Items ### Description Create new item with pricing and classification. ### Method POST ### Endpoint /b1s/v2/Items ### Request Body - **ItemCode** (string) - Required - Unique item identifier - **ItemName** (string) - Required - Item description - **ItemType** (string) - Optional - `itItem` (standard) or `itGroup` - **UnitOfMeasure** (string) - Optional - e.g., PC, BOX, KG - **BasePrice** (decimal) - Optional - Standard selling price - **SalesItem** (boolean) - Optional - Available for sale - **PurchaseItem** (boolean) - Optional - Can be purchased - **InventoryItem** (boolean) - Optional - Tracked in inventory - **ItemClass** (string) - Optional - Product classification - **ItemGroupCode** (integer) - Optional - Item group code ### Request Example ```json { "ItemCode": "B00001", "ItemName": "New Product", "ItemType": "itItem", "UnitOfMeasure": "BOX", "BasePrice": 49.99, "SalesItem": true, "PurchaseItem": true, "InventoryItem": true, "ItemClass": "F", "ItemGroupCode": 100 } ``` ``` -------------------------------- ### BankStatementsService - Query Bank Statements Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/endpoints.md Use POST to query bank statements. GET is available for retrieving them. Supports management of bank statement reconciliation. ```http POST /b1s/v2/BankStatementsService_GetList ``` -------------------------------- ### Create Business Partner Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/common-services.md Create a new customer or vendor. The request body must include essential fields like CardCode, CardName, CardType, and GroupCode. BPAddresses can be an array for multiple addresses. ```json { "CardCode": "V00001", "CardName": "New Vendor Corp", "CardType": "cVendor", "Phone": "+1-555-0124", "Email": "vendor@company.com", "BPAddresses": [ { "AddressType": "bo_BillTo", "StreetName": "456 Oak Ave", "City": "Los Angeles", "ZipCode": "90001", "Country": "US" } ], "GroupCode": 101 } ``` -------------------------------- ### Production Environment Configuration Source: https://github.com/yeshua-aguilar/sap-servicelayer-docs/blob/main/_autodocs/configuration.md Configuration object for the production environment, featuring a production server URL, shorter timeout, warning logging, and circuit breaker enabled. ```javascript const prodConfig = { serviceUrl: 'https://prod-sap.example.com:50000/b1s/v2/', ssl: { rejectUnauthorized: true }, timeout: 15000, logging: 'warn', circuitBreaker: true }; ```