Table of Contents:
Code Examples
Add contact to List: PHP, C# and NodeJS examples
C# code example of how to add a contact to your Ongage List:
PHP code example of how to add a single contact to your Ongage List:
NodeJS code example of how to add a single contact to your Ongage List
const request = require('request-promise-native')const headers = { x_username: '*******', x_password:'********', x_account_code:'*********' } const listId = 1234 // Put List Id in which you want to create contact const createContact = async () => { const payload = { uri: `https://api.ongage.net/${listId}/api/v2/contacts/`, json: true, body: { email: 'test123@gmail.com', first_name: 'Test', last_name: 'Test' }, headers, method: "POST", resolveWithFullResponse: true } return request(payload) }createContact() .then((response) => { console.log(`Response : ${JSON.stringify(response)}`) }).catch((err) => { console.log(`Error : ${err}`) })
JSON example of bulk contact add to list
POST /api/v2/contacts [ { "email": "john@doe.com", "fields" : { "name": "John Doe", "country": "Chile" } } , { "email" : "some@one.com", "fields" : { "name": "....", "country": "...." } } ] example of return: { "metadata": { "error": false }, "payload": { "rows": 2, "created": 1, "created_emails": { "some@one.com": "11111111111111111" }, "updated": 0, "updated_emails": [], "revived": 0, "revived_emails": [], "success": 1, "failed": 1, "failed_emails": { "john@doe.com": "Email already exists" } } }
JSON Example of How To Do a Contact Search Using The Ongage System Contact ID
Endpoint: POST api/contact_search
REQUEST JSON FOR SINGLE CONTACT ID ================================== { "title":"All Members: Contact ID (System field) equals \"1111\"", "include_behavior":false, "filters":{ "type":"Active", "criteria":[ { "type":"id", "operator":"=", "operand":[ "1111" ], "case_sensitive":0, "condition":"and", "field":"ocx_contact_id" } ], "user_type":"all" }, "combined_as_and":true } REQUEST JSON FOR MULTIPLE CONTACT IDS ===================================== { "title":"All Members: Contact ID (System field) equals \"1111\" OR Contact ID (System field) equals \"22222222\"", "include_behavior":false, "filters":{ "type":"Active", "criteria":[ { "type":"id", "operator":"=", "operand":[ "1111" ], "case_sensitive":0, "condition":"or", "field":"ocx_contact_id" }, { "type":"id", "operator":"=", "operand":[ "22222222" ], "case_sensitive":0, "condition":"or", "field":"ocx_contact_id" } ], "user_type":"all" }, "combined_as_and":false }
JSON Example of How To Create a Contact Search for All Members in a Given List
Endpoint: POST api/contact_search (e.g., https://api.ongage.net/12345/api/contact_search) where 12345 is the list_id. After you issue this request you'll be able to find that report under List → Contact Manager → Search
// Sample Request { "title": "All Members: Email is not empty", "include_behavior": false, "filters": { "type": "Active", "criteria": [{ "type": "string", "operator": "notempty", "operand": [""], "case_sensitive": 0, "condition": "and", "field_id": "123456" // This is the field id of the email field in that list. You can find that ID under List Settings -> Field Setup }], "user_type": "all" }, "combined_as_and": true } //Sample Response { "metadata": { "error": false }, "payload": { "list_id": 12345, "title": "All Members: Email is not empty", "include_behavior": false, "filters": { "type": "Active", "criteria": [ { "type": "string", "operator": "notempty", "operand": [ "" ], "case_sensitive": 0, "condition": "and", "field_id": "123456", "field_name": "email" } ], "user_type": "all" }, "combined_as_and": true, "account_id": 1234, "status": 1, "desc": "Pending", "id": 82169, // This is ID of the search report that was created "created": 1470930202, "modified": 1470930202 } }
How to Add a Date Filter to the Contact Search
See example 'from_date' and 'to_date' filters below:
// Sample Request { "title": "All Members: Email is not empty", "include_behavior": false, "filters": { "type": "Active", "criteria": [{ "type": "string", "operator": "notempty", "operand": [""], "case_sensitive": 0, "condition": "and", "field_id": "123456" // This is the field id of the email field in that list. You can find that ID under List Settings -> Field Setup }], "user_type": "all" "from_date": 1467320400, "to_date": 1471381199 }, "combined_as_and": true }
JSON Example for List: Copy, Create and Delete
JSON payload sample for copy list
POST api/lists/ { "list_id":32, "name":"testttt", "type":"sending" }
JSON payload sample for creating a list - list always created with field of default list
POST api/lists/<list_id>/copy? Request = array ( 'create' => true, 'name' => '<name>', 'description' => '', 'type' => 'sending', 'default' => false, )
JSON payload sample for delete list:
DELETE api/lists/<list_id> for adding a field: POST api/list_fields? Request = array ( 'name' => '<name>', 'title' => '<title>', 'type' => 'string', // string/email/date/numeric 'format' => 'yyyy-mm-dd',/* for date for example 'default' => '', 'position' => '<position in list>', 'mandatory' => NULL, 'list_id' => <list_id>, )
JSON payload sample for deleting list field:
DELETE api/list_fields/<field_id>
JSON Example How to Create a Segment Based on the Ongage Import ID
ocx_import_id is the system field that contains the import ID. As always the list_id can be indicated in numerous ways as indicated at the beginning of this guide.
POST /api/segments { "name":"Segment Based on Import ID", "type":"Active", "description":"Segment based on Import ID", "criteria":[ { "condition":"and", "field_name":"ocx_import_id", "type":"numeric", "position":0, "operator":"=", "operand":[ "11111111" ] } ] }