Create a Fraud configuration for tenant. - Fabric

Create a Fraud configuration for tenant.

cURL

curl --request POST \
  --url https://prod01.oms.fabric.inc/api/v2/configurations/fraud-config \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'x-site-context: <x-site-context>' \
  --data '
{
  "serviceName": "FRAUD_RELEASE_SERVICE",
  "processName": "ORDER_CREATE",
  "configuration": {
    "conditions": "[  // OR BLOCK START\n   [    // AND BLOCK STARTS\n     {\n       \"key\": \"orderDate\",\n       \"operator\": \"lte\",\n       \"type\": \"date\",\n       \"value\": [-59, \"SECONDS\"] // now -59 sec\n     },\n     {\n       \"key\": \"type\",\n       \"operator\": \"in\",\n       \"value\": [\"web\", \"mobile\"]\n     }\n   ],  // AND BLOCK END\n   [ // AND BLOCK STARTS\n     {\n       \"key\": \"orderDate\",\n       \"operator\": \"lt\",\n       \"type\": \"date\",\n       \"value\": [-10, \"MINUTES\"]\n     },\n     {\n       \"key\": \"type\",\n       \"operator\": \"is\",\n       \"value\": \"postman\"\n     }\n   ] // AND BLOCK ENDS\n ] // OR BLOCK ENDS\n"
  }
}'

Python

import requests

url = "https://prod01.oms.fabric.inc/api/v2/configurations/fraud-config"

payload = {
    "serviceName": "FRAUD_RELEASE_SERVICE",
    "processName": "ORDER_CREATE",
    "configuration": { "conditions": "[  // OR BLOCK START\
   [    // AND BLOCK STARTS\
     {\
       \"key\": \"orderDate\",\
       \"operator\": \"lte\",\
       \"type\": \"date\",\
       \"value\": [-59, \"SECONDS\"] // now -59 sec\
     },\
     {\
       \"key\": \"type\",\
       \"operator\": \"in\",\
       \"value\": [\"web\", \"mobile\"]\
     }\
   ],  // AND BLOCK END\
   [ // AND BLOCK STARTS\
     {\
       \"key\": \"orderDate\",\
       \"operator\": \"lt\",\
       \"type\": \"date\",\
       \"value\": [-10, \"MINUTES\"]\
     },\
     {\
       \"key\": \"type\",\
       \"operator\": \"is\",\
       \"value\": \"postman\"\
     }\
   ] // AND BLOCK ENDS\
 ] // OR BLOCK ENDS\n" }
}
headers = {
    "x-site-context": "<x-site-context>",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)

JavaScript (Fetch)

const options = {
  method: 'POST',
  headers: {
    'x-site-context': '<x-site-context>',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    serviceName: 'FRAUD_RELEASE_SERVICE',
    processName: 'ORDER_CREATE',
    configuration: {
      conditions: '[  // OR BLOCK START\n   [    // AND BLOCK STARTS\n     {\n       "key": "orderDate",\n       "operator": "lte",\n       "type": "date",\n       "value": [-59, "SECONDS"] // now -59 sec\n     },\n     {\n       "key": "type",\n       "operator": "in",\n       "value": ["web", "mobile"]\n     }\n   ],  // AND BLOCK END\n   [ // AND BLOCK STARTS\n     {\n       "key": "orderDate",\n       "operator": "lt",\n       "type": "date",\n       "value": [-10, "MINUTES"]\n     },\n     {\n       "key": "type",\n       "operator": "is",\n       "value": "postman"\n     }\n   ] // AND BLOCK ENDS\n ] // OR BLOCK ENDS\n'
    }
  })
};

fetch('https://prod01.oms.fabric.inc/api/v2/configurations/fraud-config', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));

PHP

<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://prod01.oms.fabric.inc/api/v2/configurations/fraud-config",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'serviceName' => 'FRAUD_RELEASE_SERVICE',
    'processName' => 'ORDER_CREATE',
    'configuration' => [
        'conditions' => '[  // OR BLOCK START\
   [    // AND BLOCK STARTS\
     {\
       \"key\": \"orderDate\",\
       \"operator\": \"lte\",\
       \"type\": \"date\",\
       \"value\": [-59, \"SECONDS\"] // now -59 sec\
     },\
     {\
       \"key\": \"type\",\
       \"operator\": \"in\",\
       \"value\": [\"web\", \"mobile\"]\
     }\
   ],  // AND BLOCK END\
   [ // AND BLOCK STARTS\
     {\
       \"key\": \"orderDate\",\
       \"operator\": \"lt\",\
       \"type\": \"date\",\
       \"value\": [-10, \"MINUTES\"]\
     },\
     {\
       \"key\": \"type\",\
       \"operator\": \"is\",\
       \"value\": \"postman\"\
     }\
   ] // AND BLOCK ENDS\
 ] // OR BLOCK ENDS\n'
    ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json",
    "x-site-context: <x-site-context>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
?>

Go

package main

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

func main() {

url := "https://prod01.oms.fabric.inc/api/v2/configurations/fraud-config"

payload := strings.NewReader("{\n  \"serviceName\": \"FRAUD_RELEASE_SERVICE\",\n  \"processName\": \"ORDER_CREATE\",\n  \"configuration\": {\n    \"conditions\": \"[  // OR BLOCK START\\n   [    // AND BLOCK STARTS\\n     {\\n       \"key\": \"orderDate\",\\n       \"operator\": \"lte\",\\n       \"type\": \"date\",\\n       \"value\": [-59, \"SECONDS\"] // now -59 sec\\n     },\\n     {\\n       \"key\": \"type\",\\n       \"operator\": \"in\",\\n       \"value\": [\"web\", \"mobile\"]\\n     }\\n   ],  // AND BLOCK END\\n   [ // AND BLOCK STARTS\\n     {\\n       \"key\": \"orderDate\",\\n       \"operator\": \"lt\",\\n       \"type\": \"date\",\\n       \"value\": [-10, \"MINUTES\"]\\n     },\\n     {\\n       \"key\": \"type\",\\n       \"operator\": \"is\",\\n       \"value\": \"postman\"\\n     }\\n   ] // AND BLOCK ENDS\\n ] // OR BLOCK ENDS\n"  ")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("x-site-context", "<x-site-context>")
    req.Header.Add("Authorization", "Bearer <token>")
    req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
    body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))
}

Responses

Success

{
  "serviceName": "FRAUD_RELEASE_SERVICE",
  "processName": "ORDER_CREATE",
  "configuration": {
    "conditions": "[  // OR BLOCK START\n   [    // AND BLOCK STARTS\n     {\n       \"key\": \"orderDate\",\n       \"operator\": \"lte\",\n       \"type\": \"date\",\n       \"value\": [-59, \"SECONDS\"] // now -59 sec\n     },\n     {\n       \"key\": \"type\",\n       \"operator\": \"in\",\n       \"value\": [\"web\", \"mobile\"]\n     }\n   ],  // AND BLOCK END\n   [ // AND BLOCK STARTS\n     {\n       \"key\": \"orderDate\",\n       \"operator\": \"lt\",\n       \"type\": \"date\",\n       \"value\": [-10, \"MINUTES"]\n     },\n     {\n       \"key\": \"type\",\n       \"operator\": \"is\",\n       \"value\": \"postman\"\n     }\n   ] // AND BLOCK ENDS\n ] // OR BLOCK ENDS\n"
  },
  "tenantId": "asferf3r4safasdcd"
}

Error Responses

{
  "message": "Bad Request"
}
{
  "message": "Configuration not found for tenant."
}
{
  "message": "Fraud Configuration already exists for the tenant"
}
{
  "message": "Internal Server Error"
}