Skip to content

Commit 3bbe265

Browse files
authored
Merge pull request #232082 from dlepow/ppcors
[APIM] CORS to test custom connector
2 parents ca3e272 + 47b8baa commit 3bbe265

File tree

4 files changed

+97
-11
lines changed

4 files changed

+97
-11
lines changed

articles/api-management/TOC.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@
240240
href: backends.md
241241
- name: Automate API deployments
242242
href: /azure/architecture/example-scenario/devops/automated-api-deployments-apiops?toc=%2Fazure%2Fapi-management%2Ftoc.json&bc=/azure/api-management/breadcrumb/toc.json
243-
- name: Test and monitor APIs in Postman
244-
href: export-api-postman.md
245-
displayName: collection
246243
- name: Cache
247244
items:
248245
- name: Add caching to improve performance
@@ -358,8 +355,17 @@
358355
href: developer-portal-alternative-processes-self-host.md
359356
- name: Test self-hosted portal
360357
href: developer-portal-testing.md
361-
- name: Export APIs to the Power Platform
362-
href: export-api-power-platform.md
358+
- name: Export APIs
359+
items:
360+
- name: Test and monitor APIs in Postman
361+
href: export-api-postman.md
362+
displayName: collection
363+
- name: Export APIs to the Power Platform
364+
items:
365+
- name: Export API as custom connector
366+
href: export-api-power-platform.md
367+
- name: Enable CORS to test custom connector
368+
href: enable-cors-power-platform.md
363369
- name: Monitor APIs
364370
items:
365371
- name: Get API analytics
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Enable CORS policies to test Azure API Management custom connector
3+
description: How to enable CORS policies in Azure API Management and Power Platform to test a custom connector from Power Platform applications.
4+
services: api-management
5+
author: dlepow
6+
7+
ms.service: api-management
8+
ms.topic: how-to
9+
ms.date: 03/24/2023
10+
ms.author: danlep
11+
12+
---
13+
# Enable CORS policies to test custom connector from Power Platform
14+
Cross-origin resource sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, or port) other than its own from which a browser should permit loading resources. Customers can add a [CORS policy](cors-policy.md) to their web APIs in Azure API Management, which adds cross-origin resource sharing support to an operation or an API to allow cross-domain calls from browser-based clients.
15+
16+
If you've exported an API from API Management as a [custom connector](export-api-power-platform.md) in the Power Platform and want to use the Power Apps or Power Automate test console to call the API, you need to configure your API to explicitly enable cross-origin requests from Power Platform applications. This article shows you how to configure the following two necessary policy settings:
17+
18+
* Add a CORS policy to your API
19+
20+
* Add a policy to your custom connector that sets an Origin header on HTTP requests
21+
22+
## Prerequisites
23+
24+
+ Complete the following quickstart: [Create an Azure API Management instance](get-started-create-service-instance.md)
25+
+ Export an API from your API Management instance to a Power Platform environment as a [custom connector](export-api-power-platform.md)
26+
27+
## Add CORS policy to API in API Management
28+
29+
Follow these steps to configure the CORS policy in API Management.
30+
31+
1. Sign into [Azure portal](https://portal.azure.com) and go to your API Management instance.
32+
1. In the left menu, select **APIs** and select the API that you exported as a custom connector. If you want to, select only an API operation to apply the policy to.
33+
1. In the **Policies** section, in the **Inbound processing** section, select **+ Add policy**.
34+
1. Select **Allow cross-origin resource sharing (CORS)**.
35+
1. Add the following **Allowed origin**: `https://make.powerapps.com`.
36+
1. Select **Save**.
37+
38+
* For more information about configuring a policy, see [Set or edit policies](set-edit-policies.md).
39+
* For details about the CORS policy, see the [cors](cors-policy.md) policy reference.
40+
41+
> [!NOTE]
42+
> If you already have an existing CORS policy at the service (all APIs) level to enable the test console of the developer portal, you can add the `https://make.powerapps.com` origin to that policy instead of configuring a separate policy for the API or operation.
43+
44+
> [!NOTE]
45+
> Depending on how the custom connector gets used in Power Platform applications, you might need to configure additional origins in the CORS policy. If you experience CORS problems when running Power Platform applications, use developer tools in your browser, tracing in API Management, or Application Insights to investigate the issues.
46+
47+
48+
## Add policy to custom connector to set Origin header
49+
50+
Add the following policy to your custom connector in your Power Platform environment. The policy sets an Origin header to match the CORS origin you allowed in API Management.
51+
52+
For details about editing settings of a custom connector, see [Create a custom connector from scratch](/connectors/custom-connectors/define-blank).
53+
54+
1. Sign in to Power Apps or Power Automate.
55+
1. On the left pane, select **Data** > **Custom Connectors**.
56+
1. Select your connector from the list of custom connectors.
57+
1. Select the pencil (Edit) icon to edit the custom connector.
58+
1. Select **3. Definition**.
59+
1. In **Policies**, select **+ New policy**. Select or enter the following policy details.
60+
61+
62+
|Setting |Value |
63+
|---------|---------|
64+
|Name | A name of your choice, such as **set-origin-header** |
65+
|Template | **Set HTTP header** |
66+
|Header name | **Origin** |
67+
|Header value | `https://make.powerapps.com` (same URL that you configured in API Management) |
68+
|Action if header exists | **override** |
69+
|Run policy on | **Request** |
70+
71+
:::image type="content" source="media/enable-cors-power-platform/cors-policy-power-platform.png" alt-text="Screenshot of creating policy in Power Platform custom connector to set an Origin header in HTTP requests.":::
72+
73+
1. Select **Update connector**.
74+
75+
1. After setting the policy, go to the **5. Test** page to test the custom connector.
76+
77+
## Next steps
78+
79+
* [Learn more about the Power Platform](https://powerplatform.microsoft.com/)
80+
* [Learn more about creating and using custom connectors](/connectors/custom-connectors/)

articles/api-management/export-api-power-platform.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ author: dlepow
66

77
ms.service: api-management
88
ms.topic: how-to
9-
ms.date: 08/12/2022
9+
ms.date: 03/24/2023
1010
ms.author: danlep
11+
ms.custom: engagement-fy23
1112

1213
---
1314
# Export APIs from Azure API Management to the Power Platform
@@ -19,7 +20,7 @@ This article walks through the steps in the Azure portal to create a custom Powe
1920
## Prerequisites
2021

2122
+ Complete the following quickstart: [Create an Azure API Management instance](get-started-create-service-instance.md)
22-
+ Make sure there is an API in your API Management instance that you'd like to export to the Power Platform
23+
+ Make sure there's an API in your API Management instance that you'd like to export to the Power Platform
2324
+ Make sure you have a Power Apps or Power Automate [environment](/powerapps/powerapps-overview#power-apps-for-admins)
2425

2526
## Create a custom connector to an API
@@ -37,7 +38,7 @@ This article walks through the steps in the Azure portal to create a custom Powe
3738

3839
:::image type="content" source="media/export-api-power-platform/create-custom-connector.png" alt-text="Create custom connector to API in API Management":::
3940

40-
Once the connector is created, navigate to your [Power Apps](https://make.powerapps.com) or [Power Automate](https://make.powerautomate.com) environment. You will see the API listed under **Data > Custom Connectors**.
41+
Once the connector is created, navigate to your [Power Apps](https://make.powerapps.com) or [Power Automate](https://make.powerautomate.com) environment. You'll see the API listed under **Data > Custom Connectors**.
4142

4243
:::image type="content" source="media/export-api-power-platform/custom-connector-power-app.png" alt-text="Custom connector in Power Platform":::
4344

@@ -48,10 +49,9 @@ You can manage your custom connector in your Power Apps or Power Platform enviro
4849
1. Select your connector from the list of custom connectors.
4950
1. Select the pencil (Edit) icon to edit and test the custom connector.
5051

51-
> [!NOTE]
52-
> To call the API from the Power Apps test console, you need to add the `https://make.powerautomate.com` URL as an origin to the [CORS policy](cors-policy.md) in your API Management instance.
52+
> [!IMPORTANT]
53+
> To call the API from the Power Apps test console, you need to configure a CORS policy in your API Management instance and create a policy in the custom connector to set an Origin header in HTTP requests. For more information, see [Enable CORS policies to test custom connector from Power Platform](enable-cors-power-platform.md).
5354
>
54-
> Depending on how the custom connector gets used when running Power Apps, you might need to configure additional origins in the CORS policy. You can use developer tools in your browser, tracing in API Management, or Application Insights to investigate CORS issues when running Power Apps.
5555
5656
## Update a custom connector
5757

128 KB
Loading

0 commit comments

Comments
 (0)