How to code the Web Api Route, Controller for texting - rest

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.

Related

How to send user input from TextField to GET method API without body? - Dart

I have a feedback form like this
the API for it using a GET method without body. I have to send user input from the 3 TextField (Nama, Email, Pesan Anda) to GET method API.
I'm clueless, my senior said that I have to use url parameters so I can still send data to API without a body.
How can I do that?
HTTP GET method has no body on it's requisitions, so yes, the only way to send params is in the url, where you can send like this:
http://{URL}/?nama=Nama&email=Email&pesanAnda=PesanAnda
then you API will have access to these params.

How do i handle url callbacks on my serverless flutter app?

I am testing a crypto payment system on my flutter app, and after generating a random address for payment, the api is supposed to notify me when the transaction has been confirmed using a callback url. I use firestore for my backend, how do i handle this callback url. I will post a copy of the documentation below.
"Insert your URL address where you want to get callbacks in create_payment request. The parameter name is ipn_callback_url. You will receive payment updates (statuses) to this URL address."
for anyone having a similar challenge, i actually solved this problem by writing a http cloud function to help me handle this, then supplied the url to the function as the callback url to the api. SO yes.... http cloud functions was a solution to this problem
Here's a very simple function that can be used:
exports.paymentConfirmation = functions.https.onRequest(async(req, res)=>{
const requestBody = req.body;
const paymentStatus = requestBody.payment_status;
console.log('this is the payment status: ' + paymentStatus);
Promise.resolve();
}
res.send(null);
})
basically you can do anything you want with the request body you get back. In this case i just logged one of the parameters. After deploying this function to firebase, you have access to its url. Problem solved. So when there's an update from the api u subscribed to, it can send a POST request to that url and that triggers whatever code you've written in the function.

How to generate/retrieve token from Cybersource Secure Acceptance API?

I have attempted to use the provided test data from the Cybersource documentation to create a token for a test PAN. However, when attempting to do so (assuming it was a REST Api) it results in a "403 - Forbidden" error. The documentation is limited, as it doesn't give much information on the API other than the following:
(Test) Endpoint: https://testsecureacceptance.cybersource.com/silent/token/create
Request to create a standalone payment token:
reference_number=123456789
transaction_type=create_payment_token
currency=usd
amount=100.00
locale=en
access_key=e2b0c0d0e0f0g0h0i0j0k0l0m0n0o0p3
profile_id=0FFEAFFB-8171-4F34-A22D-1CD38A28A384
transaction_uuid=02815b4f08e56882751a043839b7b481
signed_date_time=2013-07-11T15:16:54Z
signed_field_names=comma separated list of signed fields
unsigned_field_names=comma separated list of unsigned fields
signature=WrXOhTzhBjYMZROwiCug2My3jiZHOqATimcz5EBA07M=
payment_method=card
card_type=001
card_number=4111111111111111
card_expiry_date=12-2022
card_cvn=005
bill_to_forename=Joe
bill_to_surname=Smith
bill_to_email=joesmith#example.com
bill_to_address_line1=1 My Apartment
bill_to_address_city=Mountain View
bill_to_address_postal_code=94043
bill_to_address_state=CA
bill_to_address_country=US
Is this a REST or SOAP API? How can this be tested in Postman? I tested to check if either works, and was unsuccessful. There is no information on what to include in the header either, so this is a bit puzzling.
Example POST test I am attempting:
POST https://testsecureacceptance.cybersource.com/silent/token/create
Content-Type:application/json
Accept:application/json
{
reference_number:123456789
transaction_type:create_payment_token
currency:usd
amount:100.00
locale:en
access_key:e2b0c0d0e0f0g0h0i0j0k0l0m0n0o0p3
profile_id:0FFEAFFB-8171-4F34-A22D-1CD38A28A384
transaction_uuid:02815b4f08e56882751a043839b7b481
signed_date_time:2019-03-07T06:16:54Z
signed_field_names:profile_id,access_key,transaction_uuid,signed_field_names,unsigned_field_names,signed_date_time,locale,transaction_type,reference_number,auth_trans_ref_no,amount,currency,card_type,card_number,card_expiry_date,card_cvn,payment_method,bill_to_forename,bill_to_surname,bill_to_email,bill_to_address_line1,bill_to_address_city,bill_to_address_postal_code,bill_to_address_state,bill_to_address_country
unsigned_field_names:
signature:WrXOhTzhBjYMZROwiCug2My3jiZHOqATimcz5EBA07M=
payment_method:card
card_type:001
card_number:4111111111111111
card_expiry_date:12-2022
card_cvn:005
bill_to_forename:Joe
bill_to_surname:Smith
bill_to_email:joesmith#example.com
bill_to_address_line1:1 My Apartment
bill_to_address_city:Mountain View
bill_to_address_postal_code:94043
bill_to_address_state:CA
bill_to_address_country:US
}
"Is this a REST or SOAP API?"
The URL, https://testsecureacceptance.cybersource.com/silent/token/create, is used for Secure Acceptance Checkout API. Secure Acceptance Checkout API is neither a SOAP API or a REST API. It is designed to be used as an HTML form POST from a customers browser.
If your goal is to use a REST API from the browser then you will want to use Secure Acceptance Flexible Token documented here.
If your goal is to use Secure Acceptance Checkout API the full documentation for that is here.
"How can this be tested in Postman?"
Since this is not meant to be a REST API call but an HTML form POST and HTML response you may have limited success with Postman. For example even if you get the request to work successfully the response will be an HTML document not JSON.
One problem I see is that you are using the example signature, and that will not work for you. Ensure that you follow the documentation on how to create your signature as well as set the signed and unsigned fields.
#J.J. - the error you encountered -- "This field is invalid or missing.Please contact Customer Support.: ots_profileid' ". Is telling you that you are missing (or have an invalid) profileID in your request payload. The system doesn't know what profile to use when processing this request.

How to call nested apis in Springboot

Assume we have an api - /student/getStudentDetails/{id} which returns a JSON response containing the succeeding internal rest api (/student/getAdvancedStudentDetails/{id}).
{
id:123,
name:Alex,
nextapi:/student/getAdvancedStudentDetails/123
}
Here when we get the response from first api - /student/getStudentDetails, we need to process the JSON response and take out the second api from the first api and call it.
Any suggestions?
Your first response for first api "GET student details" only returns high level details of student and one of field "nextapi" in response has URL to GET more details about student.
In Your first response "nextapi" is customer field defined by you and it only has
URL without host and port details of sever. So Consumer of api, will have to parse First response. Create full http url and call the next api to get further details of student. It will not happen automatically.
eg http://localhost:8080/student/getAdvancedStudentDetails/123
{
id:123,
name:Alex,
nextapi:/student/getAdvancedStudentDetails/123
}
Note :
If your response had full http url for get advance details of student and if api was not secure api. Then if you view first Json, it might give you link for next api, which you can click and see advance details. You can give it try.

Does Syncfusion Dashboard web data source support POST http methods?

Does Syncfusion Dashboard web data source support POST http methods?
If yes, so how set it up?
Thanks!
HTTP Post requests additional data from client to server in the message body, where message body will be like JSON, XML, TEXT etc. This may result in the creation of a new resource or the updates of existing resources or both. In contrast, HTTP Get requests include all required data in the URL. So we support HTTP Get method since POST method is not valid use case.
Regards,
Umapathy S.