This example of PHP code below creates a new option list using the iFormBuilder API.
Please modify lines 46, 47, and 48 with your appropriate details before running this service. You may also want to modify other parameters to best suit your needs.
Comments
2 comments
i was trying this example and it did not work
<?php
function sendRequest($url,$params,$method) {
if ($method=="GET") {
$ch = curl_init("$url?$params");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}
else if ($method=="POST") {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}
else if ($method=="PUT") {
$fh = fopen('php://memory', 'rw');
fwrite($fh, $params);
rewind($fh);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_INFILE, $fh);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($params));
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}
else if ($method=="DELETE") {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}
else
throw new Exception("Method-$method not recognized");
$json = curl_exec($ch);
curl_close($ch);
return json_decode($json,true);
}
function printOutput($obj) {
echo "<pre style='font-size:11px;'>";
print_r($obj);
echo "</pre>";
}
// Please note the variables below will be unique for each customer
$access_token = "ba0e610305d28f431e0beb62c56879ff4b62ba89";
$server = " https://dycdkiweeadmin.iformbuilder.com/";
$profile = 10826;
$pageId = 0;
$elementIds = array();
// Create Option List
echo "<br><br/>";
echo "Create Option List";
$name = "New Option List";
$url = $server."exzact/api/profiles/$profile/optionlists";
$options = array();
//Options array("KEY_VALUE","LABEL",'SORT_ORDER")
$options[] = array("first","first",1);
$options[] = array("second","second",2);
//$options[] = array("att","att.com",3);
//$options[] = array("me","me.com",4);
$params = "ACCESS_TOKEN=$access_token&NAME=$name";
$i = 0;
foreach ($options as $optionInfo) {
list ($keyValue,$label,$sortOrder) = $optionInfo;
$params .= "&OPTIONS[$i][KEY_VALUE]=$keyValue&OPTIONS[$i][LABEL]=$label&OPTIONS[$i][SORT_ORDER]=$sortOrder";
$i++;
}
$newOptionList = sendRequest($url,$params,"POST");
printOutput($newOptionList);
$optionListId = $newOptionList["OPTIONLIST_ID"];
//Return Created Option List
echo "<br><br/>";
echo "Get Option List";
//GET
$url = $server."exzact/api/profiles/$profile/optionlists/$optionListId";
$params = "ACCESS_TOKEN=$access_token";
$optionListInfo = sendRequest($url,$params,"GET");
printOutput($optionListInfo);
?>
it failed
$json = curl_exec($ch);
any comments ?
Hi Guys
I'm also have an issue with this. I've loaded the script, change the variables an executed, but nothing happens in the option lists.
I can confirm we can get it to work via PostMAN, but we're needing to automate the process via PHP.
Can someone verify this script still works with the iForm servers?
$access_token = "aeff90726af07959d5d048497e5be94efb563f38";
$server = "https://lamanna.iformbuilder.com/";
$profile = 12214;
Cheers
Iain
Please sign in to leave a comment.