I’ve tried everything (spent 5 hours trying different things) and I keep getting the below as a response.
{code: 20003, detail: "Your AccountSid or AuthToken was incorrect.", message: "Authentication Error - No credentials provided", more_info: "https://www.twilio.com/docs/errors/20003", status: 401}
Here’s the code I have to done so far:
import {fetch} from 'wix-fetch';
//this is on the backend...
export async function a007_phoneNumberVerification(phone_number) {
let data = ""
let url = 'https://lookups.twilio.com/v1/PhoneNumbers/'+phone_number+'?CountryCode=US';
let username = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
let password = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
let headers = {
'Authorization': username + ":" + password,
};
let options = {
method:'get',
headers: headers
}
await fetch(url, options)
.then(response => response.json())
.then(json => data = json);
return data
}
//this is on the frontend
let value = await a007_phoneNumberVerification(phone_number);
console.log(value)
I have no idea how to get the username and password to push through, but I’m successfully getting a response back from the API with the error message.
Thanks Ido, but that isn’t the issue. I’m actually able to successfully use the API using Postman, so I know the API key / Auth is correct. It something with my code. Here’s a new version that is still having issues. Any suggestions? Thanks so much!
export async function phoneNumberVerification(phone_number) {
let data = ""
let url = 'https://lookups.twilio.com/v1/PhoneNumbers/'+phone_number+'?CountryCode=US';
let account_sid = "xxxxxx";
let auth_token = "xxxxxxx";
let headers = {
'Authorization': account_sid + ":" + auth_token,
};
let options = {
method:'get',
headers: headers
}
await fetch(url, options)
.then(response => response.json())
.then(json => data = json);
return data
}
I’m also trying the Node.JS way, but I’m pulling up an undefined result. See below.
Backend code:
// Filename: backend/twillio.jsw (web modules need to have a .jsw extension)
import Twillo from 'twilio';
const accountSid = 'xxxxxx'; //your accountSid
const authToken = 'xxxxxxxxx'; // your authToken
const client = require('twilio')(accountSid, authToken);
export async function verifyPhone(phone_number_to_verify) {
client.lookups.phoneNumbers('(510)867-5310')
.fetch({countryCode: 'US', type: ['carrier']})
.then(phone_number => console.log(phone_number.carrier));
}
Frontend code:
import {verifyPhone} from 'backend/twillio.jsw';
export async function button76_click(event) {
let phone_number_to_verify = "'(510)867-5310;
let value = await verifyPhone(phone_number_to_verify)
console.log(value)
}