REST Endpoint
Check and format one phone number over the WordPress REST API, from your own JavaScript or from another app.
GET /wp-json/smart-phone-field/v1/check?phone=07400123456&country=gb
POST /wp-json/smart-phone-field/v1/check
Parameters#
| Parameter | Required | Notes |
|---|---|---|
phone | Yes | The number to check. Up to 40 characters. |
country | No | Two-letter country code, for numbers typed without a country code. |
Response#
{
"phone": "07400123456",
"country": "gb",
"valid": true,
"international": "+447400123456",
"readable": "+44 7400 123456",
"message": ""
}
When the number isn’t valid, valid is false and message explains why, in the site’s language. An empty phone returns a 400 error.
Privacy and access#
The endpoint only checks the number it’s given and stores nothing. It’s public by default.
// Turn it off.
add_filter( 'nahnu_spf_rest_enabled', '__return_false' );
// Only logged-in users.
add_filter( 'nahnu_spf_rest_permission', 'is_user_logged_in' );