/
(2024.1) MFK Validation with cURL
(2024.1) MFK Validation with cURL
This is an example of cURL usage to contact an outside Web Service or REST API in a Custom Validation. cURL can also be used in Custom Events or Custom APIs.
Custom Validation using CURL
<?php
/** Custom Validation ********
* Description: MFK Validation
* Table Name: GLA
* Table Record: null
* Action: Save
*/
if ($params["RECID"] == "addNew" && $params["format"] != "A/R") {
// "A/R" type GLAs are excluded because their glNumber cannot be 40 characters
$glNumber = $params["gla_item_1"].$params["gla_item_2"].
$params["gla_item_3"].$params["gla_item_4"].
$params["gla_item_5"].$params["gla_item_6"].
$params["gla_item_7"].$params["gla_item_8"].
$params["gla_item_9"].$params["gla_item_10"];
// fill the corp with "10 "
$corp = "10%20%20%20";
// check parameter glNumber to be sure it isn't empty
if (empty($glNumber)) {
$this->setMessage("GLNumber (MFK) is null or empty");
return false;
}
// verify the length if parameter glNumber is 40 characters
if (strlen($glNumber) != 40) {
$this->setMessage("GLNumber (MFK) invalid length");
return false;
}
if ((int)$params["gla_item_3"] >= 7000) {
$corp = "20%20%20%20";
}
$valGLNumber = $corp . $glNumber;
$address = "https://apps.its.uiowa.edu/mfk/api-single.jsp?mfk=";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $address.$valGLNumber);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (false === ($response = curl_exec($ch))) {
$this->setMessage("GLNumber (MFK) validation failed");
$status = false;
} else {
$response = explode("\n", $response);
if ($response[0] == 1) {
$status = true;
} else {
$this->setMessage("GLNumber (MFK) validation failed: $response[1]");
$status = false;
}
}
curl_close($ch);
return $status;
}
, multiple selections available,
Related content
(v1) MFK Validation with cURL
(v1) MFK Validation with cURL
More like this
(v1) .MFK Validation with cURL v2022.1
(v1) .MFK Validation with cURL v2022.1
More like this
(v1) .MFK Validation with cURL v2022.2
(v1) .MFK Validation with cURL v2022.2
More like this
(v1) .Custom API v2020.1
(v1) .Custom API v2020.1
More like this
(v1) .Custom API v2019.1
(v1) .Custom API v2019.1
More like this
(v1) .Custom API v2019.6
(v1) .Custom API v2019.6
More like this