Create campaign by message_id
Este endpoint crea una campaña que enviará N cantidad de notificaciones, el envío de notificaciones inicia pasado unos segundos después de ser creado.
Campos:
- name: Nombre para la campaña, opcional.
- message_id: UUID del contenido del mensaje a enviar, este mensaje debe existir en el servicio Message-persistance, obligatorio.
- segment_id: Un segmento se refiere a una agrupación de dispositivos que recibirán un mensaje. Mediante su id el servicio solicita a Message-persistance que retorne los dispositivos vinculados a dicho segmento.
- application_name: Bundle Id de la app objetivo, obligatorio.
- company_id: Campo para forzar a que compañia pertenece esta campaña, opcional.
- notifications: Arreglo de notificaciones a enviar, obligatorio.
- trust_id: trust_id del dispositivo objetivo, obligatorio.
- variables: objeto que permite enviar notificaciones custom a cada receptor, obligatorio pero se puede dejar vacío ""
Endpoint
Headers
Key | Value | Description |
---|---|---|
Content-Type | application/json | |
Authorization | Bearer {{access_token}} | access_token obtained in Atenea |
Url
Method: POST
URL: https://api.trust.lat/campaigns/api/v1/campaign
caution
Recuerda que para utilizar este endpoint es necesario un access token obtenido en el servicio Atenea
Body
{
"name": "test",
"message_id": "6ci36ec7-vf8e-4c28-963d-6c34f6f027de",
"application_name": "com.bundle_id.company",
"company_id": "1",
"notifications": [
{
"trust_id": "39455820-40e1-4201-a261-9bad76d8b775",
"variables": {}
},
{
"trust_id": "39455820-40e1-4201-a261-9bad76d8b774",
"variables": {}
}
]
}
Code Examples
- Curl
- JavaScript
- Python
curl --location --request POST 'https://api.trust.lat/campaigns/api/v1/campaign' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer `{{access_token}}`' \
--data-raw '{
"name": "test",
"message_id": "6ci36ec7-vf8e-4c28-963d-6c34f6f027de",
"application_name": "com.bundle_id.company",
"company_id": "1",
"notifications": [
{
"trust_id": "39455820-40e1-4201-a261-9bad76d8b775",
"variables": {}
},
{
"trust_id": "39455820-40e1-4201-a261-9bad76d8b774",
"variables": {}
}
]
}'
import requests
url = "https://api.trust.lat/campaigns/api/v1/campaign"
payload = "{\n \"name\": \"test\",\n \"message_id\": \"6ci36ec7-vf8e-4c28-963d-6c34f6f027de\",\n \"application_name\": \"com.bundle_id.company\",\n \"company_id\": \"1\",\n \"notifications\": [\n {\n \"trust_id\": \"39455820-40e1-4201-a261-9bad76d8b775\",\n \"variables\": {}\n },\n {\n \"trust_id\": \"39455820-40e1-4201-a261-9bad76d8b774\",\n \"variables\": {}\n }\n ]\n}"
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer `{{access_token}}`'
}
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
var axios = require('axios');
var data = JSON.stringify({"name":"test","message_id":"6ci36ec7-vf8e-4c28-963d-6c34f6f027de","application_name":"com.bundle_id.company","company_id":"1","notifications":[{"trust_id":"39455820-40e1-4201-a261-9bad76d8b775","variables":{}},{"trust_id":"39455820-40e1-4201-a261-9bad76d8b774","variables":{}}]});
var config = {
method: 'post',
url: 'https://api.trust.lat/campaigns/api/v1/campaign',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer `{{access_token}}`'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Responses
HTTP Code: 201 Created
{
"code": 201,
"resource": "Campaign",
"data": {
"application_name": "com.bundle_id.company",
"company_id": "1",
"created_at": "2020-05-26T17:29:50.813Z",
"message_id": "6ci36ec7-vf8e-4c28-963d-6c34f6f027de",
"name": "test",
"terminated": false,
"updated_at": "2020-05-26T17:29:50.813Z",
"uuid": "85or4058-q955-mf92-b399-5f00asd866e44"
},
"message": "Created"
}
HTTP Code: 404 Not Found
{
"code": 404,
"resource": "Message",
"message": "Not exists",
"errors": "Message not found on message_persistance service"
}
HTTP Code: 404 Not Found - App not found
{
"code": 404,
"resource": "App",
"message": "Not found"
}