|
| 1 | +--- |
| 2 | +title: Import an SAP API using the Azure portal | Microsoft Docs |
| 3 | +titleSuffix: |
| 4 | +description: Learn how to import OData metadata from SAP as an API to Azure API Management |
| 5 | +ms.service: api-management |
| 6 | +author: martinpankraz |
| 7 | +ms.author: mapankra |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 01/26/2022 |
| 10 | +ms.custom: |
| 11 | +--- |
| 12 | + |
| 13 | +# Import SAP OData metadata as an API |
| 14 | + |
| 15 | +This article shows how to import an OData service using its metadata description. In this article, [SAP Gateway](https://help.sap.com/viewer/product/SAP_GATEWAY) serves as an example. However, you can apply the approach to any OData-compliant service. |
| 16 | + |
| 17 | +In this article, you'll: |
| 18 | +> [!div class="checklist"] |
| 19 | +> * Convert OData metadata to an OpenAPI specification |
| 20 | +> * Import the OpenAPI specification to API Management |
| 21 | +> * Complete API configuration |
| 22 | +> * Test the API in the Azure portal |
| 23 | +
|
| 24 | +## Prerequisites |
| 25 | + |
| 26 | +- An existing API Management instance. [Create one if you haven't already](get-started-create-service-instance.md). |
| 27 | +- An SAP system and service exposed as OData v2 or v4. |
| 28 | +- If your SAP backend uses a self-signed certificate (for test purposes), you may need to disable the verification of the trust chain for SSL. To do so, configure a [backend](backends.md) in your API Management instance: |
| 29 | + 1. In the Azure portal, under **APIs**, select **Backends** > **+ Add**. |
| 30 | + 1. Add a **Custom URL** pointing to the SAP backend service. |
| 31 | + 1. Uncheck **Validate certificate chain** and **Validate certificate name**. |
| 32 | + |
| 33 | + > [!NOTE] |
| 34 | + > For production scenarios, use proper certificates for end-to-end SSL verification. |
| 35 | +
|
| 36 | +## Convert OData metadata to OpenAPI JSON |
| 37 | + |
| 38 | +1. Retrieve metadata XML from your SAP service. Use one of these methods: |
| 39 | + |
| 40 | + * Use the SAP Gateway Client (transaction `/IWFND/GW_CLIENT`), or |
| 41 | + * Make a direct HTTP call to retrieve the XML: |
| 42 | + `http://<OData server URL>:<port>/<path>/$metadata`. |
| 43 | + |
| 44 | +1. Convert the OData XML to OpenAPI JSON format. Use an OASIS open-source tool for [OData v2](https://github.com/oasis-tcs/odata-openapi/tree/main/tools) or [OData v4](https://github.com/oasis-tcs/odata-openapi/tree/main/lib), depending on your metadata XML. |
| 45 | + |
| 46 | + The following is an example command to convert OData v2 XML for the test service `epm_ref_apps_prod_man_srv`: |
| 47 | + |
| 48 | + ```console |
| 49 | + odata-openapi -p --basePath '/sap/opu/odata/sap/epm_ref_apps_prod_man_srv' \ |
| 50 | + --scheme https --host <your IP address>:<your SSL port> \ |
| 51 | + ./epm_ref_apps_prod_man_srv.xml |
| 52 | + ``` |
| 53 | + > [!NOTE] |
| 54 | + > * For test purposes with a single XML file, you can use a [web-based converter](https://aka.ms/ODataOpenAPI) based on the open-source tool. |
| 55 | + > * With the tool or the web-based converter, specifying the \<IP address>:\<port> of your SAP OData server is optional. Alternatively, add this information later in your generated OpenAPI specification or after importing to API Management. |
| 56 | +
|
| 57 | +1. Save the `openapi-spec.json` file locally for import to API Management. |
| 58 | + |
| 59 | +[!INCLUDE [api-management-navigate-to-instance](../../includes/api-management-navigate-to-instance.md)] |
| 60 | + |
| 61 | +## Import and publish backend API |
| 62 | + |
| 63 | +1. From the side navigation menu, under the **APIs** section, select **APIs**. |
| 64 | +1. Under **Create a new definition**, select **OpenAPI specification**. |
| 65 | + |
| 66 | + :::image type="content" source="./media/import-api-from-oas/oas-api.png" alt-text="OpenAPI specifiction"::: |
| 67 | + |
| 68 | +1. Click **Select a file**, and select the `openapi-spec.json` file that you saved locally in a previous step. |
| 69 | + |
| 70 | +1. Enter API settings. You can set the values during creation or configure them later by going to the **Settings** tab. |
| 71 | + * In **API URL suffix**, we recommend using the same URL path as in the original SAP service. |
| 72 | + |
| 73 | + * For more information about API settings, see [Import and publish your first API](import-and-publish.md#import-and-publish-a-backend-api) tutorial. |
| 74 | + |
| 75 | +1. Select **Create**. |
| 76 | + |
| 77 | +> [!NOTE] |
| 78 | +> The API import limitations are documented in [another article](api-management-api-import-restrictions.md). |
| 79 | +
|
| 80 | + |
| 81 | +## Complete API configuration |
| 82 | + |
| 83 | +[Add](add-api-manually.md#add-and-test-an-operation) the following three operations to the API that you imported. |
| 84 | + |
| 85 | +- `GET /$metadata` |
| 86 | + |
| 87 | + |Operation |Description |Further configuration for operation | |
| 88 | + |---------|---------|---------| |
| 89 | + |`GET /$metadata` | Enables API Management to reach the `$metadata` endpoint, which is required for client integration with the OData server.<br/><br/>This required operation isn't included in the OpenAPI specification that you generated and imported. | Add a `200 OK` response. | |
| 90 | + |
| 91 | + :::image type="content" source="media/sap-api/get-metadata-operation.png" alt-text="Get metadata operation"::: |
| 92 | + |
| 93 | +- `HEAD /` |
| 94 | + |
| 95 | + |Operation |Description |Further configuration for operation | |
| 96 | + |---------|---------|---------| |
| 97 | + |`HEAD /` | Enables the client to exchange Cross Site Request Forgery (CSRF) tokens with the SAP server, when required.<br/><br/>SAP also allows CSRF token exchange using the GET verb.<br/><br/> CSRF token exchange isn’t covered in this article. See an example API Management [policy snippet](https://github.com/Azure/api-management-policy-snippets/blob/master/examples/Get%20X-CSRF%20token%20from%20SAP%20gateway%20using%20send%20request.policy.xml) to broker token exchange. | N/A | |
| 98 | + |
| 99 | + :::image type="content" source="media/sap-api/head-root-operation.png" alt-text="Operation to fetch tokens"::: |
| 100 | + |
| 101 | +- `GET /` |
| 102 | + |
| 103 | + Operation |Description |Further configuration for operation | |
| 104 | + |---------|---------|---------| |
| 105 | + |`GET /` | Enables policy configuration at service root. | Configure the following inbound [rewrite-uri](api-management-transformation-policies.md#RewriteURL) policy to append a trailing slash to requests that are forwarded to service root:<br/><br> `<rewrite-uri template="/" copy-unmatched-params="true" />` <br/><br/>This policy removes potential ambiguity of requests with or without trailing slashes, which are treated differently by some backends.| |
| 106 | + |
| 107 | + :::image type="content" source="media/sap-api/get-root-operation.png" alt-text="Get operation for service root"::: |
| 108 | + |
| 109 | +Also, configure authentication to your backend using an appropriate method for your environment. For examples, see [API Management authentication policies](api-management-authentication-policies.md). |
| 110 | + |
| 111 | +## Test your API |
| 112 | + |
| 113 | +1. Navigate to your API Management instance. |
| 114 | +1. From the side navigation menu, under the **APIs** section, select **APIs**. |
| 115 | +1. Under **All APIs**, select your imported API. |
| 116 | +1. Select the **Test** tab to access the test console. |
| 117 | +1. Select an operation, enter any required values, and select **Send**. |
| 118 | + |
| 119 | + For example, test the `GET /$metadata` call to verify connectivity to the SAP backend |
| 120 | +1. View the response. To troubleshoot, [trace](api-management-howto-api-inspector.md) the call. |
| 121 | +1. When testing is complete, exit the test console. |
| 122 | + |
| 123 | +## Production considerations |
| 124 | + |
| 125 | +* See an [example end-to-end scenario](https://blogs.sap.com/2021/08/12/.net-speaks-odata-too-how-to-implement-azure-app-service-with-sap-odata-gateway/) to integrate API Management with an SAP gateway. |
| 126 | +* Control access to an SAP backend using API Management policies. See policy snippets for [SAP principal propagation](https://github.com/Azure/api-management-policy-snippets/blob/master/examples/Request%20OAuth2%20access%20token%20from%20SAP%20using%20AAD%20JWT%20token.xml) and [fetching an X-CSRF token](https://github.com/Azure/api-management-policy-snippets/blob/master/examples/Get%20X-CSRF%20token%20from%20SAP%20gateway%20using%20send%20request.policy.xml). |
| 127 | +* For guidance to deploy, manage, and migrate APIs at scale, see: |
| 128 | + * [Automated API deployments with APIOps](/architecture/example-scenario/devops/automated-api-deployments-apiops) |
| 129 | + * [CI/CD for API Management using Azure Resource Manager templates](devops-api-development-templates.md). |
| 130 | + |
| 131 | +[!INCLUDE [api-management-define-api-topics.md](../../includes/api-management-define-api-topics.md)] |
| 132 | + |
| 133 | +## Next steps |
| 134 | +> [!div class="nextstepaction"] |
| 135 | +> [Transform and protect a published API](transform-api.md) |
0 commit comments