Page 1 of 1

API for campaign and group

PostPosted: Wed Mar 27, 2019 9:02 pm
by finntama
I already read API for agents and non agents and I cannot find add/update API for campaign and group. Is an API for that exist or if not is there's any way to do that via current API's?

thanks in advance

Re: API for campaign and group

PostPosted: Thu Mar 28, 2019 5:16 am
by mflorell
No, there is no Add Campaign API function currently, but there is one to update several campaign options(update_campaign):
http://vicidial.org/docs/NON-AGENT_API.txt

Re: API for campaign and group

PostPosted: Mon May 20, 2019 12:04 pm
by williamconley
Just use mysql. Use mysqldump with --where to get a single record from an existing campaign. That will provide you with an insert statement specific to your version of Vicidial. Change the Campaign ID, Name, and Description in that statement before executing. Then you can use the existing API methods to alter anything else later.

Re: API for campaign and group

PostPosted: Wed Nov 24, 2021 4:29 am
by andicrb76
hi matt,

i just add add_campaign function for NON AGENT API ini non_agent_api.php

what you need to add these codes:
if (isset($_GET["lead_order"])) {$lead_order=$_GET["lead_order"];}
elseif (isset($_POST["lead_order"])) {$lead_order=$_POST["lead_order"];}
if (isset($_GET["next_agent_call"])) {$next_agent_call=$_GET["next_agent_call"];}
elseif (isset($_POST["next_agent_call"])) {$next_agent_call=$_POST["next_agent_call"];}

and:

if ($function == 'add_campaign')
{
if(strlen($source)<2)
{
$result = 'ERROR';
$result_reason = "Invalid Source";
echo "$result: $result_reason - $source\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
echo "ERROR: Invalid Source: |$source|\n";
exit;
}
else
{
if ( (!preg_match("/ $function /",$api_allowed_functions)) and (!preg_match("/ALL_FUNCTIONS/",$api_allowed_functions)) )
{
$result = 'ERROR';
$result_reason = "auth USER DOES NOT HAVE PERMISSION TO USE THIS FUNCTION";
echo "$result: $result_reason: |$user|$function|\n";
$data = "$allowed_user";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
$stmt="SELECT count(*) from vicidial_users where user='$user' and vdc_agent_api_access='1' and modify_campaigns='1' and user_level >= 8 and active='Y';";
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$allowed_user=$row[0];
if ($allowed_user < 1)
{
$result = 'ERROR';
$result_reason = "add_campaign USER DOES NOT HAVE PERMISSION TO ADD CAMPAIGNS";
$data = "$allowed_user";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{
if ( (strlen($campaign_id)<2) or (strlen($campaign_id)>8) )
{
$result = 'ERROR';
$result_reason = "add_campaign YOU MUST USE ALL REQUIRED FIELDS";
$data = "$campaign_id|$campaign_name|$campaign_id";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{
$stmt="SELECT allowed_campaigns,admin_viewable_groups from vicidial_user_groups where user_group='$LOGuser_group';";
if ($DB>0) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$LOGallowed_campaigns = $row[0];
$LOGadmin_viewable_groups = $row[1];

$LOGallowed_campaignsSQL='';
$whereLOGallowed_campaignsSQL='';
if ( (!preg_match('/\-ALL/i', $LOGallowed_campaigns)) )
{
$rawLOGallowed_campaignsSQL = preg_replace("/ -/",'',$LOGallowed_campaigns);
$rawLOGallowed_campaignsSQL = preg_replace("/ /","','",$rawLOGallowed_campaignsSQL);
$LOGallowed_campaignsSQL = "and campaign_id IN('$rawLOGallowed_campaignsSQL')";
$whereLOGallowed_campaignsSQL = "where campaign_id IN('$rawLOGallowed_campaignsSQL')";
}

$stmt="SELECT count(*) from vicidial_campaigns where campaign_id='$campaign_id' $LOGallowed_campaignsSQL;";
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$camp_exists=$row[0];
if ($camp_exists > 0)
{
$result = 'ERROR';
$result_reason = "add_campaign CAMPAIGN ALREADY EXIST";
$data = "$campaign_id";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{
$dialmethodSQL='';
$adaptivemaximumlevelSQL='';
$campaignvdadextenSQL='';
$hopperlevelSQL='';
$dialtimeoutSQL='';
$campaignnameSQL='';
$campaigncidSQL='';
$campaignfilterSQL='';
$activeSQL='';
$autodiallevelSQL='';
$leadorderSQL='';
$nextagentcallSQL='';

if (strlen($auto_dial_level) > 0)
{
if ( ($auto_dial_level > $SSauto_dial_limit) or ($auto_dial_level < 0) )
{
$result = 'ERROR';
$result_reason = "add_campaign AUTO DIAL LEVEL MUST BE FROM 0 TO $SSauto_dial_limit, THIS IS AN OPTIONAL FIELD";
$data = "$auto_dial_level";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{$autodiallevelSQL = " ,auto_dial_level='$auto_dial_level'";}
}
if (strlen($dial_method) > 0)
{
if (preg_match("/^MANUAL$|^RATIO$|^INBOUND_MAN$|^ADAPT_AVERAGE$|^ADAPT_HARD_LIMIT$|^ADAPT_TAPERED$/",$dial_method))
{$dialmethodSQL = " ,dial_method='$dial_method'";}
else
{
$result = 'ERROR';
$result_reason = "add_campaign DIAL METHOD IS NOT VALID, THIS IS AN OPTIONAL FIELD";
$data = "$dial_method";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
}
if (strlen($adaptive_maximum_level) > 0)
{
if ( (strlen($adaptive_maximum_level) > 5) or (strlen($adaptive_maximum_level) < 1) )
{
$result = 'ERROR';
$result_reason = "add_campaign ADAPT MAXIMUM DIAL LEVEL MUST BE FROM 1 TO 5 CHARACTERS, THIS IS AN OPTIONAL FIELD";
$data = "$adaptive_maximum_level";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{$adaptivemaximumlevelSQL = " ,adaptive_maximum_level='$adaptive_maximum_level'";}
}
if (strlen($campaign_vdad_exten) > 0)
{
if ( (strlen($campaign_vdad_exten) > 20) or (strlen($campaign_vdad_exten) < 3) )
{
$result = 'ERROR';
$result_reason = "add_campaign ROUTING EXTENSION MUST BE FROM 3 TO 20 CHARACTERS, THIS IS AN OPTIONAL FIELD";
$data = "$campaign_vdad_exten";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{$campaignvdadextenSQL = " ,campaign_vdad_exten='$campaign_vdad_exten'";}
}
if (strlen($hopper_level) > 0)
{
if ( ($hopper_level > 2000) or ($hopper_level < 1) )
{
$result = 'ERROR';
$result_reason = "add_campaign HOPPER LEVEL MUST BE FROM 1 TO 2000, THIS IS AN OPTIONAL FIELD";
$data = "$hopper_level";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{$hopperlevelSQL = " ,hopper_level='$hopper_level'";}
}
if (strlen($dial_timeout) > 0)
{
if ( ($dial_timeout > 120) or ($dial_timeout < 1) )
{
$result = 'ERROR';
$result_reason = "add_campaign DIAL TIMEOUT MUST BE FROM 1 TO 120, THIS IS AN OPTIONAL FIELD";
$data = "$dial_timeout";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{$dialtimeoutSQL = " ,dial_timeout='$dial_timeout'";}
}
if (strlen($campaign_name) > 0)
{
if ( (strlen($campaign_name) > 40) or (strlen($campaign_name) < 6) )
{
$result = 'ERROR';
$result_reason = "add_campaign CAMPAIGN NAME MUST BE FROM 6 TO 40 CHARACTERS, THIS IS AN OPTIONAL FIELD";
$data = "$campaign_name";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{$campaignnameSQL = " ,campaign_name='$campaign_name'";}
}
if (strlen($outbound_cid) > 0)
{
if ( (strlen($outbound_cid) > 20) or (strlen($outbound_cid) < 6) )
{
$result = 'ERROR';
$result_reason = "add_campaign CAMPAIGN CID MUST BE FROM 6 TO 20 CHARACTERS, THIS IS AN OPTIONAL FIELD";
$data = "$outbound_cid";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{$campaigncidSQL = " ,campaign_cid='$outbound_cid'";}
}
if (strlen($lead_filter_id) > 0)
{
if ($lead_filter_id == '---NONE---')
{$lead_filter_id='';}
else
{
$stmt="SELECT count(*) from vicidial_lead_filters where lead_filter_id='$lead_filter_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$filter_exists=$row[0];

if ($filter_exists < 1)
{
$result = 'ERROR';
$result_reason = "add_campaign CAMPAIGN LEAD FILTER MUST BE A VALID FILTER IN THE SYSTEM, THIS IS AN OPTIONAL FIELD";
$data = "$lead_filter_id";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
}
$campaignfilterSQL = " ,lead_filter_id='$lead_filter_id'";
}
if (strlen($active) > 0)
{
if ( ($active != 'Y') and ($active != 'N') )
{
$result = 'ERROR';
$result_reason = "add_campaign ACTIVE MUST BE Y OR N, THIS IS AN OPTIONAL FIELD";
$data = "$active";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{$activeSQL = " ,active='$active'";}
}

if (strlen($lead_order) > 0)
{
if ( ($lead_order == '') or (!isset($lead_order)) )
{
$result = 'ERROR';
$result_reason = "add_campaign LEAD ORDER MUST NOT EMPTY";
$data = "$active";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{$leadorderSQL = " ,lead_order='$lead_order'";}
}

if (strlen($next_agent_call) > 0)
{
if ( (strlen($next_agent_call) > 40) or (strlen($next_agent_call) < 6) )
{
$result = 'ERROR';
$result_reason = "add_campaign NEXT AGENT CALL MUST BE FROM 6 TO 40 CHARACTERS, THIS IS AN OPTIONAL FIELD";
$data = "$next_agent_call";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
exit;
}
else
{$nextagentcallSQL = " ,next_agent_call='$next_agent_call'";}
}
$insertSQL = "$campaignnameSQL$activeSQL$dialtimeoutSQL$hopperlevelSQL$campaignvdadextenSQL$adaptivemaximumlevelSQL$dialmethodSQL$autodiallevelSQL$campaigncidSQL$campaignfilterSQL$leadorderSQL$nextagentcallSQL";

if (strlen($insertSQL)< 3)
{
$result = 'NOTICE';
$result_reason = "add_campaign NO ADD DEFINED";
$data = "$insertSQL";
echo "$result: $result_reason: |$user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
}
else
{
//$stmt="UPDATE vicidial_campaigns SET campaign_changedate='$NOW_TIME' $updateSQL WHERE campaign_id='$campaign_id';";
$stmt = "INSERT INTO vicidial_campaigns (campaign_id,auto_dial_level,dial_method,adaptive_maximum_level,campaign_vdad_exten,hopper_level,dial_timeout,campaign_name,campaign_cid,lead_filter_id,active,lead_order,next_agent_call)
VALUES('$campaign_id','$auto_dial_level','$dial_method','$adaptive_maximum_level','$campaign_vdad_exten','$hopper_level','$dial_timeout','$campaign_name','$outbound_cid','$lead_filter_id','$active','$lead_order','$next_agent_call')";;
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "|$stmt|\n";}

### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|";
$SQL_log = preg_replace('/;/', '', $SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$user', ip_address='$ip', event_section='CAMPAIGNS', event_type='ADD', record_id='$campaign_id', event_code='ADMIN API ADD CAMPAIGN', event_sql=\"$SQL_log\", event_notes='campaign: $campaign_id';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);

$result = 'SUCCESS';
$result_reason = "add_campaign CAMPAIGN HAS BEEN ADDED";
$data = "$campaign_id";
echo "$result: $result_reason - $user|$data\n";
api_log($link,$api_logging,$api_script,$user,$agent_user,$function,$value,$result,$result_reason,$source,$data);
}

}
}
}
}
exit;
}


hope can help someone

Best Regards

Andi Suhandi

Re: API for campaign and group

PostPosted: Wed Nov 24, 2021 9:22 am
by mflorell
Thank you for posting!

Please post a patch file(using "diff -u") against the most recent svn/trunk revision of the non_agent_api.php script to the Issue Tracker if you can.

Re: API for campaign and group

PostPosted: Thu Nov 25, 2021 6:18 am
by andicrb76
Hi Matt,

thanks for the response, i follow your advice but i cant login if using my account.
Do you need to activate my account to post ?


Best Regards


Andi

Re: API for campaign and group

PostPosted: Thu Nov 25, 2021 7:15 am
by mflorell
The Issue Tracker is a separate system, you have to register on the Issue Tracker to post there.

Re: API for campaign and group

PostPosted: Fri Nov 26, 2021 8:00 pm
by carpenox
great addition andi