{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":37176,"path":"order-management/configure-external-connection.md","title":"Create an external connection","bundle":null,"doc_type":null,"release":"australia","body":"\n# Create an external connection\n\nCreate an external connection in CPQ to enable enrichments to retrieve data from an external system for use in configuration rules.\n\n## Before you begin\n\nRole required: admin\n\n## About this task\n\nExternal connections are used in configuration rules only. They can only be called from an enrichment script. After you configure an external connection, reference it in your enrichment script using `External.*connectionName*(inputs)`, where *connectionName* is the unique name of the connection.\n\n\\[Omitted image \"cpq-enrichments-external-connections.png\"\\] Alt text: External Connections list view in CPQ Administration\n\n**Note:** To call an external system from a transaction rule instead, add a connection. For more information, see [Create a connection for ServiceNow Quote Experience calls](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/order-management/configure-a-connection.md).\n\n## Procedure\n\n1.  Navigate to **All** &gt; **CPQ Administration** &gt; **Utilities** &gt; **External Connections**.\n\n2.  Select **+New** to create a new external connection.\n\n3.  In the **Authentication type** field, select the credential method that the external system requires, then complete the fields for that authentication type.\n\n<table><thead><tr><th align=\"left\" id=\"d112713e156\">\n\nAuthentication type\n\n</th><th align=\"left\" id=\"d112713e159\">\n\nAction\n\n</th></tr></thead><tbody><tr><td id=\"d112713e165\">\n\n**No authentication**\n\n</td><td>\n\nNo additional fields are required. The external connection calls the API without credentials.\n\n</td></tr><tr><td id=\"d112713e174\">\n\n**Bearer token**\n\n</td><td>\n\nIn the **Authentication token** field, enter the bearer token provided by the external service.\n\n</td></tr><tr><td id=\"d112713e186\">\n\n**OAuth - Client credentials flow**\n\n</td><td>\n\nComplete the following fields:-   **Client ID**: Client identifier created for CPQ with the authorization server.\n-   **Client secret**: Tokenized reference to the client secret. The actual value is stored in the GCP secret store. In development environments, the value is stored directly.\n-   **Token URL**: URL of the authorization server where CPQ exchanges the client ID and secret for an access token.\n-   **Scope**: Scopes to include in the token request. This field is available only when OAuth - Client credentials flow is selected in the Authentication type field.\n\n\n</td></tr></tbody>\n</table>4.  In the **Path** field, enter the path to append to the host URL, including any parameter variables for dynamic segments.\n\n    Use double curly braces to define a parameter variable in the path. For example:\n\n    ```\n    /v4/latest/{{inputVariable}}\n    ```\n\n    In your enrichment script, pass the variable as a key-value pair in the inputs object and wrap the value in `encodeURIComponent()` to ensure the value is URL-safe:\n\n    ```\n    let inputs = {\"inputVariable\": encodeURIComponent(cfgRequest.baseCurrency.value)};\n    let results = External.exchangeRatesAPI(inputs);\n    ```\n\n5.  In the **Timeout** field, enter the maximum time in milliseconds that CPQ waits for a response from the external system.\n\n    Start with 500 milliseconds. If the external connection regularly exceeds this limit, increase the value, keeping in mind that higher timeouts may slow the end-user configuration experience.\n\n6.  Select **Save**.\n\n\n## Result\n\nThe external connection is saved and available to call from enrichment scripts.\n\n## BOM enrichment using an external pricing connection\n\nThe following on-BOM-response enrichment calls a `powerPricing` external connection to retrieve customer-specific rate data and apply it to `ProductList` records. The connection accepts two input variables — `membershipCode` and `icp` — and returns a pricing response that the script uses to set prices on individual products.\n\n```\nvar powerInputs = {\"membershipCode\": cfg.eCMembershipCode, \"icp\": cfg.eCICPNumber};\nlet powerResponse = External.powerPricing(powerInputs);\n\nlet dailyCharge = 0;\nlet ratesArr = [];\n\nif (powerResponse.status == 200) {\n\n  for (var record of powerResponse.body) {\n    if (record.chargeType == cfg.expectedUsage) {\n      dailyCharge = record.dailyCharges;\n      ratesArr = record.rates;\n    }\n  }\n\n  for (var prod of ProductList) {\n    if (prod.id == \"electricBillEstimator\") {\n      let addedPrice = dailyCharge * cfg.serviceDurationInDays;\n      prod.price = addedPrice;\n    }\n    if (prod.id == \"Standard Rate\" || prod.id == \"Low Rate\") {\n      prod.price = dailyCharge;\n    }\n  }\n\n  for (var rateVal of ratesArr) {\n    ProductList.id = \"Additional Charge Per KWH: \" + rateVal.name;\n    ProductList.quantity = 1;\n    ProductList.bomType = \"Manufacturing\";\n    ProductList.orderNumber = 2;\n    ProductList.price = rateVal.rate;\n    ProductList.notes = rateVal.measure;\n    ProductList.parentProduct = \"electricBillEstimator\";\n    ProductList.next();\n  }\n\n}\n\nreturn ProductList;\n```\n\n**Related topics**  \n\n\n[Set up External connections for configuration rules](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/order-management/external-connections.md)\n\n"}}