How do I send a text message with twilio in react native?
I have not found anything related to react native in the documentation.
The code below is not working to send a text message.
fetch('https://api.twilio.com/2019-01-01/Accounts/ACxxxxxxxxxxx/Messages',
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
user:'ACxxxxxxxxxxxxxxxxxxxxxxx',
password:'xxxxxxxxxxxxxxxxxxxxxxxxx',
to: '+xxxxxxxxxx',
body: 'test',
from: '+xxxxxxxxxxx',
}),
}) .then((response) => {
console.log(JSON.stringify(response))
alert(JSON.stringify(response))
})
.catch((error) => {
alert('error' + error);
});
ERROR:
I/ReactNativeJS: {"type":"default","status":401,"ok":false,"headers":{"map":{"connection":"keep-alive","content-length":"327","x-powered-by":"AT-5000","x-shenanigans":"none","www-authenticate":"Basic realm=\"Twilio API\"","access-control-allow-headers":"Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since","date":"Tue, 08 Jan 2019 09:22:05 GMT","access-control-allow-methods":"GET, POST, DELETE, OPTIONS","twilio-request-id":"RQ4e86455b1a2446afb35feab5ea5f0789","access-control-allow-credentials":"true","access-control-allow-origin":"*","access-control-expose-headers":"ETag","content-type":"application/xml","twilio-request-duration":"0.003","strict-transport-security":"max-age=31536000"}},"url":"https://api.twilio.com/2010-04-01/Accounts/AC8xxxxxxxxxxxxxxxxX/Messages","_bodyInit":"\n20003
Your AccountSid or AuthToken was incorrect.Authentication Error - No credentials providedhttps://www.twilio.com/docs/errors/20003401","_bodyText":"\n20003
Your AccountSid or AuthToken was incorrect.Authentication Error - No credentials providedhttps://www.twilio.com/docs/errors/20003401"}
HTTP Basic Authentication
or you have togenerate a revocable API Keys to authenticate
which again has to be sent as a header, not as a body value. Please check the documentation for the error message as it clearly states what's wrong/missing. – cramopy