if (0) { $ipost_api_url = $ipost_base_api_url . $client_token . '/DataTables/' . $cdt_id . '/addupdate/'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $ipost_api_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $payload = $contacts; curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); $response = curl_exec($ch); $rcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $r = json_decode($response); if ($r && $r->status === 'error') { throw new Exception($r->errors); } } // DATA TABLE CREATION $ipost_api_url = $ipost_base_api_url . $client_token . '/DataTables/create/'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $ipost_api_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $payload='{ "Attributes": [{ "Name": "email", "DataType": "Email", "Required": true, "PrimaryKey": true, "Sendable": true }, { "Name": "firstname", "DataType": "Short Text", "Required": false, "PrimaryKey": false, "Sendable": false } ], "DataTableName": "New_Data_Table' . '_' . time() . '", "Description": "API Upload", "ContentType": "Custom", "Sendable": false, "SendableType": 0, "Testing": false }'; curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); $response = curl_exec($ch); $rcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $r = json_decode($response); $cdt_id = $r->data->data_table_id; ------ - // AUTOMATION CREATION $ipost_api_url = $ipost_base_api_url . $client_token . '/automations/process/create/; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $ipost_api_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $activity = array(); $activity[0]['type'] = "email"; $activity[0]['name'] = $decoded_data['mailing_name'] . '-' . time(); $activity[0]['from_name'] = $from_name; $activity[0]['from_address'] = $from_addr; $activity[0]['email_id'] = $ec_id; $activity[0]['subject'] = $decoded_data['subject']; $activity[0]['destination']['destination_type'] = 'cdt' $activity[0]['destination']['destination_ids'] = array($cdt_id) $schedule = array(); $schedule['schedule_date'] = ''; $schedule['schedule_time_zone'] = ''; $schedule['RecurrenceType'] = ''; $schedule['FrequencyType'] = ''; $schedule['EndDate'] = ''; $schedule['EndOcurrences'] = 1; $payload = array(); $payload['Automation_Name'] = $decoded_data['mailing_name'] . '-' . time(); $payload['Automation_Status'] = "Active"; $payload['type'] = "email"; $payload['Automation_Activities'] = $activity; $payload['Automation_Schedule'] = $schedule; $payload = json_encode($payload); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); $response = curl_exec($ch); $rcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $r = json_decode($response); if ($r && $r->status === 'error') { throw new Exception($r->errors); }