Creating a simple target
Mindbaz target
A simple target allows you to target the subscribers of your MINDBAZ database. You can use them to send a test bat, a campaign or define an export. A target is composed of several criteria called "filter".
There are several types of filters:
- declarative filters (e.g. > postal code, address, opt-in type, webmail, etc),
- behavioural filters (e.g. > opened / clicked on a campaign),
- geolocation filters
- file filters (selects emails present in a file)
- etc.
A target must first be created with the Targets api and then filters are assigned to it with the targetFilters api.
In the interface, it is also possible to create combined targets. This type of target combines several targets by making a union, intersection or subtraction between them. The targets api does not currently allow the creation of this type of target.
Creating a simple target
First, let's create our first target by calling POST api/{idsite}/Targets.
The parameters to specify in the url are the following:
Name | Description | Type | Additional information |
---|---|---|---|
idsite | MindBaz site identifier | Integer | Mandatory |
In the query body, the parameters to be passed in the form "application/json, text/json " are as follows:
Name | Description | Type | Additional information |
---|---|---|---|
name | Name of the target (255 carac max) | String | Mandatory |
isTestTarget | true if it is a target for BAT | Boolean | None |
pctSelect | Percentage of the target to select (100 by default). | Integer | None |
maxSelect | Maximum number of emails to be selected by the target (if defined, maxSelect replaces pctSelect). | ||
isRandomMode | True to activate the random mode (useful with a percentage lower than 100). Caution: only for standard targets Caution: do not exclude a target that is in random mode because the excluded population will be different for each calculation** | Boolean | None |
excludedTargets | List of target ids to exclude from the target. | Integer Collection | None |
isAutomation | true if it is an Automation Target | Boolean | Deprecated |
Example
Here is an example to create a target that randomly selects 10 emails after excluding the result of target id 1 and 2.
[
{
"name": "sample string 1",
"isTestTarget": false,
"maxSelect": 10,
"isRandomMode": true,
"excludedTargets": [
1,
2
]
}
]
In return for the call, I get the information of the newly created target:
{
"success": true,
"data": {
"id": 183813,
"parameters": {
"name": "sample string 1",
"isTestTarget": false,
"pctSelect": 100,
"maxSelect": 10,
"isRandomMode": true,
"excludedTargets": [1,2],
"isAutomation": false
},
"creationDate": "2021-08-25T11:29:41.961503+02:00",
"lastUpdateDate": "2021-08-25T11:29:41.961503+02:00",
"targetType": 1,
"hasFieldFilter": false,
"hasGeolocFilter": false,
"hasSqlFilter": false,
"hasEmailPressureFilter": false,
"hasBehaviourFilter": false,
"hasReactivityFilter": false,
"hasSendingFilter": false,
"hasFileFilter": false,
"hasThematicFilter": false
},
"error": null,
"typeName": "Target"
}
Codeline of a simple target
- C#
- Java
- Python
string token = ""; //Valeur du token récupéré pour l'authentification
string idSite = ""; //Valeur de l'identifiant du site
var client = new RestClient("https://api.mindbaz.com/api/" + idSite + "/targets/");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer " + token);
request.AddHeader("Content-Type", "application/json");
var body = @"{""name"": ""sample string 1"",""isTestTarget"": false,""maxSelect"": 10,""isRandomMode"": true,""excludedTargets"": [1,2]}";
request.AddParameter("application/json", body, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://api.mindbaz.com/api/{idsite}/targetfilters/field")
.header("Authorization", "Bearer `TOKEN`")
.header("Content-Type", "application/json")
.body("{\"name\": \"sample string 1\",\"isTestTarget\": false,\"maxSelect\": 10,\"isRandomMode\": true,\"excludedTargets\": [1,2]}")
.asString();
import http.client
import json
conn = http.client.HTTPSConnection("api.mindbaz.com")
payload = json.dumps({
"name": "sample string 1",
"isTestTarget": false,
"maxSelect": 10,
"isRandomMode": True,
"excludedTargets": [
1,
2
]
})
headers = {
'Authorization': 'Bearer `TOKEN`',
'Content-Type': 'application/json'
}
conn.request("POST", "/api/{idsite}/targets/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
At this point, we have created a target but no filter is defined. At this step, the target is not yet usable and cannot appear in the target manager in the interface. For the target to be valid, it must have at least one filter.
Creating a filter
Our target needs at least one filter to work. To create one, you can use the call corresponding to the desired filter type:
- Filter by field (POST api/{idsite}/targetfilters/{idTarget}/field)
- Filter by sql (POST api/{idsite}/targetfilters/{idTarget}/sql)
- Filter by behaviour (POST api/{idsite}/targetfilters/{idTarget}/behaviour)
- Filter by sending (POST api/{idsite}/targetfilters/{idTarget}/sending)
- Filter by file (POST api/{idsite}/targetfilters/{idTarget}/file)
- Filter by theme (POST api/{idsite}/targetfilters/{idTarget}/thematic)
- Filter by geolocation (POST api/{idsite}/targetfilters/{idTarget}/geoloc)
- Filter by email pressure (POST api/{idsite}/targetfilters/{idTarget}/pressure)
A single target can only have one filter of each type.
Filter by field
For the example, we will create a filter by field:
The parameters to be specified in the url are as follows:
Name | Description | Type | Additional information |
---|---|---|---|
idsite | MindBaz site identifier | Integer | Mandatory |
In the query body, the parameters to be passed in the form "application/json, text/json " are as follows:
Name | Description | Type | Additional information |
---|---|---|---|
idTarget | target identifier | integer | Mandatory |
isEnabled | true if filter is enabled | Boolean | None |
filters | List of field filters (operations) to be applied to each field. Note that an idField cannot have more than one filter at a time! | Collection of FieldFilter | None |
The FieldFilter type is a collection of fields representing the following:
Name | Description | Type | Additional information |
---|---|---|---|
idField | Field identifier (0 = id, 1 =email...). The list of fields can be retrieved here. Click here for more information. | Integer | Mandatory |
operator | Operator to use | EOperator | Required |
value | Value of the field to be used with the operator. For the Date type, the format dd/MM/yyyy must be used. For the List type, the id corresponding to the desired value must be used. For example, to make "subscriber status" = "subscriber". You must use { idField=7, operator=3,value=0} | Object | Required |
The EOperator type is of type Enum:
- "HasValue"
- "NoValue
- "Equals"
- "DifferentThan"
- "LessThan" (for Number and Date type only)
- "MoreThan" (for Number and Date type only)
- "Between" (for Number and Date type only)
- "DatePast" (for type Date only)
- "DateFuture" (for Date type only) 10.
- "NbDaysMoreThan" (for Date type only)
- "NbDaysLessThan" (for type Date only)
- "AgeGreaterThan" (for type Date only)
- "AgeLesserThan" (for type Date only)
- "AgeBetween" (for type Date only)
For the operators "Equals" and "DifferentThan", you can combine several values by separating them with a ";". A logical OR will be applied between the values.
You can for example create a test target with a field filter on the email by passing several emails separated by ";". As the length of the field is limited, if you have a lot of values to include, it will be better to use a filter by file.
Example
We will add email address informed
and subscriber status equal to unsubscribed
.
{
"idTarget": 183813,
"isEnabled": true,
"filters": [
{
"idField": 1,
"operator": 1
},
{
"idField": 7,
"operator": 3,
"value": "1"
}
]
}
The return code is as follows:
{
"success": true,
"data": true,
"error": null,
"typeName": "Boolean"
}
Codeline of a filter by field
- C#
- Java
- Python
string token = ""; //Value of the token recovered for the authentication
string idSite = ""; //Value of the site identifier
var client = new RestClient("https://api.mindbaz.com/api/" + idSite + "/targetfilters/field");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer " + token);
request.AddHeader("Content-Type", "application/json");
var body = @"{""idTarget"": 183813,""isEnabled"": true,""filters"": [{""idField"": 1,""operator"": 1},{""idField"": 7,""operator"": 3,""value"": ""1""}]}";
request.AddParameter("application/json", body, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://api.mindbaz.com/api/{idsite}/targetfilters/field")
.header("Authorization", "Bearer `TOKEN`")
.header("Content-Type", "application/json")
.body("{\"idTarget\": 183813,\"isEnabled\": true,\"filters\": [{\"idField\": 1,\"operator\": 1},{\"idField\": 7,\"operator\": 3,\"value\": \"1\"}]}")
.asString();
import http.client
import json
conn = http.client.HTTPSConnection("api.mindbaz.com")
payload = json.dumps({
"idTarget": 183813,
"isEnabled": True,
"filters": [
{
"idField": 1,
"operator": 1
},
{
"idField": 7,
"operator": 3,
"value": "1"
}
]
})
headers = {
'Authorization': 'Bearer `TOKEN`',
'Content-Type': 'application/json'
}
conn.request("POST", "/api/{idsite}/targetfilters/field", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))