Download and install nexmo/client without Composer
Shortdescription PHP Client for using Nexmo's API.
Rated 5.00 based on 1 reviews
All versions of client with dependencies
Informations about the package client
Nexmo Client Library for PHP
This library requires a minimum PHP version of 5.6
This is the PHP client library for use Nexmo's API. To use this, you'll need a Nexmo account. Sign up for free at nexmo.com. This is currently a beta release, see contributing for more information.
To use the client library you'll need to have created a Nexmo account.
To install the PHP client library to your project, we recommend using Composer.
You don't need to clone this repository to use this library in your own projects. Use Composer to install it from Packagist.
If you're new to Composer, here are some resources that you may find useful:
- Composer's Getting Started page from Composer project's documentation.
- A Beginner's Guide to Composer from the good people at ScotchBox.
If you're using Composer, make sure the autoloader is included in your project's bootstrap file:
Create a client with your API key and secret:
Sending a Message
To use Nexmo's SMS API to send an SMS message, call the
The API can be called directly, using a simple array of parameters, the keys match the parameters of the API.
The API response data can be accessed as array properties of the message.
A message object is a more expressive way to create and send messages. Each message type can be constructed with the required parameters, and a fluent interface provides access to optional parameters.
The message object is passed to the same
Once sent, the message object can be used to access the response data.
Array access can still be used:
If the message text had to be sent as multiple messages, by default, the data of the last message is returned. However, specific message data can be accessed using array notation, passing an index to a getter, or iterating over the object.
The send example also has full working examples.
Receiving a Message
Inbound messages are sent to your application as a webhook, and the client library provides a way to create an inbound message object from a webhook:
You can also access the webhook data as an array:
Fetching a Message
You can retrieve a message log from the API using the ID of the message:
If the message was sent to a Nexmo virtual number, the object will be an instance of
the message was sent from your account, it will be an instance of
Nexmo\Message\Message. You can also pass a message
object to the client:
Signing a Message
The SMS API supports the ability to sign messages by generating and adding a signature using a "Signature Secret" rather than your API secret. The algorithms supported are:
Both your application and Nexmo need to agree on which algorithm is used. In the dashboard, visit your account settings page and under "API Settings" you can select the algorithm to use. This is also the location where you will find your "Signature Secret" (it's different from the API secret).
Create a client using these credentials and the algorithm to use, for example:
Using this client, your SMS API messages will be sent as signed messages.
Starting a Verification
Nexmo's Verify API makes it easy to prove that a user has provided their own phone number during signup, or implement second factor authentication during signin.
You can start a verification process using a simple array:
Or you can pass the client a verification object:
Controlling a Verification
To cancel an in-progress verification, or to trigger the next attempt to send the confirmation code, you can pass either an existing verification object to the client library, or simply use a request ID:
Checking a Verification
In the same way, checking a verification requires the code the user provided, and an existing verification object:
Or a request ID:
Searching For a Verification
You can check the status of a verification, or access the results of past verifications using either an existing verification object, or a request ID. The verification object will then provide a rich interface:
You can also access the raw API response here using array access:
Making a Call
$client->calls() methods require the client to be constructed with a
Nexmo\Client\Credentials\Keypair, or a
Nexmo\Client\Credentials\Container that includes the
You can start a call using an array as the structure:
Or you can create a
Nexmo\Call\Call object, and use that:
Fetching a Call
You can fetch a call using a
Nexmo\Call\Call object, or the call's UUID as a string:
The call collection can also be treated as an array:
And iterated over:
With an optional filter:
Creating an Application
Application are configuration containers. You can create one using a simple array structure:
You can also pass the client an application object:
You can iterate over all your applications:
Or you can fetch an application using a string UUID, or an application object.
Updating an Application
Once you have an application object, you can modify and save it.
You can also pass an array and the application UUID to the client:
Search Available Numbers
You can search for numbers available to purchase in a specific country:
Purchase a Number
To purchase a number, you can pass in a value returned from number search:
Or you can specify the number and country manually:
An API is provided to allow you to rotate your API secrets. You can create a new secret (up to a maximum of two secrets) and delete the existing one once all applications have been updated.
To get a list of the secrets:
You can create a new secret (the created dates will help you know which is which):
And delete the old secret (any application still using these credentials will stop working):
Some users have issues making requests due to the following error:
This is due to some PHP installations not shipping with a list of trusted CA certificates. This is a system configuration problem, and not specific to either cURL or Nexmo.
IMPORTANT: In the next paragraph we provide a link to a CA certificate bundle. Nexmo do not guarantee the safety of this bundle, and you should review it yourself before installing any CA bundle on your machine.
To resolve this issue, download a list of trusted CA certificates (e.g. the curl bundle) and copy it on to your machine. Once this is done, edit
php.ini and set the
- [X] Balance
- [X] Pricing
- [ ] Settings
- [ ] Top Up
- [X] Secret Management
- [X] Numbers
- [X] Search
- [X] Buy
- [X] Cancel
- [X] Update
- Number Insight
- [X] Basic
- [X] Standard
- [X] Advanced
- [X] Webhook Notification
- [X] Verify
- [X] Check
- [X] Search
- [X] Control
- [X] Send
- [X] Delivery Receipt
- [X] Inbound Messages
- [X] Search
- [X] Message
- [X] Messages
- [X] Rejections
- [ ] US Short Codes
- [ ] Two-Factor Authentication
- [ ] Event Based Alerts
- [ ] Sending Alerts
- [ ] Campaign Subscription Management
- [X] Outbound Call
- [ ] Inbound Call
- [ ] Text-To-Speech Call
- [ ] Text-To-Speech Prompt
This library is currently being refactored from an earlier prototype to match the current client library spec.
legacy branch can be used to require that earlier version. During the transition the
branches will have both new and legacy code. The API coverage section identifies what features are
currently implemented and up to date.
To contribute to the library, docs, or examples, create an issue or a pull request. Please only raise issues about features marked as working in the API coverage as the rest of the code is being updated.
This library is released under the MIT License