As always, to authenticate a call Basic Authentication header should be set. See this for details. As soon as BEAR API is REST one (read here for details), to create a marker we have to use POST request to markers.
To create a marker you have to know ID of the campaign this marker will be added to. See how to create a campaign here. To get list of campaigns, you can call GET http://apidev.bear2b.com/campaigns
There are 2 ways to provide actual image file to be used as marker – over an URL or by selecting a file from the local drive.
Create a marker from an URL
Code (working example here):
var user = 'user';
var password = 'test';
var auth = "Basic " + btoa(user + ":" + password);
var urlApi = 'https://apidev.bear2b.com/markers';
// Users allowed to add markers to their own campaigns or to campaigns of their company
var campaignId = 649; // user's campaign (Your First Campaign)
// Note: you can get list of your campaings by calling GET http://apidev.bear2b.com/campaigns
var params = {
book_id:campaignId,
url:'http://apidev.bear2b.com/media/1555f2f0f1618a.jpg'
};
$.ajax({
processData: true,
type: 'POST',
url: urlApi,
headers: {"Authorization": auth},
data: JSON.stringify(params),
dataType: 'json',
success: function(data){
var marker = data[0];
console.log(marker);
$('body').html('#'+marker.id + ' ' + marker.page_num);
},
error: function(data){
$('body').html( 'Marker has been created!' );
$('body').html( data.responseJSON.error + ' ' + data.responseJSON.description );
}
});
Send markers as a file
Live example here
<form action="http://user:test@apidev.bear2b.com/markers" method="POST" enctype="multipart/form-data">
<p>campaign id:<input name="book_id" type="text" value="649"/></p>
<p>marker:<input name="file" type="file" /></p>
<p><button type="submit">Submit</button></p>
</form>