S’abonner

Créer une campagne

Only users with admin role may create a campaign through API.

As seen before, Basic Authentication header should be set to authenticate every call to the API. Please read this article for more details.

BEAR API being a REST one (look here for more details), we will have to use a POST request to create a campaign.

 

Following example is written in JavaScript with jQuery :

var user = 'admin';

var password = 'test';

var auth = "Basic " + btoa(user + ":" + password);

var urlApi = 'https://apidev.bear2b.com/campaigns';

var params = {name:'test'}; 

$.ajax({

   processData: true,

   type: 'POST',

   url: urlApi,

   headers: {"Authorization": auth},

   data: JSON.stringify(params),

   dataType: 'json',

   success: function(data){

       var campaign = data[0];

       $('body').html(campaign.id + ' ' + campaign.name);

   },

   error: function(data){

       $('body').html( data.responseJSON.error + ' ' + data.responseJSON.description );

   }

});

0 Commentaires

Veuillez vous connecter pour laisser un commentaire.