For ease of use of UniSender API, you are recommended to use the PHP class we have developed for you. This class is universal, it will not become obsolete even if we add new methods or change the call procedure.
Using our class, you can completely disregard the network level and work directly with UniSender methods.
Let's see how to connect this class to your PHP project:
require_once("UniSender/UnisenderApi.php"); //enable the class file $apikey="abcdefghijklmnopqrstuvwxyz1234567890"; //API key to your personal account $uni=new UnisenderApiWrapperUnisenderApi($apikey); //create the class sample, we will work with later on
Class methods are API methods described in the documentation. For example, to create a new list in your personal account, just write:
Please note that you does not need to transfer the API key, the class does it automatically. The response received from API will be recorded in the $result variable. The answer is encoded into the JSON format, therefore, you need to run the following command to make it readable:
$answer = json_decode($result);
As a result, we will get an array in the $answer variable. Detailed documentation of the json_decode method is provided here.
Let us consider a more complex example — sending a single SMS message using the sendSms method.
$phone='+380123456789'; $sender='UniSender'; $text='This is test message from UniSender'; $result=$uni->sendSms(Array("phone"=>$phone,"sender"=>$sender,"text"=>$text));
The recipient's phone number, the sender's name and the message text are recorded to the $phone, $sender, $text variables, respectively. Then, just like in the previous example, call the sendSms method and transfer the parameters there.
You should note that there are methods where the parameter itself is an associative array. For example, it is the fields parameter in subscribe method. What should you do in this case?
$fields['phone']='+380123456789'; $fields['Name']='UserName'; $fields['email']='firstname.lastname@example.org';
Create the $fields array with the fields you need. Next, call the subscribe method and transfer the array to the required parameter.
As you can see, there is nothing difficult!