SurveyMonkey - Create Webhook with AWS API Gateway as Subscription Url - amazon-web-services

I am trying to Integrate SurveyMonkey with my backend.
This is the flow:
(1) We create a webhook(https://developer.surveymonkey.com/api/v3/#webhooks) using POST method from PHP, with Subscription url as an AWS API Gateway.
(2) When user completes a survey, SurveyMonkey invokes the subscription Url (API Gateway), which in turn calls a Lambda function to update the database.
The problem is when i try to give a API Gateway url as the subscription Url, SurveyMonkey returns a Bad Request response. If i use a general .php page, the webhook is getting created successfully.
In the conversation with SurveyMonkey Support Team, they say, the API Gateway should return a 200 response for HEAD request. I am not sure how to set this up in AWS.
Can anyone who has implemented / integrated, API Gateway with SurveyMonkey please guide me on how to solve this issue?
Here is the conversation with SurveyMonkey Support Team:
Thanks for getting back in touch. I just spoke with my colleagues on
the development team and they noted that there shouldn't be an issue
in using a lamda function for your subscription_URL. As long as it
accepts HEAD and POST requests and returns a 200. I hope this helps
you out; of course, please let me know if I can assist further.
Thanks for getting back in touch. I wanted to confirm that the lambda
function needs to return a 200 to a HEAD request in order for us to
enable the webhook properly. This isn't done after the webhook is
cerated, but as the webhook is created. It still seems like the
lambda function isn't responding, or responding correctly, as it is
created, so it will continue to fail. I hope this helps clarify;
please let me know if I can assist further.

One way or another, you need to get the API Gateway to respond to HEAD requests. There are a lot of ways to do this. You could add a HEAD method to the resource of your URL. You can do that in the API Gateway console under the resource section when you're editing you api. You can send the HEAD requests to a lambda function and have that function return a 200 status code for appropriate HEAD requests. You can set up a mock return in the api integration request, but you'll need to set up the correct integration details. You can also just set ANY lambda proxy integration and deal with everything on the lambda side.
Once you have something setup you should be able to test with curl:
curl -I http://yourUrl.example.com

Related

Instagram API Webhook URL not receiving test updates

I have a Business App in dev mode and would like to test the handling of a test updates to my webhook for Instagam, but none of my test updates seem to go through.
I'm trying to use a Firebase HTTP Cloud Function to handle the verification and notification updates. Upon setting up the HTTP cloud function to respond appropriately if it's invoked with a GET or a POST request, I deployed my function to Firebase Cloud Functions.
I followed the steps in the getting started pages of using Webhooks, including configuring the Webhook Product, enabling page subscriptions, I have access to the Instagram Account and Facebook Page with admin access, but none of my test updates are going through to the webhook url, which I specified as a url to my Firebase Cloud Function.
My firebase cloud function url is
https://us-xxxx-xxxx-xxxxx.cloudfunctions.net/webhooks with the "xxxx" covering my project id details. When I first specify my url Webhook URL using "Instagram" and subscribing to "messages" I see that my function get's one GET request, but that's it. No test updates, or subscribing updates go through.
What the function currently does is respond with the hub.challenge if the request to the cloud function is a GET request, and if it's a POST request to the cloud function, I'll send 200 OK HTTPS. I have print messages along the way so I would know in my cloud function logs that something is being triggered. Any ideas?
Any suggestions on what to do to get the test webhooks to show up would be great. Thanks

Mapping request when Wrapping graphQL(appsync) with GET REST API using Amazon api gateway

I want to create a GET endpoint as a wrapper over an existing App Sync api for a specific query using AWS Service integration in API Gateway.
Eg. /employee/{id}/residenceCountry
In the mapping template I put the query as
{"query":"query MyQuery {getEmployeeDetails(id: \"$method.request.path.id\") {address {country}}}"}
However, I am getting a 500 Internal server error with no proper logs.
When I create a POST endpoint such that I pass the above body as request body to my rest api with passthrough, it works.
In the execution logs I see the exact same content for Endpoint request body after transformations:
In order to get the proper logs I tried getting $context.error.message and $context.integrationErrorMessage but I do not get any details.
Could someone please tell what I could be doing wrong or how to debug this better?
It turned out to be a very silly mistake of selecting App Sync as AWS Service in GET vs App Sync Data Plane in POST. It was only made apparent via another set of eyes. Thanks to my colleague Albert Hoxha.

AWS Lex and Facebook Messenger Integration Not Working

I'm banging my head against the wall trying to get an AWS Lex based chatbot integrated with Facebook.
As far as I can tell, everything is set up correctly.
When I send a message to my page in Facebook, I don't get a reply. However, the analytics in my app shows that the app is getting messages, so I know the message is making it from the page to the app.
When I try to hit the AWS Lex Webhook directly using POSTMAN, the webhook responds to literally everything I sent to it with a blank HTTP 200 OK response.
The lambda function that is tied to the AWS Lex chatbot is not getting invoked as a result of the messages from Facebook because no logs are getting generated and cloudwatch doesn't show an attempts to run the lambda function.
Does anyone have any ideas?
UPDATE : I ended up engineering around this by bypassing the Facebook channel capability inside AWS Lex and using Lambda instead. I deployed a passthrough API which calls a lambda function and then interacts with AWS Lex via Boto3/Python. In theory this is all supposed to be taken care of from inside AWS Lex with the Facebook channel integration, but I wasn't able to get it to work so I just built around it.
Verify Amazon lex is properly configured with facebook messenger .
Check : Page access token
Verification token
App ID
Check if your webhook is subscribed to page you are messaging on.
Check if your facebook user is added as tester/admin/developer
Check if your latest version of BOt is published on intended alias.
Also while configuring webhook tick necessary options : messages, messaging_postbacks, messaging_optins, message_deliveries, message_reads, messaging_payments
This should resolve your head ache. If not please reply

Handling "Missing Authentication Token" after setting up AWS Lambda with API Gateway

Here are the exact steps I just followed to setup a Lambda function behind and API Gateway.
1. Select blueprint
2. Add trigger
3. Configure
4. Create Role
5. Create Function
6. Congrats
7. Deploy API
However, when I visit the endpoint:
https://hq1hf4tmlf.execute-api.us-west-2.amazonaws.com/prod/myLambda
I get the following error:
{
"message": "Missing Authentication Token"
}
The error you are getting is because the API key isn't included when you invoke the API through the URL alone.
With the way you currently have it set up, you would need to use something like python's requests package to call the API and invoke the lambda:
import requests
CustomHeader = {'x-api-key': YOUR_API_KEY}
Response = requests.get(YOUR_API_URL, headers=CustomHeader)
Or, you could go back into your API's configuration (under Your API/Resources/API Call/Method Request) and disable use of your API key for that call, but is a very insecure option.
You may want to check if you have a web security service or web filtering proxy installed on your device that might be stripping off JWT/auth tokens from requests going out of your work/home network. I had the same problem where I was getting “Missing Authentication token” error while trying to create a lambda function on my work laptop. After struggling for few hours, I switched on to my personal laptop and was able to create the lambda function successfully in the first attempt. I then tried again on my work laptop with fiddler turned on and noticed that even though the auth credentials were setup properly in my outbound request, I was still getting “x-amzn-ErrorType: MissingAuthenticationTokenException” from AWS in the response. I turned off the web security proxy service on my work laptop and I was able to create Lambda functions successfully. Hope it helps.

OPTION request rejected by CloudFront

Since last week I have been struggling to fix this problem but still its not resolved. I have deployed my Django code on AWS lambda and configure the API gateway to serve all api and admin section.
All http method are working fine from rest client/postman but when I am trying to integrating the api in AngularJS then try to perform the POST request to the api but Chrome sends a default OPTION request to the server but every time CloudFront returns an error with 500 status.
"Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."
Please help me to resolve the issue as I need to move my product to production.
Thanks,
AbdulWahid
Thanks to Michael-sqlbot's comment, I finally succeed to get 200 response from AWS Lambda. Just enable CORS for your Method in API Gateway then it will work.