Skip to content

Quickstart tutorial

This tutorial will guide you through the basic process of how VerifyAPI works, and how to implement a two-factor authentication process for your web site or app.

A detailed reference of the API endpoints and their parameters can be found in the API Reference.

Step 1 - Request destination number

If the user you are trying to verify is not yet known to you (as an existing user), you will need to request a telephone number from them. This number needs to be in the E.164 format, and is used for further verification with VerifyAPI.

Step 2 - Send verification code

An API call to the VerifyAPI /verify endpoint is made, supplying the destination number obtained in step 1, along with the desired channel for sending the verification code. The channel can be either sms or voice.

bash
curl --request POST \
  --url https://api.verifyapi.dev/verify \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{ 
    "destination": "+12123464738", 
    "channel": "sms" 
}'
csharp
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Post,
    RequestUri = new Uri("https://api.verifyapi.dev/verify"),
    Headers =
    {
        { "Authorization", "Bearer YOUR_API_KEY" },
    },
    Content = new StringContent("{ \"destination\":\"+12123464738\", \"channel\":\"sms\" }")
    {
        Headers =
        {
            ContentType = new MediaTypeHeaderValue("application/json")
        }
    }
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://api.verifyapi.dev/verify"

	payload := strings.NewReader("{ \"destination\":\"+12123464738\", \"channel\":\"sms\" }")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Authorization", "Bearer YOUR_API_KEY")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
java
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.verifyapi.dev/verify"))
    .header("Content-Type", "application/json")
    .header("Authorization", "Bearer YOUR_API_KEY")
    .method("POST", HttpRequest.BodyPublishers.ofString("{ \"destination\":\"+12123464738\", \"channel\":\"sms\" }"))
    .build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
javascript
fetch('https://api.verifyapi.dev/verify', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer YOUR_API_KEY'
  },
  body: JSON.stringify({
    destination: '+12123464738',
    channel: 'sms'
  })
})
javascript
const axios = require('axios').default;
const options = {
  method: 'POST',
  url: 'https://api.verifyapi.dev/verify',
  headers: {
    'Content-Type': 'application/json', 
    Authorization: 'Bearer YOUR_API_KEY' 
  },
  data: {
    destination: '+12123464738',
    channel: 'sms'
  }
};

try {
  const { data } = await axios.request(options);
  console.log(data);
} catch (error) {
  console.error(error);
}
php
$request = new HttpRequest();
$request->setUrl('https://api.verifyapi.dev/verify');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders([
  'Content-Type' => 'application/json',
  'Authorization' => 'Bearer YOUR_API_KEY'
]);

$request->setContentType('application/json');
$request->setBody(json_encode([
  'destination' => '+12123464738',
  'channel' => 'sms'
]));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
python
import http.client

conn = http.client.HTTPSConnection("api.verifyapi.dev")

payload = "{ \"destination\":\"+12123464738\", \"channel\":\"sms\" }"

headers = {
    'Content-Type': "application/json",
    'Authorization': "Bearer YOUR_API_KEY"
}

conn.request("POST", "/verify", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
ruby
require 'uri'
require 'net/http'

url = URI("https://api.verifyapi.dev/verify")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request["Authorization"] = 'Bearer YOUR_API_KEY'
request.body = "{ \"destination\":\"+12123464738\", \"channel\":\"sms\" }"


response = http.request(request)
puts response.read_body

A succesful response will contain a JSON object with an id field, which is used in step 3, this should be stored on your website or app temporarily.

json
{
  "id":"6603443f241aa2b2299003b6",
  "destination":"+12123464738",
  "channel":"sms",
}

Step 3 - Confirm verification code

The user will receive a verification code via the chosen channel. This code will then be supplied to your website or app, whicn in turn will call the /verify endpoint to confirm the code is valid. The id obtained in step 2 will also need to be included in the request.

bash
curl --request POST \
  --url https://api.verifyapi.dev/confirm \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{ 
    "id": "6603443f241aa2b2299003b6", 
    "code": "123456" 
}'
csharp
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Post,
    RequestUri = new Uri("https://api.verifyapi.dev/confirm"),
    Headers =
    {
        { "Authorization", "Bearer YOUR_API_KEY" },
    },
    Content = new StringContent("{ \"id\":\"6603443f241aa2b2299003b6\", \"code\":\"123456\" }")
    {
        Headers =
        {
            ContentType = new MediaTypeHeaderValue("application/json")
        }
    }
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.verifyapi.dev/confirm"

	payload := strings.NewReader("{ \"id\":\"6603443f241aa2b2299003b6\", \"code\":\"123456\" }")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Authorization", "Bearer YOUR_API_KEY")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
java
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.verifyapi.dev/confirm"))
    .header("Content-Type", "application/json")
    .header("Authorization", "Bearer YOUR_API_KEY")
    .method("POST", HttpRequest.BodyPublishers.ofString("{ \"id\":\"6603443f241aa2b2299003b6\", \"code\":\"123456\" }"))
    .build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
javascript
fetch('https://api.verifyapi.dev/confirm', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer YOUR_API_KEY'
  },
  body: JSON.stringify({
    id: '6603443f241aa2b2299003b6',
    code: '123456'
  })
})
javascript
const axios = require('axios').default;
const options = {
  method: 'POST',
  url: 'https://api.verifyapi.dev/confirm',
  headers: {
    'Content-Type': 'application/json', 
    Authorization: 'Bearer YOUR_API_KEY' 
  },
  data: {
    id: '6603443f241aa2b2299003b6',
    code: '123456'
  }
};

try {
  const { data } = await axios.request(options);
  console.log(data);
} catch (error) {
  console.error(error);
}
php
$request = new HttpRequest();
$request->setUrl('https://api.verifyapi.dev/confirm');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders([
  'Content-Type' => 'application/json',
  'Authorization' => 'Bearer YOUR_API_KEY'
]);

$request->setContentType('application/json');
$request->setBody(json_encode([
  'id' => '6603443f241aa2b2299003b6',
  'code' => '123456'
]));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
python
import http.client

conn = http.client.HTTPSConnection("api.verifyapi.dev")

payload = "{ \"id\":\"6603443f241aa2b2299003b6\", \"code\":\"123456\" }"

headers = {
    'Content-Type': "application/json",
    'Authorization': "Bearer YOUR_API_KEY"
}

conn.request("POST", "/confirm", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
ruby
require 'uri'
require 'net/http'

url = URI("https://api.verifyapi.dev/confirm")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request["Authorization"] = 'Bearer YOUR_API_KEY'
request.body = "{ \"id\":\"6603443f241aa2b2299003b6\", \"code\":\"123456\" }"


response = http.request(request)
puts response.read_body

Upon a successful verification, the /verify endpoint will return a HTTP 200 OK status code.

This confirms the process has completed successfully, and you can let the user proceed with the necessary action or location on your website or app.