00:00Hello and welcome.
00:02This video is the second video in our API how-to series and will show you how to make
00:07a call using PHP and NetBeans IDE.
00:11For the purpose of this video, we are using NetBeans IDE 7.3.
00:17Firstly, let's open our NetBeans IDE program.
00:20Once opened, go to File and New Project.
00:24As discussed, we are going to use PHP.
00:27Now click on PHP Application.
00:31Click Next.
00:33Name the project Make underscore Cool.
00:39Save the project in your local hosts folder.
00:43We are using WAMP and www. Again, save this as Make underscore Cool.
00:52In terms of the version, we are going to use PHP version 5.4.
00:58Click Next.
01:00We are going to run this from our local host, so you can click on the next screen.
01:06We are not going to use any PHP framework, so you can click Finish once prompted with this
01:12screen.
01:14Your new project is now created.
01:18We now need to find this project by going to Source File and selecting Index.php.
01:25This file contains all of the code we need to get started.
01:29Before we add our code, we need to add the Suneti Account API clasp into our project.
01:35We can retrieve this from the development centre of the Suneti website.
01:39We have included a direct link to this section in the detail of this video.
01:43We now need to add this library to our project.
01:48This is just a sample you downloaded from the website as it includes the class we need
01:52for the library.
01:54Make sure you unzip the folder once you have downloaded it.
01:58The folder you are looking for is Account underscore LVL.
02:03You will then need to find the file Suneti underscore Account underscore API dot PHP.
02:11Copy this file and paste it into your project folder.
02:14Now we have copied the class, we now need to add a configuration file that contains some
02:19parameters we need to use in our project.
02:22To create these parameters, we need to go to Source Files, followed by New and PHP file.
02:29Name this file config.php.
02:33The config needs to contain three parameters.
02:36Username of the account you are going to use on this project, password of the account and
02:42license key.
02:43Now let's define those parameters.
02:52Firstly, username of the account you are going to use.
02:55This is your account ID.
03:04Secondly, we need to define the password for the account.
03:07Please note this is the service password.
03:12If you do not have access to your username and password, you can retrieve these from the
03:16Suneti portal by going to Configuration and Service Accounts.
03:20Find a user you wish to configure and click Configure.
03:24Their details will then be displayed.
03:27Finally, we need to add your license key.
03:31If you haven't yet created your unique license key or you need to access your current one,
03:36please go to the Suneti portal and click Integration and API license keys.
03:42Once you have your license key, copy and paste this into your code.
03:47Once all of your configuration parameters are entered and are correct, you will need to
03:52go to your index.php file.
03:55Here you will need to add the Suneti code.
03:58The first thing we need to do is to create a simple UI, a user interface, that takes two
04:04parameters from the user.
04:06The first parameter is the CLI and the second is the CLD.
04:11The CLI is the phone number of the caller.
04:14This is otherwise known as the first leg of the call.
04:18The CLD is the number of the caller, otherwise known as the second leg of the call.
04:25We need to create a very simple UI using HTML.
04:29This will contain two text fields.
04:32The first one will take the value of the CLI, input, type, text.
04:43We will name this CLI.
04:51We now need to create the second text field for the CLD.
04:54We will name this CLD.
04:57We will name this CLD.
04:582.
05:27We will name this CLD.
05:27We will name this CLD.
05:27So now it is the CLD.
05:35The final step here is to add the Submit button, otherwise known as Make a Call button.
05:41We will name this Make underscore Call.
06:06Before we add the code to process the request and make calls, we need to specify the method
06:11we are going to use and the URL we are going to send the request to.
06:14We are going to use a post method and sync the same URL to the same page.
06:20To do this, set action to the same page.
06:41Now we have finished building our simple user interface, we now need to write the code to
06:46action the request.
06:48We need to make sure we include the library.
06:51To do this, at the top of the page we need to write that we require the Suneti library.
06:55Use the library we added before.
07:13We need to create an object of the class.
07:16This will be Suneti underscore API equals new Suneti underscore account underscore API.
07:37Before we write the code to process the request, we need to make sure the form says method and
07:42not type, as demonstrated.
07:46Now let's write the code to process the request.
07:49We need to make sure we don't process the request if it is not coming from the CLI and CLD
07:54we
07:54mentioned in the above form, which has post as method.
07:59The code you need is if I set post make underscore call.
08:10This will check if the post field is called make underscore call.
08:14If it comes to the request, we need to process this request.
08:17We need to pass the parameters from the form.
08:21The first one is the CLI.
08:23We need to check whether the parameters are empty or not valid for members.
08:30First of all we need to remove any space in the parameters passed to the process.
08:35This code will remove any spaces in the CLI.
08:39We will do the same for CLD.
09:09Now let's check to see if we have any space in the CLI.
09:13The first check is for empty string.
09:17So, if empty CLI or empty CLD, we need to display a message that prompts the user to complete
09:24all fields.
09:37all fields.
09:39We have set the colour to fire brick.
09:53Please complete all fields.
10:03Secondly, we need to check whether it's a valid number or not.
10:07We can do this by using built-in function PHP code.
10:28If the CLI or CLD variables do not contain a valid number, we need to display another message.
10:55If the function finds anything that is not a number, it will display the error message we
11:00have included.
11:01This error message being, please enter valid phone numbers.
11:06Finally, we need to enter the code that processes the request.
11:10This is simple.
11:11We just need to execute one function.
11:15To get the response of this function, we use the object at the top of the page.
11:19cnety underscore account underscore api class.
11:49Now we need to add the make underscore call method.
11:53We just need to pass the CLI and CLD to make this function work.
12:08Finally, we need to echo the response.
12:20This response will determine if the call was successful or not.
12:24Our code is now finished.
12:26Now it's time to test what we have written.
12:29Don't forget to save your configuration.
12:32To test your project, open a new browser and type the address localhost forward slash
12:43index dot php.
12:47Your CLI and CLD boxes will now appear.
12:51Enter your details.
12:59If you leave the CLD box empty, your message of please complete all fields appears.
13:07Now let's try testing an invalid number.
13:11Our message of please enter valid phone numbers appears.
13:16Finally, for our third test we will add a valid number in both fields.
13:28As you can see, and hear, the call is valid.
13:32The response shows that the call was made.
13:35It shows the session ID of the call and also shows the CLI and CLD numbers of the calls and
13:41various other details.
13:43We hope you have found this video useful.
13:45Please watch our other API videos that are available from the Sonetti site.