这份文档还在翻译中,预期年底前完成。欢迎您提供宝贵的意见及建议。

Send verification code with workflow

When you have collected a user's phone number, start the verification process by sending a verify request to the Verify API. This example includes use of a specific workflow for the request.

The Verify API returns a request_id. Use this to identify a specific verification request in subsequent calls to the API, such as when making a check request to see if the user provided the correct code.

Replace the following variables in the sample code with your own values:

Name Description
NEXMO_API_KEY Your Nexmo API key
NEXMO_API_SECRET Your Nexmo API secret
RECIPIENT_NUMBER The phone number to verify
BRAND_NAME Included in the message to explain who is confirming the phone number
WORKFLOW_ID Choose a workflow (number between 1 and 7), these are defined in the workflows guide

Write the code

Add the following to send-verification-code-with-workflow.sh:

Copy to Clipboard
curl -X GET "https://api.nexmo.com/verify/json?&api_key=$NEXMO_API_KEY&api_secret=$NEXMO_API_SECRET&number=$RECIPIENT_NUMBER&brand=AcmeInc&workflow_id=$WORKFLOW_ID"

View full source

Run your code

Save this file to your machine and run it:

sh send-verification-code-with-workflow.sh

Prerequisites

Install dependencies

npm install nexmo
Initialize your dependencies

Create a file named request-with-workflow.js and add the following code:

Copy to Clipboard
const Nexmo = require('nexmo');
const nexmo = new Nexmo({
  apiKey: NEXMO_API_KEY,
  apiSecret: NEXMO_API_SECRET
});

View full source

Write the code

Add the following to request-with-workflow.js:

Copy to Clipboard
nexmo.verify.request({
  number: RECIPIENT_NUMBER,
  brand: BRAND_NAME,
  workflow_id: WORKFLOW_ID
}, (err, result) => {
  if (err) {
    console.error(err);
  } else {
    const verifyRequestId = result.request_id;
    console.log('request_id', verifyRequestId);
  }
});

View full source

Run your code

Save this file to your machine and run it:

node request-with-workflow.js

Prerequisites

Install dependencies

Install-Package Nexmo.Csharp.Client
Import dependencies

Create a file named SendVerificationRequestWithWorkflow.cs and add the following code:

Copy to Clipboard
using Nexmo.Api;
using Nexmo.Api.Request;
using Nexmo.Api.Verify;

View full source

Initialize your dependencies

Add the following to SendVerificationRequestWithWorkflow.cs:

Copy to Clipboard
var credentials = Credentials.FromApiKeyAndSecret(NEXMO_API_KEY, NEXMO_API_SECRET);
var client = new NexmoClient(credentials);

View full source

Write the code

Add the following to SendVerificationRequestWithWorkflow.cs:

Copy to Clipboard
var request = new VerifyRequest() { Brand = BRAND_NAME, Number = RECIPIENT_NUMBER, WorkflowId = VerifyRequest.Workflow.TTS };
var response = client.VerifyClient.VerifyRequest(request);

View full source

Prerequisites

Install dependencies

composer require nexmo/client
Initialize your dependencies

Create a file named request_with_workflow.php and add the following code:

Copy to Clipboard
$basic  = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));

View full source

Write the code

Add the following to request_with_workflow.php:

Copy to Clipboard
$verification = new \Nexmo\Verify\Verification(NUMBER, BRAND_NAME, ['workflow_id' => WORKFLOW_ID]);
$client->verify()->start($verification);

View full source

Run your code

Save this file to your machine and run it:

php request_with_workflow.php

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

Create a file named request_with_workflow.rb and add the following code:

Copy to Clipboard
client = Nexmo::Client.new(
  api_key: NEXMO_API_KEY,
  api_secret: NEXMO_API_SECRET
)

View full source

Write the code

Add the following to request_with_workflow.rb:

Copy to Clipboard
response = client.verify.request(
  number: TO_NUMBER,
  brand: 'AcmeInc',
  workflow_id: WORKFLOW_ID
)

if response
  # display the Verify `request_id`
  puts response.request_id
end

View full source

Run your code

Save this file to your machine and run it:

ruby request_with_workflow.rb

Note: If you receive the error code 15: The destination number is not in a supported network, the target network might have been blocked by the platform's anti-fraud system. See Velocity Rules.