PingOne DaVinci

Launching a flow with an API call

Launch a prepared flow with an API call.

This method is effective for flows without a UI component.

Configuring the Flow

Prepare a flow to be launched with an API call.

About this task

This procedure only covers the steps and nodes required to prepare a flow for API invocation. It assumes that you have already created a flow for the purpose you have in mind. See the Getting started with DaVinci and DaVinci Best Practices documentation for more information about building flows.

Steps

  1. Click the Flows tab.

  2. Find the flow and click ... → Edit

  3. At the end of the success path, add an HTTP node to send a JSON success response.

  4. At the end of any failure paths, add an HTTP node to send a JSON error response.

  5. Optional: If you want to pass parameters to the flow as part of the invocation, add them to the input schema.

    1. Click Input Schema.

    2. Click Add to add a new parameter.

    3. In the Parameter Name field, enter a name for the input parameter.

    4. Optional: In the Description field, enter a description for the input parameter.

    5. In the Data Type list, select a data type for the input parameter.

    6. Select Required if the parameter is required for the flow.

    7. Optional: Repeat steps b-f to add additional parameters.

    8. Click Save.

  6. Click Save.

  7. Click Deploy.

Creating an Application

Create an application in DaVinci to enable your flow.

About this task

If you want to use an existing application to launch the flow, you can start at step 5.

Steps

  1. Click the Applications tab.

  2. Click Add Application.

    The Add Application modal opens.

  3. In the Name field, enter a name for the application.

  4. Click Create.

  5. Find the application and click Edit.

  6. On the General tab, note the following parameters:

    1. Note the Company ID.

    2. Note the API Key.

  7. Create a flow policy:

    1. Click the Flow Policy tab.

    2. Click Add Flow Policy.

    3. In the Name field, enter a name for the flow policy.

    4. In the flow list, select your flow.

    5. In the version list, select Latest Version.

    6. Click Create Flow Policy.

      This example only uses one flow, but if your flow policy included multiple flows or flow versions, you could use this modal to split traffic between them.

    7. Click Save Flow Policy.

    8. Note the Policy ID of your flow policy.

Adding CORS Settings in PingOne

Add the domain from which the flow will be launched to the DaVinci application in PingOne to prevent CORS issues.

Steps

  1. Sign on to PingOne and go to Applications > Applications.

  2. Click the PingOne DaVinci Connection application.

  3. Click the Configuration tab.

  4. Click the Pencil icon.

  5. In the CORS Settings section, select Allow specific origins.

  6. In the Allowed Origins field, enter the domain from which you plan to launch the flow.

  7. Click Save.

Invoking the Flow

Steps

  1. Using a tool such as Postman, construct the DaVinci API call using the POST method and the following URL structure:

    https://orchestrate-api.pingone.com/v1/company/<YOUR_COMPANY_ID>/policy/<YOUR_POLICY_ID>/start

    The headers should include your API key using the following format.X-SK-API-KEY=<YOUR_API_KEY>

    You can include one or more parameters in the call. If you do so, you must include these parameters in the input schema for the flow. The following examples include a userId parameter.

  2. Execute the API call. The response body will be the output from the Send Success JSON Response action.

Examples

cURL
curl
--location
--request POST 'https://orchestrate-api.pingone.com/v1/company/731f6c64-619a-46e5-97a5-c7cf0be0a70e/policy/e31c3b327523685b8e71ab9d76c83346/start' \
--header 'X-SK-API-KEY: 08cfa...45a6d'
--header 'Content-Type: application/json'
--data '{
    "userId": "b7e5ad3e-ccbd-4043-b22e-8d6d3bf8f7be"
}'
JavaScript and Fetch:
const myHeaders = new Headers();
myHeaders.append("X-SK-API-Key",
"08cfa...45a6d");
myHeaders.append("Content-Type", "application/json");

const raw = JSON.stringify({
  "userId": "b7e5ad3e-ccbd-4043-b22e-8d6d3bf8f7be"
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://orchestrate-api.pingone.com/v1/company/731f6c64-619a-46e5-97a5-c7cf0be0a70e/policy/e31c3b327523685b8e71ab9d76c83346/start", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
JavaScript and NodeJS - Axios:
const axios = require('axios');
let data = JSON.stringify({
  "userId": "b7e5ad3e-ccbd-4043-b22e-8d6d3bf8f7be"
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://orchestrate-api.pingone.com/v1/company/731f6c64-619a-46e5-97a5-c7cf0be0a70e/policy/e31c3b327523685b8e71ab9d76c83346/start',
  headers: {
    'X-SK-API-Key': '08cfa...45a6d',
    'Content-Type': 'application/json'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});