Platform Documentation

API reference

Explore Apifonica products

Platform
Build unique voice & messaging processing logic and automation workflows with zero need for costly hardware or software.
Voicebot
Create more modern and valuable communications with IVR, AI, and automation.
SMS Campaigns
Encourage customers to interact with your business by contacting them on their most personal communication device: a mobile phone.
Incognito
Protect customer privacy and record calls to improve customer service, anonymity, and security.
Documentation

How to build with Apifonica

Bulk SMS Messaging

Mass text messaging

Enable your site administrator to launch an SMS marketing campaign using the mobile numbers of your customers who opt-in to receive such information.

Learn how to send the same text message to a list of your customers (for example, marketing or event notification) right from your web site.

What does this thing do?

This PHP sample application demonstrates how to create a web form that sends bulk SMS to the specified mobile phone numbers. In this tutorial, we will show you the HTML form that accepts a message and a list of recipient numbers, and the code that sends the message via SMS to these mobile numbers at one click and checks message delivery statuses by using Apifonica API.

Let’s get started!

Prerequisites

  1. An Apifonica account SID and password to send SMS messages from the web. You can find these in your personal account.
  2. An Apifonica phone number to be the SMS sender’s number. You can rent a number from your Apifonica account.
  3. An Apache/nginx HTTP server supporting PHP version 5 or higher.

Step 1. Get the Code

Click here to download the source (case02.php), which includes everything you need for this tutorial.

The file contains an HTTP form to be displayed to the site administrator who will run the SMS campaign. It also has the functions that send your marketing content via SMS messages to all mobile numbers specified by the administrator, and check SMS delivery statuses.

The following diagram demonstrates how the sample works.

Step 2 – Set Default Variables

In the downloaded case02.php file, specify the default parameter values:

  • Your account SID.
  • Your account password (authToken).
  • A number you have rented from this account—this number will be used as the SMS sender’s number.

It is recommended that you use an alpha name as the sender’s number. You can register an alpha name in the the personal account.

// Specify Apifonica API URL
$api_url = 'https://api.apifonica.com';
// Specify your Apifonica account SID
$accountSID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
// Specify your Apifonica account password
$password = 'XXXXXXXXXXXX';
// Specify the message sender's number or alpha-name (this number must belong to the Apifonica account you have specified)
$from = '883XXXXXXXXXXXX';

Step 3 – Upload the Updated Sample File to Your Server

The data you have specified will now be used for sending SMS messages: your Apifonica account will be charged for outgoing SMS messages sent from the web to those mobile numbers you specify in the web form.

Step 4 – Open the Web Form on Your Site and Try How It Works

Fill in the fields in the web form and click Send Your Message to send a message notification to multiple recipients via SMS from the browser.

Step 5 – Check the Message Delivery

Click the Update Delivery Status button to see that your message is sent and then delivered to your customers’ mobiles.

Calling a mobile phone from your website

Enable your site visitors to call mobile numbers while they are on the site.

The following guide explains how to create a web form that enables users to make calls to a specified number via a REST API request.

Download source

How it works

This PHP sample application demonstrates the creation of a web contact form that calls a specified mobile number from your Apifonica account. The call is made using the data the user specifies in the form. Call status is then checked using Apifonica API.

Let’s get started!

Prerequisites

  1. An Apifonica account SID and password to make phone calls from a web site. You can find these in your personal account.
  2. An application SID for an application you have registered at the Apifonica Account web site’s Manage Applications page.
  3. An Apifonica phone number to call from. You can rent a number from your Apifonica account.
  4. An Apache/nginx HTTP server supporting PHP version 5 or higher and cURL.

Step 1. Get the Code

Click here to download the source (call.php), which includes everything you need in this example.

The file contains an HTTP form to be displayed to site visitors, as well as the backend function to make the call to the predefined mobile number and check its status.

The following diagram demonstrates how the sample works.

Step 2. Upload the Source Code File to Your Server

Copy the source code file you have downloaded to a directory on your web server capable of serving PHP code

Step 3. Open the Web Form on Your Web Site and Fill Out the Required Data

Fill in the fields in the web form. You will need to fill out the following fields:

  • Your account SID.
  • Your account password (authToken).
  • Your application SID.
  • A number you have rented for this account. It will be used as the caller’s number.
  • A recipient’s mobile phone number.

Step 4. Make the Call

Click the Make Your Call button to execute the call from your browser. The mobile phone you have specified in the input form should receive the call shortly.

The Apifonica account with the credentials you have provided will be charged for the outgoing calls from your web server to the mobile number(s) you have specified.

Step 5. Check the Message Delivery

Click the Check Your Call Status button to verify that your call has been successfully created.

Configuring Zoiper to make a SIP call using Apifonica

This article describes how you can use APIFONICA API to obtain a phone number and initiate a voice call by the example of ZoiPer — a free VoIP SIP softphone dialer.

Step 1. Prerequisites

  1. Register at apifonica.com and create an Apifonica account.
  2. Top up the balance.
  3. Rent an Apifonica voice phone number to be used for calling:

    • Using a personal account: You can search and rent a number here
  4. Change the default mode and the default password of the rented number (password for outbound and inbound calls has to be the same, you will need this password during account creation in ZoiPer):

    • Using a personal account: You can set that in the properties of the rented number by clicking it.
      • Outbound configuration example:
      • Inbound configuration example

Step 2

  1. Download and install ZoiPer on your Android phone from GooglePlay or download the app from the website
  2. Use the server, login and password details from the “Settings”, “SIP Connection” section of your personal profile.

    Username: [email protected] – where 1423 is the SIP number from your personal profile

    Password: your SIP number password, from the “SIP Connection” section of your personal profile

    After entering the details click “Login”.

  3. Enter the sip-eu.apifonica.com server address on the next page and click “Next”.

  4. There is no need to enter the settings on this page, click “Skip”.

  5. On the next page, Zoiper will attempt to find the priority transport for your network. Select SIP UDP or SIP TLS and click “Next”.

  6. You can test the audio devices on the next page. The setup is now complete.

*Important! You will be charged for the calls in accordance with the tariffs.

Note You can also use any softphone application of your choice.

Contacting you by SMS from your website

Enable your site visitors to contact you by sending SMS messages.

Learn how to build a contact form on a website that will send user requests via SMS to a predefined phone number belonging, for example, to the sales or support team.

Download source

What does this thing do?

This PHP sample application demonstrates how to create a web contact form that sends SMS to the specified mobile phone number. In this tutorial, we will show you the HTML form that accepts user messages and the code that sends these messages via SMS and checks message delivery statuses by using Apifonica API.

Let’s get started!

Prerequisites

  1. An Apifonica account SID and password to send SMS messages from the web. You can find these in your personal account.
  2. An Apifonica phone number to be the SMS sender’s number. You can rent a number from your Apifonica account.
  3. An Apache/nginx HTTP server supporting PHP version 5 or higher and cURL.

Step 1. Get the Code

Click here to download the source (case.php) which includes everything you need for this tutorial.

The file contains an HTTP form to be displayed to site visitors, and also the functions to send user input via SMS messages to the predefined mobile number and check SMS delivery statuses.

The following diagram demonstrates how the sample works.

Step 2. Set Default Variables

In the downloaded case file, specify the default parameter values:

  • Your account SID.
  • Your account password (authToken).
  • A number you have rented from this account—this number will be used as the SMS sender’s number.
  • A mobile number to receive SMS messages—this number will be used as recipient’s phone number.
// Specify Apifonica API URL
$api_url = 'https://api.apifonica.com';
// Specify your Apifonica account SID
$accountSID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
// Specify your Apifonica account password
$password = 'XXXXXXXXXXXX';
// Specify the message sender's number (this number must belong to the Apifonica account you have specified)
$from = '883XXXXXXXXXXXX';
// Specify the mobile number to receive SMS messages sent from the web form
$to = 'XXXXXXXXXX';

Step 3. Upload the Updated Sample File to Your Server

The data you have specified will now be used for sending SMS messages: your Apifonica account will be charged for outgoing SMS messages sent from the web to the predefined mobile number.

Step 4. Open the Web Form on Your Site and Try How It Works

Fill in the fields in the web form and click the Send Your Message button to send the SMS message from the browser.

Step 5. Check the Message Delivery

Click the Update Delivery Status button to see that your message is sent and then delivered to your mobile.

Establishing a call between soft/hard phone and other phone number

Step 1. Prerequisites

  1. Register at apifonica.com and create your Apifonica account.
  2. Top up the balance and make sure that the balance is not less than 5 EUR before testing the functionality.
  3. In your personal account, find your Apifonica AccountSID and password (AuthToken).
  4. Rent an Apifonica voice phone number to link it with soft/hard phones:

    1. Using personal account: You can search and rent a number here
    2. Using Console: make the GET request to /accounts/{accountSID}/availableNumbers (get list of available countries), then make the GET request to /accounts/{accountSID}/availableNumbers/{countryCode} (available numbers for specified country) and finally make the POST request to /accounts/{accountSID}/numbers (rent phone number)
  5. Change the default mode and the default password of the rented number:

    • Using personal account: In the properties of the rented number set the password for sip-calls and check the mode option to sip_phone.
    • Using Console: make the PUT request to /accounts/{accountSID}/numbers/{numberSID} (Change number properties)

      curl –X PUT ‘https://api.apifonica.com/v2/accounts/{accountSID}/numbers/{numberSID}’
       -H ‘Content-Type: application/json’
       -d ‘{
       "sip_password":"qwerty12345",
       "mode":"sip_phone"
       }’
       -u {accountSID}:{authToken}

      Response example

      {
         "status_code": 200,
         "status_message": "OK",
         "uri": "/accounts/{accountSID}/numbers/{numberSID}"
       }

Step 2. Registration

To register a sip soft/hard phone in the Apifonica platform you need to specify:

  • sip server addres (host): sip-eu.apifonica.com
  • sip login (user name): voice number you have purchased
  • sip password: password that was set up in Step 1

For more details please refer to Configuring Zoiper to make a SIP call using Apifonica How-To.

Now your soft/hard phone is ready to make and receive the calls via Apifonica platform.

Step 3

  1. Create a simple XML file with a number you want to call. Example:

    <?xml version="1.0" encoding="UTF-8"?>
     <response>
       <makeCall>
         <number>35315313424</number>
       </makeCall>
     </response>

    Full Apifonica XML format can be found here. Upload ready XML to your server

  2. Create an application:

    • Using Console: Make the POST request to /accounts/{accountSID}/applications (Create application)
    • Using personal account: You can create it here
  3. Associate your XML with the created Application:

    • Using Console: make the PUT request to /accounts/{accountSID}/applications/{applicationSID} to change “controller” parameter (Update app properties)
    • Using personal account: Insert the link to your XML to the line Controller here

Step 4. Connection setup

  1. Making the calls using Console (Make voice call):

    • make the POST request to /accounts/{accountSID}/calls
    • “from“ parameter is a number rented from Apifonica
    • “to“ parameter is a number, connected to soft/hard phone, which receives the call (Step 2)
    • “Call_app_sid” parameter is Application SID of created application where a link to XML with the second phone number should be indicated (Step 3, Point 3)
  2. Making the callback using personal account:

    • Click the Sandbox
    • Choose accountSID in the list of your accounts/subaccounts
    • Choose “from“ parameter in the list of numbers rented from Apifonica
    • Fill in “to“ parameter – a number connected to soft/hard phone, which receives the call (Step 2)
    • Choose “Controller“ parameter – find in the list of created applications the name of application where a link to XML with the second phone number should be indicated (Step 3)

After that the call is connected between the soft/hard phone and the other local or mobile number.

Implementing callback functionality

Step 1. Prerequisites

  1. Register at apifonica.com and create an Apifonica account, if you have not done so already.
  2. Rent an Apifonica local or virtual phone number to be used for calling.
  3. You can find instructions on registering Apifonica accounts and renting numbers here.
Download source

Step 2. Creating files and applications

  1. Create a simple XML file and upload the created XML to your server.
  2. Create an application and associate the XML file you have created with it.

Detailed instructions on creating XML files and applications can be found here.

Step 2. Creating files and applications

  1. Making the callback using Console (Make voice call):

    • make the POST request to /accounts/{accountSID}/calls
    • “from“ parameter is a number rented from Apifonica
    • “to“ parameter is a number which receives the call (point 1)
    • “Call_app_sid” parameter is Application SID of created application in which a link to XML is set up (point 2)
  2. Making the parallel call using personal account:

    • Go to Sandbox
    • Choose accountSID in the list of your accounts/subaccounts
    • Choose “from“ parameter in the list of numbers rented from Apifonica
    • Fill in “to“ parameter – a number which receives the call (point 1)
    • Choose “Controller“ parameter – find in the list of created applications the name of the application in which a link to the XML file is set up (point 2).
  3. After that the call is connected between the customer and the user.

Step 4. Statistics

  1. To get call statistics (logs), please use the console to make a GET request to /accounts/{accountSID}/calls (get call history).
  2. To get the list of expenses, please make a GET request to /accounts/{accountSID}/balance/expenses (get expenses history). You can also get the list of expenses via the personal account.

You can implement this functionality into virtually everything that supports html. For example, setting up a simple website allows you to have plain text link to it directly in your company’s e-mails.

Making parallel calls to two numbers

Step 1. Prerequisites

  1. Register at apifonica.com and create an Apifonica account, if you have not done so already.
  2. Rent an Apifonica local or virtual phone number to be used for calling.
  3. You can find instructions on registering Apifonica accounts and renting numbers here.

Step 2. Creating files and applications

  1. Create a simple XML file and upload the created XML to your server.

    The XML file to be used for parallel calls should look as follows:

    <?xml version="1.0" encoding="UTF-8"?>
     <response>
       <makeCall>
         <number>883xxxxxxxxxxx1</number>
         <number>883xxxxxxxxxxx2</number>
       </makeCall>
     </response>

    where 883xxxxxxxxxxx1 and 883xxxxxxxxxxx2 are numbers you are calling in parallel.

  2. Create an application and associate the XML file you have created with it.

    Detailed instructions on creating XML files and applications can be found here.

Step 3. Making the call

  1. Making the parallel call using console (Make voice call):

    • make the POST request to /accounts/{accountSID}/calls
    • “from“ parameter is a number rented from Apifonica
    • “to“ parameter is a number which receives the call (point 1)
    • “Call_app_sid” parameter is Application SID of created application in which a link to XML is set up (point 2)
  2. Making the parallel call using personal account:

    • Go to Sandbox
    • Choose accountSID in the list of your accounts/subaccounts
    • Choose “from“ parameter in the list of numbers rented from Apifonica
    • Fill in “to“ parameter – a number which receives the call (point 1)
    • Choose “Controller“ parameter – find in the list of created applications the name of the application in which a link to the XML file is set up (point 2).
  3. You can also use the test script provided in this example to test parallel call functionality by entering the Application SID of the application you have registered in Step 2 into the appropriate field of the HTML form.
  4. The call between the customer and the user is connected.
  5. After the recipient accepts the call, the second leg of the call is executed. The two numbers specified in the makeCall section of the XML file are called in parallel. The connection is then established with the number that answers the call first. After the first call is answered, the second one is ignored.
  6. Step 4. Statistics

    1. To get call statistics (logs), please use the console to make a GET request to /accounts/{accountSID}/calls (get call history).
    2. To get the list of expenses, please make a GET request to /accounts/{accountSID}/balance/expenses (get expenses history). You can also get the list of expenses via the personal account.

    You can embed this functionality into virtually anything that supports HTML.

Two-Factor authentication

Add one more layer of security to your web site with the account verification feature, and also keep your customer personal phone number up to date.

Learn how to implement phone number verification functionality on your web site by using Apifonica API.

Download source

What does this thing do?

This PHP sample application demonstrates how to create a web site signup form that verifies user mobile number.

The user registration process will be the following:

  1. Your customer enters his name and a mobile phone number into a signup form.
  2. Your web site generates a one-time verification code, and sends it via Apifonica API to the user’s mobile phone to ensure the user physically possesses it. The user enters the code into a verification form to complete the registration process.
  3. There is also a possibility to organize two-factor authentication while excluding sms or voice traffic cost when user authenticates. Renting several amount of numbers from Apifonica, you can code them to be authenticators themselves. While showing customer a number to call (for example providing it in a authorization form or on a website itself), it can be set to hangup immediately and Apifonica will register the call thus authenticating user. To ease-up the process you can also generate a QR code for the Apifonica’s number, giving your customer a simple and elegant authentication process.

In this tutorial, we will show you the HTML form that accepts user data and verification code, and the functions that send this code via SMS to the user’s mobile number and check the code validity.

Let’s get started!

Prerequisites

  1. An Apifonica account SID and password to send SMS messages from the web. You can find these in your personal account.
  2. An Apifonica phone number to be the SMS sender’s number. You can rent a number from your Apifonica account.
  3. An Apache/nginx HTTP server supporting PHP version 5 or higher.

Step 1. Get the Code

Click here to download the source (case03.php), which includes everything you need for this tutorial.

The file contains an HTTP signup form to be displayed to the users desiring to register at your web site. The file also has the functions that generate five digit verification code, send it as an SMS message to the mobile number specified by the user, and check if the entered verification code is valid.

The following diagram demonstrates how the sample works.

Step 2 – Set Default Variables

In the downloaded case03.php file, specify the default parameter values:

  • Your account SID.
  • Your account password (authToken).
  • A number you have rented from this account—this number will be used as the SMS sender’s number.

It is necessary that you use a mobile number as the sender’s number. Enter it with the area code, but without a plus sign in the beginning.

// Specify Apifonica API URL
$api_url = 'https://api.apifonica.com';
// Specify your Apifonica account SID
$accountSID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
// Specify your Apifonica account password
$password = 'XXXXXXXXXXXX';
// Specify the message sender's number (this number must belong to the Apifonica account you have specified)
$from = '883XXXXXXXXXXXX';
// Specify the mobile number to receive SMS messages sent from the web form
$to = 'XXXXXXXXXX';

Step 3 – Upload the Updated Sample File to Your Server

The data you have specified will now be used for sending SMS messages with verification codes: your Apifonica account will be charged for outgoing SMS messages sent from the cloud to the mobile numbers your users specify in the web form.

Step 4 – Open the Web Form on Your Site and Try How It Works

Fill in the fields in the web form and click Send Verification Code in order to generate a one-time verification code and send it to the mobile number you have specified. Include the area code, but omit the plus sign.

Step 5 – Enter the Code You Receive in SMS

After you receive an SMS with the code, enter it and click the Proceed button to complete the registration.

Step 6 – Check Code Validity

In case you enter the valid code, the registration process is successfully completed.

Ready to get started?

See how Apifonica can help you automate customer communication and scale with confidence.