Setting up Twilio CallBack - callback

To fellow Twilio users,
we have set up a Twilio trial account.
Our question is can we define/set up a CALLBACK URL in Twilio App Dashboard ( or any other settings panel) to satisfy the following use case:
1. From browser/apps / mobile device
, user dials 310-333-1234 6789 (Twilio phone # / accesscode)
2. Twilio receives this call
3. Twilio captures accesscode (6789) trailing the phone number
and passes to CALLBACK URL
I understand Twilio MakeCall API allows you to specify CallBackURL:
where parmeters :
sendDigits=6789
StatusCallBack=My_CallBack_URL
StatusCallBackMethod=Post
But what we want is to set up CALLBACK URL so physical incoming calls (not calls made with API) and their accesscode would always be passed to this CALLBACK URL.

I'm Megan from Twilio. Not sure what language you're working with and I typically write Python, but I'll share an example in PHP below.
It looks like what you're trying to do here involves the Twiml <Gather> verb, where in the following example you would set http://example.com/complex_gather.xml as the URL in your Voice Request URL configuration of your Twilio number per Carter's suggestion in the comments. The <action> verb then allows you to redirect the caller to your custom Voice Request URL after they input the access code.
<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/complex_gather.xml -->
<Response>
<Gather numDigits="4" action="/customVoiceUrl" method="GET">
<Say>
Please enter your access code.
</Say>
</Gather>
<Say>We didn't receive any input. Goodbye!</Say>
</Response>
And an example page for the customVoiceUrl:
<?php
// page located at http://example.com/customVoiceUrl
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<Response><Say>You entered " . $_REQUEST['Digits'] . "</Say></Response>";
?>

Same issue described above was happening to me. It was happening because the url contained a query parameter that had an apostraphe in the value
e.g. the url had an apostraphe that was encoded with %27
https://www.example.com?name=O%27Malley
The fix for me was to double encode the query parameters before sending the request to twilio.
e.g. https://www.example.com?name=O%2527Malley
And then make sure to do an extra decoding on the callback query params on my backend
If the signature generated by Twilio decodes special charecters including those in the url as query parameter values, the library should do decoding along with parsing on validate
https://github.com/twilio/twilio-ruby/blob/main/lib/twilio-ruby/security/request_validator.rb#L27

Related

How Do I Authenticate an API Request Using a Token With Postman

I am trying to test a Web API using Postman on a project which I have inherited from previous developers. All I know so far is that Authentication has been configured using ASP.Net Identity and Identity Server 4.0 which implements OAuth and issues short lived JSON Web Tokens (JWT) and Refresh Tokens.
If I navigate to the development website, log in (successfully), and use Chrome Developer Tools to inspect the initial log in request I can see that the body of the request contains a Form with 3 fields; userName, password and returnUrl. If I right-click on the request I can copy the request as cURL (bash) and in Postman I can import the data to create a new request. If I send the request I get a status 200 OK back and the response includes 6 cookies. However the body of the response contains an htlm page which Postman can't render and a message You need to enable JavaScript to run this app.
I'm lost now as to how I can use the response to authenticate a request for some data. Is the Token I need contained within one of the cookies? How do I extract the Token and use it within a request for some data? Any advice or suggestions would be very welcome.
Normally, with JavaScript enabled in the browser, <form> would be automatically posted to its' destination defined in action, using method. JavaScript would do somethign like the following:
window.addEventListener('load', function(){document.forms[0].submit();});
So without JavaScript, you would need to somehow parse the form that you received and recreate equivalent request.
The form, received upon successful login, contains data that should be sent back to your origin website, to authenticate the end-user.
For example, form's body contains hidden input fields, defined by OpenID protocol:
...
<input type='hidden' name='token_type' value='Bearer' />
<input type='hidden' name='expires_in' value='600' />
...
Form action attribute points back to sign-in endpoint on your website. For example:
<form method='post' action='https://{hostname:post}/signin-oidc'>

POST request to url that has query string parameters

System I have to update has http-handlers that are accessible via address like
http://<server>/handlers?name=some-handler-name
I added http form with action tag that directs to one of this handlers like this:
<form ... action="/handlers?name=some-handler-name" >
My form is a part of a system and located right on the same server. Basically its accessible via adress like
http://<server>/handlers?name=my-handler-with-form
But when I submit my form - nothing is posted to some-handler-name handler because my http-request receives code 302 (redirect).
Do I use correct address in action method (what I want is my form data to be posted to address like http://server/handlers?name=some-handler-name)?
Is it possible to post data to url that has query string parameters?
I guess that system intercept my postback and for some reason redirects it
Correct address is important
Yes, it is possible to post data with query params
There would be some redirect rule set at the server side. You would need to work with server side dev or read server side deployment/code documentation.

How to code the Web Api Route, Controller for texting

I need to create a REST API Web Service using MVC4 Web Api that will be consumed by Twilio. I need to be able to accept Twilio's HTTP POST for receiving SMS from the user and for responding. So if the user texts a word "Join" or "My Order" then they would call my API using the URL that I have given and I should be sending the Welcome Message for join and the Order List for the text "My Order" and so on. How the heck do I do that? Do I need a single controller or multiple? How would I route this? Please help. Totally lost :-(
Twilio evangelist here.
Twilios HTTP requests are no different than any other HTTP client. So if you want to use Web API as your Twilio SMS URL, then you would just create a Post method and in the method definition, specify the parameters you want to capture from the request.
Twilio sends along a bunch if info with each request, like the to & from phone numbers and the body of the message. You can use model binding to grab this:
public HttpResponseMessage Post(string Body) {
//your code here
// if you want to return TwiML commands, use
// us the TwilioResponse object
return Request.CreateResponse(HttpStatusCode.OK, [your twiml]);
}
Twilio will made its request with an Accept header of text/xml, so WEb API should automatically try to return your TwiML commands as XML.
This blog post has more details on using Web API with Twilio:
http://www.twilio.com/blog/2012/11/building-twilio-apps-using-asp-net-mvc-4-web-api.html
Hope that helps.

Unable to create(POST) objects (Account, customer...) on QB Windows using IDS and Sync Manager

Here I am provideing you the complete scenario where I am getting the error while posting request for creating a new account.
I am using Intuit OAuth Access and OAuth API console for testing (Using all security tokens).(https://appcenter.intuit.com/Playground/OAuth)
And the URL and request:
URL: https://services.intuit.com/sb/account/v2/570357960
Method : Post
Format: XML/JSON
Request:
<?xml version="1.0" encoding="UTF-16"?><Add xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" RequestId="4df87bw2-916a-
4r95-h5d6-06dce3667562"
xmlns="http://www.intuit.com/sb/cdm/v2"><ExternalRealmId>570357960</ExternalRealmId><Objectxsi:type="Account"><Name>CurrentAccount</Name><Active>true</Active><Type>Expense<
/Type><Subtype>Expense</Subtype><AcctNum>1111</AcctNum></Object></Add>
And getting the response (error in html):
<div class="content-container"><fieldset>
<h2>500 - Internal server error.</h2>
<h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3>
and I have also checked with RESTClient utility, but getting the same above error.
Please note that the same url
(https://services.intuit.com/sb/account/v2/570357960) with same
security tokens is working fine for GET data , I am getting data from
QB desktop into my online Application.
As Keith said, check the Content-Type. You will also need to use a RestClient for testing. The playground will not work for testing API calls. It only works for platform calls.
If I had to guess... I'd guess you're sending the wrong Content-Type header... but it's impossible to tell for sure until you post more code/the rest of your HTTP request.
A few things to try. Be sure the XML is in the same order as this sample and try it.
the other is a common mistake when you use Oauth in a GET you are including just the url in the signature, but in a POST you need to include the Body in the signature too or it will not pass Oauth validation.
Lastly, as Keith mentioned to check the content type. Although you would generally get a content type error.
156234822
CurrentAccount
true
Expense
Expense
1111

GWT Async to URL

I'm using GWT to develop a web app. I'm currently using AJAX calls to retrieve values from the server. I have following queries regarding to AJAX calls:
Assume: I have an app, name of which is: "Application" and the entry point class is: "entry.java"
I know: the application could be invoked as: http://localhost:8080/Application/entry.html
1. I would like to know what what is the output URL given by gwt.getmodulebaseURL()?
Assume: In the same application I have a service called "ServerValuesService" and its corresponding Async. I have corresponding serviceImpl, which has a method called List < String >search(String) at the server side.
I could retrieve the values from the server as well. However,
2. I would like to know what would be the direct URL to access this service? For Instance, I need to obtain the list of values, by just giving a URL (passing value for the String). i.e. I need to access the method search(String) and retrieve the list just by typing a url such as:
http://localhost:8080/Application/entry/serverValuesService?string="hello"
I'm sure the above URL is wrong. I need to know exact conversion between URL and the corresponding service. Is this possible at all?
Thanks in advance!
1) In your case it will give you http://localhost:8080/Application . Application is your modulename.
2) These services are actually HttpServlets and their URL's are defined in the web.xml file. But Google uses POST method to send your variables and takes care of serialization for you, what you are trying to do is send it via GET method which is as far as I know not implemented by Google RemoteServiceServlet.So I would say no its not possible unless you extend these services to work with GET methods yourself but I don't know if that is possible.
Assume: I have an app, name of which is: "Application" and the entry point class is: "entry.java"
I know: the application could be invoked as: http://localhost:8080/Application/entry.html
The url http://localhost:8080/Application/entry.html is called host page url. In this html page you load your GWT module using a script tag:
<!-- This script tag is what actually loads the GWT module. The -->
<!-- 'nocache.js' file (also called a "selection script") is -->
<!-- produced by the GWT compiler in the module output directory -->
<!-- or generated automatically in hosted mode. -->
<script language="javascript" src="calendar/calendar.nocache.js"></script>
So if you put above example in your entry.html, the module will be loaded from http://localhost:8080/Application/calendar/calendar.nocache.js making http://localhost:8080/Application/calendar/ your module base url.
I would like to know what would be the direct URL to access this
service? For Instance, I need to obtain the list of values, by just
giving a URL (passing value for the String). i.e. I need to access the
method search(String) and retrieve the list just by typing a url
GWT RPC use a custom serialization format to encode requests to the RPC Service on server. The RPC service is implemented as a subclass of RemoteServiceServlet on the server. The RemoteServiceServlet handles the http POST requests, de-serializing the request from client and invvoking appropriate service method of sub-class.
So for directly accessing the service you'll need:
1. The service URL
2. Request payload encoded in GWT's custom serialization format
3. Ability to HTTP POST the payload to the Service URL
1 and 3 are easy to acquire. You already know the URL at which your service is mapped in web.xml. And you can do post from any http client or browser plugins like this. The hard-part would be to generate request payload in GWT's custom serialization format. For simple cases, you can generate a request from your application and capture the raw payload from Firebug, Fiddler or similar tool and simply replay it using your http client.