PingOne Platform APIs

Evaluate a Decision Request

 

POST {{apiPath}}/environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}}

The POST {{apiPath}}/environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}} operation executes a decision request against the decision endpoint specified by its ID in the request URL. The request body requires the parameters property. The userContext property is optional.

For property descriptions, refer to Policy decision evaluation request data model

Prerequisites

Request Model
Property Type? Required?

parameters

Object

Required

userContext.environment.id

UUID

Optional

userContext.user.id

UUID

Optional

Headers

Authorization      Bearer {{accessToken}}

Content-Type      application/json

Body

raw ( application/json )

{
    "parameters": {
        "Policy Request": "payment",
        "Request - Payment.creditorName": "Customer2987",
        "Request - Payment.paymentAmount": "3000",
        "Request - Payment.consentId": "{{consentID}}"
    },
    "userContext": {
        "user": {
            "id": "{{userID}}"
        }
    }
}

Example Request

  • cURL

  • C#

  • Go

  • HTTP

  • Java

  • jQuery

  • NodeJS

  • Python

  • PHP

  • Ruby

  • Swift

curl --location --globoff '{{apiPath}}/environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{accessToken}}' \
--data '{
    "parameters": {
        "Policy Request": "payment",
        "Request - Payment.creditorName": "Customer2987",
        "Request - Payment.paymentAmount": "3000",
        "Request - Payment.consentId": "{{consentID}}"
    },
    "userContext": {
        "user": {
            "id": "{{userID}}"
        }
    }
}'
var options = new RestClientOptions("{{apiPath}}/environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}}")
{
  MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest("", Method.Post);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Bearer {{accessToken}}");
var body = @"{" + "\n" +
@"    ""parameters"": {" + "\n" +
@"        ""Policy Request"": ""payment""," + "\n" +
@"        ""Request - Payment.creditorName"": ""Customer2987""," + "\n" +
@"        ""Request - Payment.paymentAmount"": ""3000""," + "\n" +
@"        ""Request - Payment.consentId"": ""{{consentID}}""" + "\n" +
@"    }," + "\n" +
@"    ""userContext"": {" + "\n" +
@"        ""user"": {" + "\n" +
@"            ""id"": ""{{userID}}""" + "\n" +
@"        }" + "\n" +
@"    }" + "\n" +
@"}";
request.AddStringBody(body, DataFormat.Json);
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io"
)

func main() {

  url := "{{apiPath}}/environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}}"
  method := "POST"

  payload := strings.NewReader(`{
    "parameters": {
        "Policy Request": "payment",
        "Request - Payment.creditorName": "Customer2987",
        "Request - Payment.paymentAmount": "3000",
        "Request - Payment.consentId": "{{consentID}}"
    },
    "userContext": {
        "user": {
            "id": "{{userID}}"
        }
    }
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("Authorization", "Bearer {{accessToken}}")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := io.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
POST /environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}} HTTP/1.1
Host: {{apiPath}}
Content-Type: application/json
Authorization: Bearer {{accessToken}}

{
    "parameters": {
        "Policy Request": "payment",
        "Request - Payment.creditorName": "Customer2987",
        "Request - Payment.paymentAmount": "3000",
        "Request - Payment.consentId": "{{consentID}}"
    },
    "userContext": {
        "user": {
            "id": "{{userID}}"
        }
    }
}
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n    \"parameters\": {\n        \"Policy Request\": \"payment\",\n        \"Request - Payment.creditorName\": \"Customer2987\",\n        \"Request - Payment.paymentAmount\": \"3000\",\n        \"Request - Payment.consentId\": \"{{consentID}}\"\n    },\n    \"userContext\": {\n        \"user\": {\n            \"id\": \"{{userID}}\"\n        }\n    }\n}");
Request request = new Request.Builder()
  .url("{{apiPath}}/environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}}")
  .method("POST", body)
  .addHeader("Content-Type", "application/json")
  .addHeader("Authorization", "Bearer {{accessToken}}")
  .build();
Response response = client.newCall(request).execute();
var settings = {
  "url": "{{apiPath}}/environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}}",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/json",
    "Authorization": "Bearer {{accessToken}}"
  },
  "data": JSON.stringify({
    "parameters": {
      "Policy Request": "payment",
      "Request - Payment.creditorName": "Customer2987",
      "Request - Payment.paymentAmount": "3000",
      "Request - Payment.consentId": "{{consentID}}"
    },
    "userContext": {
      "user": {
        "id": "{{userID}}"
      }
    }
  }),
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
var request = require('request');
var options = {
  'method': 'POST',
  'url': '{{apiPath}}/environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}}',
  'headers': {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {{accessToken}}'
  },
  body: JSON.stringify({
    "parameters": {
      "Policy Request": "payment",
      "Request - Payment.creditorName": "Customer2987",
      "Request - Payment.paymentAmount": "3000",
      "Request - Payment.consentId": "{{consentID}}"
    },
    "userContext": {
      "user": {
        "id": "{{userID}}"
      }
    }
  })

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
import requests
import json

url = "{{apiPath}}/environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}}"

payload = json.dumps({
  "parameters": {
    "Policy Request": "payment",
    "Request - Payment.creditorName": "Customer2987",
    "Request - Payment.paymentAmount": "3000",
    "Request - Payment.consentId": "{{consentID}}"
  },
  "userContext": {
    "user": {
      "id": "{{userID}}"
    }
  }
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer {{accessToken}}'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('{{apiPath}}/environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}}');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Content-Type' => 'application/json',
  'Authorization' => 'Bearer {{accessToken}}'
));
$request->setBody('{\n    "parameters": {\n        "Policy Request": "payment",\n        "Request - Payment.creditorName": "Customer2987",\n        "Request - Payment.paymentAmount": "3000",\n        "Request - Payment.consentId": "{{consentID}}"\n    },\n    "userContext": {\n        "user": {\n            "id": "{{userID}}"\n        }\n    }\n}');
try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
require "uri"
require "json"
require "net/http"

url = URI("{{apiPath}}/environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}}")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Bearer {{accessToken}}"
request.body = JSON.dump({
  "parameters": {
    "Policy Request": "payment",
    "Request - Payment.creditorName": "Customer2987",
    "Request - Payment.paymentAmount": "3000",
    "Request - Payment.consentId": "{{consentID}}"
  },
  "userContext": {
    "user": {
      "id": "{{userID}}"
    }
  }
})

response = http.request(request)
puts response.read_body
let parameters = "{\n    \"parameters\": {\n        \"Policy Request\": \"payment\",\n        \"Request - Payment.creditorName\": \"Customer2987\",\n        \"Request - Payment.paymentAmount\": \"3000\",\n        \"Request - Payment.consentId\": \"{{consentID}}\"\n    },\n    \"userContext\": {\n        \"user\": {\n            \"id\": \"{{userID}}\"\n        }\n    }\n}"
let postData = parameters.data(using: .utf8)

var request = URLRequest(url: URL(string: "{{apiPath}}/environments/{{envID}}/decisionEndpoints/{{decisionEndpointID}}")!,timeoutInterval: Double.infinity)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("Bearer {{accessToken}}", forHTTPHeaderField: "Authorization")

request.httpMethod = "POST"
request.httpBody = postData

let task = URLSession.shared.dataTask(with: request) { data, response, error in
  guard let data = data else {
    print(String(describing: error))
    return
  }
  print(String(data: data, encoding: .utf8)!)
}

task.resume()

Example Response

{
  "correlationId": "07ffb9f8-151e-4509-8205-31c46e2a4784",
  "authorizationVersion": {
    "id": "2027cfbe-4fcc-46f8-9c2f-d1f34983a43f"
  },
  "timestamp": "2021-04-06T10:41:42",
  "elapsedMicroseconds": 12345,
  "status": {
    "code": "TIMEOUT",
    "message": "description of error"
  },
  "decision": "PERMIT",
  "statements": [
    {
      "id": "fd0249a2-efa8-4f2c-b57b-859047392d53",
      "name": "payment",
      "code": "PAYMENT",
      "payload": {
        "creditorName": "Customer2987",
        "paymentAmount": 3000,
        "consentId": "a6e8d467-d512-4315-aba1-ed63059a410b"
      }
    },
    {
      "id": "57f1d526-f16a-4645-9161-412da57d89bf",
      "name": "payment",
      "code": "PAYMENT",
      "payload": {
        "creditorName": "Customer9872",
        "paymentAmount": 1428,
        "consentId": "e9fef464-06fc-4952-9339-e47cd40f4d8a"
      }
    }
  ]
}