Microsoft Power Platform Connectors CLI

Note

These release notes describe functionality that may not have been released yet. To see when this functionality is planned to release, see What's new and planned for Common Data Model and Data Integration. Delivery timelines and projected functionality may change or may not ship (see Microsoft policy).

The paconn command line tool is designed to aid Microsoft Power Platform custom connectors development.

Installing

  1. Install Python 3.5+ from https://www.python.org/downloads. Select the 'Download' link on any version of Python greater than Python 3.5. For Linux and Mac OS X, follow the appropriate link on the page. You can also install using an OS specific package manager of your choice.

  2. Run the installer to begin installation and be sure to check the box 'Add Python X.X to PATH'.

  3. Make sure the installation path is in the PATH variable by running:

    python --version

  4. After python is installed, install paconn by running:

    pip install paconn

Custom Connector Directory and Files

A custom connector consists of three files: an icon for the connector, an Open API swagger definition, and an API properties file. The files are generally located in a directory with the connector ID as the name of the directory.

Sometimes, the custom connector directory may include a settings.json file. Although this file is not part of the connector definition, it can be used as an argument-store for the CLI.

API Definition (Swagger) File

The API definition file describes the API for the custom connector using the OpenAPI specification. It is also known as the swagger file. More information about API definitions used to write custom connectors can be found in the connector documentation on the subject. Also review the tutorial on extending an OpenApi definition.

API Properties File

The API properties file contains some properties for the custom connector. These properties are not part of the API definition. It contains information such as the brand color, authentication information, and so on. A typical API properties file looks like the following:

{
  "properties": {
    "capabilities": [],
    "connectionParameters": {
      "api_key": {
        "type": "securestring",
        "uiDefinition": {
          "constraints": {
            "clearText": false,
            "required": "true",
            "tabIndex": 2
          },
          "description": "The KEY for this API",
          "displayName": "KEY",
          "tooltip": "Provide your KEY"
        }
      }
    },
    "iconBrandColor": "#007EE6",
    "policyTemplateInstances": [
      {
        "title": "MyPolicy",
        "templateId": "setqueryparameter",
        "parameters": {
            "x-ms-apimTemplateParameter.name": "queryParameterName",
            "x-ms-apimTemplateParameter.value": "queryParameterValue",
            "x-ms-apimTemplateParameter.existsAction": "override"
        }
      }
    ]    
  }
}

More information on the each of the properties are given below:

  • properties: The container for the information.

  • connectionParameters: Defines the connection parameter for the service.

  • iconBrandColor: The icon brand color in HTML hex code for the custom connector.

  • capabilities: Describes the capabilities for the connector, for example, cloud only, on-prem gateway, and so on.

  • policyTemplateInstances: An optional list of policy template instances and values used in the custom connector.

Icon File

The icon file is a small image representing the custom connector icon.

Settings File

Instead of providing the arguments in the command line, a settings.json file can be used to specify them. A typical settings.json file looks like the following:

{
  "connectorId": "CONNECTOR-ID",
  "environment": "ENVIRONMENT-GUID",
  "apiProperties": "apiProperties.json",
  "apiDefinition": "apiDefinition.swagger.json",
  "icon": "icon.png",
  "powerAppsApiVersion": "2016-11-01",
  "powerAppsUrl": "https://preview.api.powerapps.com"
}

In the settings file the following items are expected. If an option is missing but required, the console will prompt for the missing information.

  • connectorId: The connector ID string for the custom connector. This parameter is required for download and update operations, but not for the create operation since a new custom connector with the new ID will be created. If you need to update a custom connector just created using the same settings file, make sure the settings file is correctly updated with the new connector ID from the create operation.

  • environment: The environment ID string for the custom connector. This parameter is required for all three operations.

  • apiProperties: The path to the API properties apiProperties.json file. It is required for the create and update operation. When this option is present during the download, the file will be downloaded to the given location.

  • apiDefinition: The path to the swagger file. It is required for the create and update operation. When this option is present during the download, the file in the given location will be written to.

  • icon: The path to the icon file. It is required for the create and update operation. When this option is present during the download, the file in the given location will be written to.

  • powerAppsApiVersion: The API version to use for Power Apps. This is optional and set to 2016-11-01 by default.

  • powerAppsUrl: The API URL for Power Apps. This is optional and set to https://preview.api.powerapps.com by default.

Command Line Operations

Login

Login to Power Platform by running:

paconn login

This will ask you to login using the device code login process. Follow the prompt for the login.

Download Custom Connector Files

The connector files are always downloaded into a sub-directory with the connector ID as the directory name. When a destination directory is specified, the sub-directory will be created in the specified one. Otherwise, it will be created in the current directory. In addition to the three connector files, the download operation will also write a fourth file called settings.json containing the parameters used to download the files.

Download the custom connector files by running:

paconn download

or

paconn download -e [Power Platform Environment GUID] -c [Connector ID]

or

paconn download -s [Path to settings.json]

When the environment or connector ID is not specified, the command will prompt for the missing argument(s). The command will output the download location for the connector if it successfully downloads.

All the arguments can be also specified using a settings.json file.

Arguments
   --cid -c      : The custom connector ID.
   --dest -d     : Destination directory.
   --env -e      : Power Platform environment GUID.
   --pau -u      : Power Platform URL.
   --pav -v      : Power Platform API version.
   --settings -s : A settings file containing required parameters.
                   When a settings file is specified some command 
                   line parameters are ignored.

Create a New Custom Connector

A new custom connector can be created from the three files introduced earlier. Create a connector by running:

paconn create --api-prop [Path to apiProperties.json] --api-def [Path to apiDefinition.swagger.json] --icon [Path to icon.png]

or

paconn create -e [Power Platform Environment GUID] --api-prop [Path to apiProperties.json] --api-def [Path to apiDefinition.swagger.json] --icon [Path to icon.png] --secret [The OAuth2 client secret for the connector]

or

paconn create -s [Path to settings.json] --secret [The OAuth2 client secret for the connector]

When the environment is not specified the command will prompt for it. However, the API definition, API properties, and icon file must be provided as part of the command line argument or a settings file. The OAuth2 secret must be provided for a connector using OAuth2. The command will print the connector ID for the newly created custom connector on successful completion. If you are using a settings.json for the create command, make sure to update it with the new connector ID before you update the newly created connector.

All the arguments can be also specified using a settings.json file.

Arguments
   --api-def     : Location for the Open API definition JSON document.
   --api-prop    : Location for the API properties JSON document.
   --env -e      : Power Platform environment GUID.
   --icon        : Location for the icon file.
   --pau -u      : Power Platform URL.
   --pav -v      : Power Platform API version.
   --secret -r   : The OAuth2 client secret for the connector.
   --settings -s : A settings file containing required parameters.
                   When a settings file is specified some command 
                   line parameters are ignored.

Update an Existing Custom Connector

Like the create operation, an existing custom connector can be updated from the three files introduced earlier. Update a connector by running:

paconn update --api-prop [Path to apiProperties.json] --api-def [Path to apiDefinition.swagger.json] --icon [Path to icon.png]

or

paconn update -e [Power Platform Environment GUID] -c [Connector ID] --api-prop [Path to apiProperties.json] --api-def [Path to apiDefinition.swagger.json] --icon [Path to icon.png] --secret [The OAuth2 client secret for the connector]

or

paconn create -s [Path to settings.json] --secret [The OAuth2 client secret for the connector]

When environment or connector ID is not specified, the command will prompt for the missing argument(s). However, the API definition, API properties, and icon file must be provided as part of the command line argument or a settings file. The OAuth2 secret must be provided for a connector using OAuth2. The command will print the updated connector ID on successful completion. If you are using a settings.json for the update command, make sure the correct environment and connector ID are specified.

All the arguments can be also specified using a settings.json file.

Arguments
   --api-def     : Location for the Open API definition JSON document.
   --api-prop    : Location for the API properties JSON document.
   --cid -c      : The custom connector ID.
   --env -e      : Power Platform environment GUID.
   --icon        : Location for the icon file.
   --pau -u      : Power Platform URL.
   --pav -v      : Power Platform API version.
   --secret -r   : The OAuth2 client secret for the connector.
   --settings -s : A settings file containing required parameters.
                   When a settings file is specified some command 
                   line parameters are ignored.

Best Practice

Download all the custom connectors and use git or any other source control system to save the files. In case of an incorrect update, re-deploy the connector by re-running the update command with the correct set of files from the source control system.

Test the custom connector and the settings file in a test environment before deploying in the production environment. Always double check that the environment and connector ID are correct.

Limitations

The project is limited to creation, update, and download of a custom connector in the Power Automate and Power Apps environment. When an environment is not specified, only the Power Automate environments are listed to choose from. For a non-custom connector, the swagger file is not returned.

Reporting issues and feedback

If you encounter any bugs with the tool, file an issue in the Issues section of our GitHub repo.

If you believe you have found a security vulnerability that meets Microsoft's definition of a security vulnerability, submit a report to MSRC. More information can be found at MSRC frequently asked questions on reporting.