Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Azure-Samples/functions-javascript-sap-cloud-sdk-quickstart

Sample project showcasing SAP Cloud SDK for OData consumption from SAP S4 with Azure Functions
https://github.com/Azure-Samples/functions-javascript-sap-cloud-sdk-quickstart

app-service azd-templates azure azure-functions odata sample-code sap-cloud-sdk

Last synced: 3 months ago
JSON representation

Sample project showcasing SAP Cloud SDK for OData consumption from SAP S4 with Azure Functions

Awesome Lists containing this project

README

        

---
page_type: sample
languages:
- azdeveloper
- typescript
- bicep
- hcl
- powershell
products:
- azure
- azure-monitor
- azure-key-vault
- azure-functions
- azure-api-management
urlFragment: functions-javascript-sap-cloud-sdk-quickstart
name: SAP Cloud SDK on Azure Functions Quickstart
description: Quick-start project showcasing SAP Cloud SDK for JavaScript for SAP OData running on Azure Functions.
---

# SAP Cloud SDK on Azure Functions Quickstart🚀

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=az-function-quickstart&repo=704534226)

This repos serves as quick-start project showcasing [SAP Cloud SDK for JavaScript](https://sap.github.io/cloud-sdk/docs/js/tutorials/getting-started/introduction) OData consumption running on [Azure Functions](https://learn.microsoft.com/azure/azure-functions/functions-overview?pivots=programming-language-javascript). Its primary purpose is to set you up for success for your SAP extension project on Azure and reduce the lead time to your first successful deployment as much as possible with developer friendly commands.

It uses the [Business Partner OData v2 API](https://api.sap.com/api/OP_API_BUSINESS_PARTNER_SRV/overview) for SAP S/4HANA as an example.

The project is setup as per the best practices advocated by the [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview) and referenced as [official awesome azd template](https://azure.github.io/awesome-azd/?tags=sapcloudsdk).

Looking for Azure App Service instead of Functions?🤔 Here you [go](https://github.com/Azure-Samples/app-service-javascript-sap-cloud-sdk-quickstart).

![Illustration of app setup in Azure](assets/project-overview-azd-style-functions.png)

> [!WARNING]
> Verify latest [SAP's open-source license](https://sap.github.io/cloud-sdk/docs/overview/overview-cloud-sdk#license) for the Cloud SDK for your reference.

> [!TIP]
> - In case you need to translate between OData versions and metadata specification use our converter [here](https://aka.ms/ODataOpenAPI).
> - Looking for [SAP Cloud Application Programming model](https://cap.cloud.sap/docs/) instead of plain SAP Cloud SDK? See [this sister project](https://github.com/Azure-Samples/app-service-javascript-sap-cap-quickstart).
> - In case you prefer an implementation without 3rd party library dependencies, have a look at [this sister project](https://github.com/Azure/azure-sdk-for-sap-odata).
> - Looking for SAP Cloud SDK for Java? See this [SAP repos](https://github.com/SAP/cloud-sdk-java).

## Features ⚙️

Implementations using the approach described by this repos expand the [feature scope](https://sap.github.io/cloud-sdk/docs/overview/cloud-sdk-feature-matrix) of SAP's Cloud SDK for JavaScript to Azure PaaS apps.

> [!IMPORTANT]
> When deployed on Azure Functions instead of SAP Business Technology Platform, Cloud Foundry specific features like the destination service or XSUAA are not available.

* One code base to run on both Azure Functions and SAP Business Technology Platform
* Built in [resiliency](https://learn.microsoft.com/azure/architecture/reference-architectures/app-service-web-app/multi-region) and caching patterns
* Native [Azure authentication and token handling](https://learn.microsoft.com/azure/app-service/configure-authentication-provider-aad) with Azure AD without any coding effort
* Configurable Azure API Management integration for SAP APIs including policy enforcement for use cases like request throttling, SAP token caching, etc.
* Native [Azure virtual network integration](https://learn.microsoft.com/azure/app-service/configure-vnet-integration-enable) next to the SAP workload
* Enabled for [SAP Private Link](https://help.sap.com/docs/PRIVATE_LINK/42acd88cb4134ba2a7d3e0e62c9fe6cf/e9cc67716a3a41c9885862661e6c4234.html) and [Azure Private Link / Private Endpoint](https://learn.microsoft.com/azure/app-service/networking/private-endpoint?source=recommendations) (depending on wether you use the SAP Business Technology Platform or Azure only)
* OData v2 and v4 + entity and client generator managed by SAP
* OpenAPI + client generator managed by SAP

Example uses the NEST framework module [azure-func-http](https://github.com/nestjs/azure-func-http) compatible with Azure Functions runtime v3.

## Getting Started 🛫

### Prerequisites & Installation

Follow the [SAP Cloud SDK documentation for JavaScript](https://sap.github.io/cloud-sdk/docs/js/tutorials/getting-started/introduction) for your project setup.

Use the devcontainer (with GitHub Codespaces for instance) or install the [Azure Developer CLI](https://aka.ms/azd-install) in your environment.

Use any OData enabled SAP system:

* SAP's [ABAP Platform Trial image](https://hub.docker.com/r/sapse/abap-cloud-developer-trial),
* SAP's [mock server](https://github.com/SAP-archive/cloud-s4-sdk-book/tree/mock-server) (used in screenshots below),
* SAP API Business Hub [S/4HANA Cloud sandbox with APIKey](https://api.sap.com/api/API_BUSINESS_PARTNER/tryout) (⚠️read-only)
* SAP's [public demo system ES5](https://developers.sap.com/tutorials/gateway-demo-signup.html) (⚠️Business Partner API not activated!),
* S/4HANA Fully-Activated Appliance from [SAP Cloud Appliance Library](https://cal.sap.com/) or
* your own available in-house SAP system.

> [!IMPORTANT]
> Be aware that SAP's mock server is anticipating the S4 Cloud version of the Business Partner API. So, you might need to adapt the mock server to your needs. During our testing at the time of release there were no discrepancies discovered. You may expose the mock server running locally for testing with the cloud services to the internet using [ngrok](https://ngrok.com/) or similar tools.

[![GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=576207479) to hit the ground running with our tailored image and avoid installing anything on your local machine and continue with step 6.

### Quickstart 🚀

Familiarize yourself with the [SAP Cloud SDK for JavaScript developer tutorial](https://sap.github.io/cloud-sdk/docs/js/tutorials/getting-started/introduction)

#### Deploy time

0. Run `azd auth login`.

1. Run the following command to package a deployable copy of your application, provision the template's infrastructure to Azure and also deploy the application code to those newly provisioned resources.

```bash
azd up
```

This command will prompt you for the following information:

- `Azure Location`: The Azure location where your resources will be deployed.
- `Azure Subscription`: The Azure Subscription where your resources will be deployed.

> [!NOTE]
> This may take a while to complete as it executes three commands: `azd package` (packages a deployable copy of your application), `azd provision` (provisions Azure resources), and `azd deploy` (deploys application code). You will see a progress indicator as it packages, provisions and deploys your application.

#### Dev time

2. Select suitable [VS Code workspace](https://code.visualstudio.com/docs/editor/workspaces). We suggest [bicep](workspaces/azd-bicep.code-workspace) as it is the default for Azure Developer CLI.
3. `cd functions-javascript-sap-cloud-sdk-quickstart/src/api`
4. `npm install`
5. `cp ../../templates/.env ./.env` and maintain your OData url including credentials
6. `npm run start:azure`
7. Browse to [http://localhost:8080/api/](http://localhost:8080/api/) for your "hello world"
8. Maintain your SAP OData url with credentials in [.env](templates/.env) file (put in project root `functions-javascript-sap-cloud-sdk-quickstart/src/api`) and restart the app if necessary
9. Browse to [http://localhost:8080/api/business-partner](http://localhost:8080/api/business-partner) for your first OData call and pick one of the business partners (examples below use ids from SAP mock server)

> [!NOTE]
> SAP's examples for the business partner API for SAP S/4HANA Cloud mentioned in the tutorial **differ** to the SAP S/4HANA on-premises flavor. Add AddressUsage, otherwise you will see "Internal error when calling operation module BUA_CHECK_ADDRESS_VALIDITY_ALL; a check table is missing". Check SAP KBA's for more details.

10. Get that business partner by id: [http://localhost:8080/api/business-partner/1003764](http://localhost:8080/api/business-partner/1003764)

![screenshot of successful business partner retrieval by id](assets/bupa-get-vsc-rest.png)

11. Update the address with a house number: [http://localhost:8080/api/business-partner/1003764/address/28238](http://localhost:8080/api/business-partner/1003764/address/28238).

> [!NOTE]
> For your convenience we provide a [collection of REST calls](/sample-http-requests/business-partner-requests.http) in the repos. Execute them with the [VS Code REST client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client).

![screenshot of business partner address update with request details](assets/bupa-update-vsc-rest.png)

12. Delete the address: [http://localhost:8080/api/business-partner/1003764/address/28238](http://localhost:8080/api/business-partner/1003764/address/28238)

![screenshot of business partner address delete](assets/bupa-delete-vsc-rest.png)

13. Add an address to your chosen business partner: [http://localhost:8080/api/business-partner/1003764/address](http://localhost:8080/api/business-partner/1003764/address)

![screenshot of successful business partner address creation with request details](assets/bupa-create-vsc-rest.png)

**Congratulations** 🥳, you have successfully consumed SAP OData with the SAP Cloud SDK for JavaScript running on Azure Functions!

## Deploy to Azure 🪂

There are multiple ways to deploy this project to Azure. We provide two options in this repository:

1. Via template deployment and VS Code extension. This approach allows an quick deployment to Azure but does not necessarily reflect the best practices. You find more information on this option [here](documentation/DEPLOYMENT-VSCODE.md).
2. Via [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview) using `azd up`. This approach enables a quick and easy deployment and already contains best practices. It serves as a perfect starting point for a production grade setup. You find more information on this option [here](documentation/DEPLOYMENT-AZD.md).

## Deploy to SAP BTP 🪂

This repos build on functions is not configured to be deployed to SAP Business Technology Platform as is. We provide the necessary configurations for the deployment to SAP BTP leveraging the open source project [btp setup automator](https://github.com/SAP-samples/btp-setup-automator) for Azure App Service [here](https://github.com/Azure-Samples/app-service-javascript-sap-cloud-sdk-quickstart#deploy-to-sap-btp-).

## What's next?

You can do a lot more once the app is deployed. Curious? We go you covered with some more information on **out-of-the-box authentication** with Microsoft Entra ID, insights into networking, OpenUI5 for frontend design, and DevOps [here](documentation/WHATS-NEXT.md).

## Troubleshooting 🩺

Sometimes things do not work as expected. Here are some resources that support you in finding and fixing the issue:

* [Access SAP Gateway logs in /IWFND/ERROR_LOG](https://wiki.scn.sap.com/wiki/display/ABAPConn/SAP+Gateway+Error+Log)
* [Azure Functions diagnostics](https://learn.microsoft.com/azure/azure-functions/functions-diagnostics)
* Use [Kudu SSH console](https://learn.microsoft.com/azure/app-service/resources-kudu) from VNet integrated Functions to check connectivity to SAP Gateway with `curl https://:/sap/opu/odata/sap/API_BUSINESS_PARTNER -u ":"`
* [Azure API Management Request tracing](https://learn.microsoft.com/azure/api-management/api-management-howto-api-inspector)
* [Azure API Management Gateway logs](https://learn.microsoft.com/azure/api-management/api-management-howto-use-azure-monitor#view-diagnostic-data-in-azure-monitor)

## Additional resources

We collected additional resources and related efforts and projects [here](documentation/ADDITIONAL-RESOURCES.md).

## Contributing 👩🏼‍🤝‍👨🏽

This project welcomes contributions and suggestions. Please use [GitHub Issues](https://github.com/Azure-Samples/functions-javascript-sap-cloud-sdk-quickstart/issues) to report errors or request new features. For conceptual conversations, please use [GitHub Discussions](https://github.com/Azure-Samples/app-service-javascript-sap-cloud-sdk-quickstart/discussions/categories/ideas)

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

## Trademarks™

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.