hbulens
hbulens

Reputation: 1969

Power Platform custom connector works in flows but not in a canvas app

I've got a custom connector that works perfectly for any kind of flow I've built. When I try to use the same connector in a canvas app, nothing seems to happen. There are no error messages either and the monitor indicates success:

{
    "status": 200,
      "duration": 311.5,
      "dataSource": "DS",
      "responseSize": 0,
      "controlName": "btnSendToDS",
      "propertyName": "OnSelect",
      "nodeId": 16,
      "formulaData": {
        "script": "",
        "spanStart": null,
        "spanEnd": null
      },
      "data": {
        "context": {
          "entityName": "btnSendToDS",
          "propertyName": "OnSelect",
          "nodeId": 16,
          "id": 343,
          "diagnosticContext": {
            "dataOperation": {
              "protocol": "rest",
              "operation": "upsertTask",
              "dataSource": "DS"
            }
          }
        },
        "request": {
          "url": "https://europe-002.azure-apim.net/apim/dime-2escheduler-20import-5fa42ba8c1798e4bb5-5ffc65ed5301df6bbf/949038e657344d26be8687bfb0eddb41/task",
          "method": "POST",
          "headers": {
            "x-ms-pa-client-telemetry-options": "paclient-telemetry {\"operationName\":\"/providers/microsoft.powerapps/apis/shared_dime-2escheduler-20import-5fa42ba8c1798e4bb5-5ffc65ed5301df6bbf.upsertTask\"}",
            "ServiceNamespace": "DS",
            "Content-Type": "application/json"
          },
          "body": {
            "sourceApp": "POWERAPPS",
            "sourceType": "POWERAPPS",
            "jobNo": "POWERAPP_001",
            "taskNo": "DRUNKER_SAILOR",
            "shortDescription": "What shall we do?",
            "description": "What shall we do?"
          }
        },
        "response": {
          "duration": 311.5,
          "size": 0,
          "status": 200,
          "headers": {
            "Content-Length": 0,
            "Date": "Thu, 23 Jun 2022 09:12:07 GMT",
            "x-ms-apihub-cached-response": false,
            "x-ms-apihub-obo": true
          },
          "body": "",
          "responseType": "pabinary"
        },
        "startTime": 12581.6,
        "name": "https://europe-002.azure-apim.net/invoke",
        "fetchStart": 12606.1,
        "responseEnd": 12888.4,
        "nextHopProtocol": ""
      }
    }
     

The custom connector simply invokes an Azure API Management endpoint, but it never gets there, according to the analytics/logs in this service.

It really has to do with the PowerApp, because if I run the same endpoint through a Flow, the API is called correctly. On the OnSelect event of a button, this is the code I call:

'DS'.Task(
    {        
        'ds-append': true,
        sourceApp: "POWERAPPS",
        sourceType: "POWERAPPS",
        jobNo: "POWERAPP_001",
        taskNo: tblTasks.Selected.Id,
        shortDescription: tblTasks.Selected.Description,
        description: tblTasks.Selected.Description
    }
);

Is there anything I'm missing here?

Upvotes: 0

Views: 1492

Answers (1)

hbulens
hbulens

Reputation: 1969

It turns out the problem wasn't necessarily related to the canvas app but to the backend, which is an Azure API Management instance. I adjusted the CORS settings of the API to allow GET and OPTIONS methods and that solved the problem.

For future reference, try out the following solution:

<cors allow-credentials="false">
    <allowed-origins>
        <origin>*</origin>
    </allowed-origins>
    <allowed-methods>
        <method>*</method>
    </allowed-methods>
    <allowed-headers>
        <header>*</header>
    </allowed-headers>
</cors>

If that works, you can obviously fine-tune the settings afterwards.

Upvotes: 1

Related Questions