loading

Connect to API

You can connect to the API through a request (get,post,put,delete or update) using user-:secret@appsmsserver.com/index.php/api and by sending the header SIMP-API-KEY with the api key. We`ll have the following basic object:

var api = {
	key: "", //Your API Key
	user: "", // utilizator-proiect_id
	secret: "", //Project secret
	request: function(target, data, method, callBack, errorCallback) {
		target = (typeof target === "string") ? target : "";
		method  = (typeof target === "string") ? method : "get";
		data = (typeof data === "object") ? data : {};
		callBack = (typeof target === "function") ? callBack : function(){};
		errorCallback = (typeof errorCallback === "function") ? errorCallback : function(){};
		$.ajax({
            url: "https://"+api.user+":"+api.secret+"@appsmsserver.com/index.php/api/"+target,
            type: method,
            data: data,
            headers: {
                "SIMP-API-KEY": api.key
            },
            dataType: "json",
            success: function (data) {
                callBack(data);
            },
            error: function(xhr, ajaxOptions, thrownError) {
                var resp = JSON.parse(xhr.responseText);
                errorCallback(resp);
            }
        });
	},
	callBack: function(resp) {

	},
	errorCallback: function(resp) {

	}
};

Recieve data and query the API according to your needs.

Requesting the API to return SMS List.

(function(){
	api.request("sms/", {}, "get", function(resp) {
		//Do stuff - resp(Format: JSON)
		console.log(resp);
	},function(error) {
		console.log(error);
	});
})();

To get a specific SMS we have the following syntax:

(function(){
	var id = 2; //This is an example. The id must be owned by your project.
	api.request("sms/id/" + id, {}, "get", function(resp){
		//Do stuff - resp(Format: JSON)
		console.log(resp);
	}, function(error) {
		console.log(error);
	});
})();

To send an SMS we have to make the following request:

(function(){
	var data = {
		sms_phone: "004072222222",
		sms_text: "Hello! This is a test message.",
		sms_date: "2018-01-01", //Empty date, hours, minutes, seconds => instant sending, data format: YYYY-MM-DD
		sms_hour: "8",
		sms_min: "15",
		sms_priority: 1
	};

	api.request("sms", data, "post", function(resp){
		//Do stuff - resp(Format: JSON)
		console.log(resp);
	}, function(error) {
		console.log(error);
	});
});

To send data to the API, it must target a particular object in the List:

sms, 
users,
proiecte

Fiecare request trebuie sa trimita un obiect cu urmatoarele date in functie de alegerea anterioara:

sms_phone,sms_text,
sms_priority,sms_date,
sms_hour,sms_min

(function() {
	var data = {}; //Object containing data to be sent to the API (specific parameters required for each object targeted)
	api.request("target_object", data, "post", function(resp){
		//Do stuff - resp(Format: JSON)
		console.log(resp);
	},function(error) {
		console.log(error);
	});
});

Sends data related to the object used

(function() {
	var data = {sms_phone: "04073333333"};
	api.request("obiect/id/xx", data, "put", function(resp) {
		//Do stuff - resp(Format: JSON)
		console.log(resp);
	}, function(error) {
		console.log(error);
	});
});

var api = {
	init: function() {
		this.SMSList();
		this.getSMS(2); //2 it`s an example. You have to use the above function "SMSList" to get the ids of messages
		this.sendSMS(); 
	},
	key: "", //Your API Key
	user: "", // username-project_id
	secret: "", //Project secret
	request: function(target, data, method, callBack, errorCallback) {
		target = (typeof target === "string") ? target : "";
		method  = (typeof target === "string") ? method : "get";
		data = (typeof data === "object") ? data : {};
		callBack = (typeof target === "function") ? callBack : function(){};
		errorCallback = (typeof errorCallback === "function") ? errorCallback : function(){};
		$.ajax({
            url: "https://"+api.user+":"+api.secret+"@appsmsserver.com/index.php/api/"+target,
            type: method,
            data: data,
            headers: {
                "SIMP-API-KEY": api.key
            },
            dataType: "json",
            success: function (data) {
                callBack(data);
            },
            error: function(xhr, ajaxOptions, thrownError) {
                var resp = JSON.parse(xhr.responseText);
                errorCallback(resp);
            }
        });
	},
	callBack: function(resp) {

	},
	errorCallback: function(resp) {

	},
	SMSList: function() {
		api.request("sms/", {}, "get", function(resp) {
			//Do stuff - resp(Format: JSON)
			console.log(resp);
		},function(error) {
			console.log(error);
		});
	},
	getSMS: function(id) {
		id = (typeof id === "number") ? id : 0; //This is an example. The id must be owned by your project.
		api.request("sms/id/" + id, {}, "get", function(resp){
			//Do stuff - resp(Format: JSON)
			console.log(resp);
		}, function(error) {
			console.log(error);
		});
	},
	sendSMS: function() {
		var data = {
			sms_phone: "004072222222",
			sms_text: "Salut! Acesta este un mesaj de test!",
			sms_date: "2018-01-01", //Empty sms_date, sms_hour, sms_min => instant sending, date format: YYYY-MM-DD
			sms_hour: "8",
			sms_min: "15",
			sms_priority: 1
		};

		api.request("sms", data, "post", function(resp){
			//Do stuff - resp(Format: JSON)
			console.log(resp);
		}, function(error) {
			console.log(error);
		});
	}
};

(function() {
	api.init();
})();