Movatterモバイル変換


[0]ホーム

URL:


Skip to contentSkip to navigationSkip to topbar
Go to the Twilio Docs home page
Twilio Docs

Verify API


As part of Twilio's account security offerings, the Twilio Verify API makes it simple to add user verification to your web application. The API supports the following channels:

For more information on Verify, see ourproduct page(link takes you to an external page).


All URLs referenced in the documentation have the following base:

https://verify.twilio.com/v2/

The Twilio REST API is served over HTTPS. To ensure data privacy, unencrypted HTTP is not supported.


To authenticate requests to the Twilio APIs, Twilio supportsHTTP Basic authentication(link takes you to an external page). Use yourAPI key as the username and yourAPI key secret as the password. You can create an API key eitherin the Twilio Console orusing the API.

Note: Twilio recommends using API keys for authentication in production apps. For local testing, you can use your Account SID as the username and your Auth token as the password. You can find your Account SID and Auth Token in theTwilio Console(link takes you to an external page).

Learn more aboutTwilio API authentication.

1
curl-XPOST https://verify.twilio.com/v2/Services\
2
-dFriendlyName=MyServiceName\
3
-u$TWILIO_API_KEY:$TWILIO_API_KEY_SECRET

User Verification Workflow

user-verification-workflow page anchor

This guide shows the 3 steps to completing a basic one-time passcode (OTP) verification. Follow the links for more documentation on advanced features such asservice configuration,custom codes,rate limiting,PSD2 compliance, and more.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
consttwilio=require("twilio");// Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
constaccountSid=process.env.TWILIO_ACCOUNT_SID;
7
constauthToken=process.env.TWILIO_AUTH_TOKEN;
8
constclient=twilio(accountSid, authToken);
9
10
async functioncreateService() {
11
constservice= awaitclient.verify.v2.services.create({
12
friendlyName:"My First Verify Service",
13
});
14
15
console.log(service.sid);
16
}
17
18
createService();

Response

Note about this response
1
{
2
"sid":"VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid":"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"friendly_name":"My First Verify Service",
5
"code_length":4,
6
"lookup_enabled":false,
7
"psd2_enabled":false,
8
"skip_sms_to_landlines":false,
9
"dtmf_input_required":false,
10
"tts_name":"name",
11
"mailer_sid":"MDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
12
"do_not_share_warning_enabled":false,
13
"custom_code_enabled":true,
14
"push": {
15
"include_date":false,
16
"apn_credential_sid":"CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
17
"fcm_credential_sid":null
18
},
19
"totp": {
20
"issuer":"test-issuer",
21
"time_step":30,
22
"code_length":3,
23
"skew":2
24
},
25
"whatsapp": {
26
"msg_service_sid":"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
27
"from":"whatsapp:+1234567890"
28
},
29
"default_template_sid":"HJaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
30
"verify_event_subscription_enabled":false,
31
"date_created":"2015-07-30T20:00:00Z",
32
"date_updated":"2015-07-30T20:00:00Z",
33
"url":"https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
34
"links": {
35
"verification_checks":"https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/VerificationCheck",
36
"verifications":"https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Verifications",
37
"rate_limits":"https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/RateLimits",
38
"messaging_configurations":"https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/MessagingConfigurations",
39
"entities":"https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities",
40
"webhooks":"https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks",
41
"access_tokens":"https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AccessTokens"
42
}
43
}

Create a Service in one of two ways:

  1. In the Twilio Verify Console(link takes you to an external page)
  2. Using the API (code sample on this page)

A Verification Service is the set of common configurations used to create and check verifications. This includes features like:

One verification service can be used to send multiple verification tokens, it is not necessary to create a new service each time.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
consttwilio=require("twilio");// Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
constaccountSid=process.env.TWILIO_ACCOUNT_SID;
7
constauthToken=process.env.TWILIO_AUTH_TOKEN;
8
constclient=twilio(accountSid, authToken);
9
10
async functioncreateVerification() {
11
constverification= awaitclient.verify.v2
12
.services("VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.verifications.create({
14
channel:"sms",
15
to:"+15017122661",
16
});
17
18
console.log(verification.status);
19
}
20
21
createVerification();

Response

Note about this response
1
{
2
"sid":"VEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"service_sid":"VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"account_sid":"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"to":"+15017122661",
6
"channel":"sms",
7
"status":"pending",
8
"valid":false,
9
"date_created":"2015-07-30T20:00:00Z",
10
"date_updated":"2015-07-30T20:00:00Z",
11
"lookup": {},
12
"amount":null,
13
"payee":null,
14
"send_code_attempts": [
15
{
16
"time":"2015-07-30T20:00:00Z",
17
"channel":"SMS",
18
"attempt_sid":"VLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
19
}
20
],
21
"sna":null,
22
"url":"https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Verifications/VEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
23
}

This will send a token to the end user through the specified channel. Newly created verifications will show a status ofpending. Supported channels are:

Learn more about how to turnphone number input into E.164 format(link takes you to an external page) or how tocustomize the verification message.

Verification documentation.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
consttwilio=require("twilio");// Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
constaccountSid=process.env.TWILIO_ACCOUNT_SID;
7
constauthToken=process.env.TWILIO_AUTH_TOKEN;
8
constclient=twilio(accountSid, authToken);
9
10
async functioncreateVerificationCheck() {
11
constverificationCheck= awaitclient.verify.v2
12
.services("VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.verificationChecks.create({
14
code:"123456",
15
to:"+15017122661",
16
});
17
18
console.log(verificationCheck.status);
19
}
20
21
createVerificationCheck();

Response

Note about this response
1
{
2
"sid":"VEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"service_sid":"VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"account_sid":"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"to":"+15017122661",
6
"channel":"sms",
7
"status":"approved",
8
"valid":true,
9
"amount":null,
10
"payee":null,
11
"sna_attempts_error_codes": [],
12
"date_created":"2015-07-30T20:00:00Z",
13
"date_updated":"2015-07-30T20:00:00Z"
14
}

This will check whether the user-provided token is correct.

TokenStatus in response
Correctapproved
Incorrectpending

VerificationCheck documentation.

(information)

Info

You made it through the Verify API Overview. To protect your service against fraud, view our guidance onPreventing Toll Fraud when using Verify.


[8]ページ先頭

©2009-2025 Movatter.jp