pakbull6772540
Posts: 0
Joined: Sun Mar 30, 2014 4:08 pm

Twilio plugin gives a 401 error message when tested in app or chrome but works within REST API

After configuring the Twilio plugin, it works as expected in the REST API builder / tester. However, whether testing the app using Chrome or compiled app, getting the
error:

POST https://api.appery.io/rest/1/proxy/tu... 401 (Unauthorized)

The header looks fine in debugger, has the From, To, Body. The proxy for Apperyio is also turned on. The message using the Appery REST API Tester goes out within a second.

I read on one of the documentations about secure proxy:
link: http://devcenter.appery.io/documentat...

"Some REST API services use HTTP basic authentication to authenticate users. One such service is the Twilio API. You would provide the username and password in the URL. For example:
http://username:password@host.com/
This approach is being phased out by most modern browsers"

Do I need to add the steps for Basic authentication? or there is something else that needs to be turned on at Twilio. The Twilio SMS service on their website also works just fine during testing.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Twilio plugin gives a 401 error message when tested in app or chrome but works within REST API

Hello Pakbull,

1) You can use server code to send your messages
2) You should turn proxy off and try to use your service on the device. In tester you would probably see CORS, but it should work on device

pakbull6772540
Posts: 0
Joined: Sun Mar 30, 2014 4:08 pm

Twilio plugin gives a 401 error message when tested in app or chrome but works within REST API

Twilio requires a header item: Authorization
added to the Twilio_sendMessage REST service. Go to headers and add this.

The value of this header is explained here: (PS: the user id and password here refers to the Twilio settings of accountSid and password is the Twilio authToken.

See these two docs for more reference:
https://getsatisfaction.com/apperyio/...
http://devcenter.appery.io/documentat...

Basic header-based authentication

Switching to Basic header-based authentication is very simple. You need to complete the following steps (from MDN):

Username and password are combined into a string “username:password”
The resulting string literal is then encoded using Base64
The authorization method and a space, i.e. “Basic ” is then put before the encoded string
A header is added to a service in the following form: Authorization Basic
For example, if the username is: my_user and the password is: my big secret, then the header and the encoded string would look like this:

Authorization: Basic bXlfdXNlcjpteSBiaWcgc2VjcmV0

To encode a string into Base64 string can be easily done with the browser’s built-in function window.btoa(string). For example, you can run this from browser’s console:

return "Basic " + window.btoa(username+":"+password);
This approach will allow you to use the new proxy (or the old proxy).

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Twilio plugin gives a 401 error message when tested in app or chrome but works within REST API

Hello Pakbull,

Thanks, we are aware of that, all questions with Twilio service was closed, the main problem in your parameters, not in the Appery.io.

xueyun77
Posts: 0
Joined: Mon Sep 28, 2015 10:05 am

Twilio plugin gives a 401 error message when tested in app or chrome but works within REST API

Hi,

When I tested SMS in Twilio Service, it works.

However, when I run the test in Chrome, there is an error (I coded the JS).

By the way, I'm Singapore user for appery.io.

Is there any dummy number or any format that I can use for SMS in appery.io?

thank you

Return to “Issues”