Why can I invoke my API Gateway endpoint from terminal but not from Braintree's console? - amazon-web-services

I have an API Gateway that invokes a lambda function. I deployed the gateway and am succesfully invoking the function from my terminal by sending a POST request to the endpoint. I do this like so:
curl -H "Content-Type: application/json" -X POST -d "{\"bt_signature\":\"curl\",\"bt_payload\":\"abcsdsddsd\"}" https://*myendpointurl*
When I enter this endpoint in my Braintree console though as a webhook url though and click "check url" i get the following error pop up:
Last delivery unsuccessful. Invalid server response 400
It is weird that it works when I invoke it from my terminal but not here. Futhermore when i enter my endpoint for the method in my web browser it turns up with this error message:
{"message":"Missing Authentication Token"}
I have double checked I am using the write endpoint for this specific POST method. It's just weird that it works from terminal but not as a webhook url in braintree. Ideas?

The reason you get "Missing Authentication Token" when hitting from the browser is because the browser will make a GET request, whereas your API is setup for POST method. API Gateway will respond with a "Missing Authentication Token" when you make requests for non-existent resources/methods. (It's possible Braintree is also generating a GET request internally, but I would recommend you check with their support for confirmation.)
Hope this helps,
Ritisha.

Related

Missing Authentication Token while accessing API Gateway when tested in chrome but working in postman

I created an AWS Lambda function which invokes the endpoint of ML model I created in sagemaker. I tested it and it's working fine. Next I created REST API that calls this lambda function. I set any authentication type as NONE. Anyone with the url can access it. I created it following this aws blog. I tested my url in postman. It's working fine in postman but when I entered the url in chrome, its throwing {"message":"Missing Authentication Token"} error. Can someone please tell how do I get rid of that error while testing my url in chrome
The error is misleading. It's got absolutely nothing to do with tokens. What is actually happening is that the URL you are trying to access is invalid.
API Gateway's URL looks like this: https://xxxxxxx.execute-api.some-region.amazonaws.com/your-stage but it's very likely that you created an endpoint on API Gateway, which would then be accessible via https://xxxxxxx.execute-api.some-region.amazonaws.com/your-stage/YOUR_ENDPOINT
If you hit the base URL or a path which does not exist, you will get that weird, misleading Missing Authentication Token message.
So, long story short, hit a valid path for your API and it should work just fine.
Tip: maybe you are doing a POST request via Postman but whenever you try with the browser it issues a GET request, which would also result in an invalid path and therefore the Missing Authentication Token message.

How to POST a request on Moodle using POSTMAN api tool

I want to create an API request in Postman that creates a category in Moodle.
The following are the steps which I did in Moodle :
Enabled Web service
Created an External service and added core_course_create_categories function.
Enabled REST protocol
Created Token.
This is my POST URL:
http://localhost/test/moodle/webservice/rest/server.php?username=admin&password=Password#1&service=mycustomservice&name=CustomCategory&parent=1&idnumber=CSTM1&description=Desc
Under Authorization tab, I have selected Bearer Token and added the Token from Moodle web service.
When I send the request, I am getting invalidtoken Invalid token - token not found error.
Can anyone please suggest a solution for this
Moodle version: 3.4.8 and Postman version 7.6.0
Thanks in advance.
You can not call API by GET Method.
In postman you have to call the API using POST method.
pass your token in form-data as wstoken.
call your function as wsfunction.
Check my Screenshot below.

How to send a POST request which has Content-Type "application/x-www-form-urlencoded' by using AWS API Gateway?

I'm trying to send a POST request to a REST service via AWS API Gateway.
The content-type of the request should be 'application/x-www-form-urlencoded'. It's an authentication service that I'm trying to access. I'm sending 'username' and 'password' in my request body.
When I send the the request via Postman, it works ( It's giving me the proper response ).
But I want to create an API from the API Gateway to access this endpoint.
When I create a POST method in the API Gateway and try to test it without specifying any content-type, the back-end server tells me to send the request by using the content-type 'application/x-www-form-urlencoded'.
Then when I try to put the content-type in 'Mapping Template' section in the 'Integration Request' of the API, the request doesn't even hit the backend. There's an error ( a JSON response ) comes when I test it, saying 'Unsupported Media Type'.
Does anyone out here knows any workaround for this?
I found the solution.
In order to access a POST service using the content-type ‘application/x-www-form-urlencoded’ in API Gateway, make sure you are doing the following in the API console.
Make sure you have enabled the ‘Use HTTP Proxy integration’ as the following in the ‘Integration Request’ section.
When you test the request, make sure you are putting the content type ‘application/x-www-form-urlencoded’ inside the Header’s box as in the following.
And the request body should be like the following as well.
username=user#wellcomww.com.au&password=123456

how to execute aws apigateway post method form client?

I have created a API gateway which have both get and post method , and both have same parameters and will execute the same lambda function . my get method url is;
https://zfd17ebjag.execute-api.ap-south-1.amazonaws.com/stage/cons?name=testname
and my post method url is;
https://zfd17ebjag.execute-api.ap-south-1.amazonaws.com/stage2/cons?name=testname
when I call a get url it executes successfully..
but when I call a post url it show the following wrror..
{"message":"Missing Authentication Token"}
is it any other way to call post method ?
The way of invoking a GET and POST urls is different. GET is used to request data from a specified resource. While POST is used to send data to a server to create/update a resource.
In your case, it looks like you have enabled API Key required in Method request.
Now either you turn off API Key required or you have to send API Key in Header when calling POST Method url.
Assuming XXXXXXXXX is the API Key and Content Type is application/json. You can invoke POST url using curl. See below command.
curl -X POST -H "x-api-key: XXXXXXXXX" -H "Content-Type: application/json" -d '{"name":"testname"}' https://zfd17ebjag.execute-api.ap-south-1.amazonaws.com/stage2/cons
You can also call the POST url through postman.
See screenshots.
Set post body.

How to access secured backend API using API Gateway?

I have created a backend spring-boot REST api which is deployed on the EC2 that is authenticated with JWT. So, I first curl to get the Bearer token:
curl -iH "Content-Type: application/json" -X POST -d '{"username":"myusername", "password":"mypassword"}' http://123.45.6782.910:8080/login
Then make the REST call to access my REST resource
curl -H "Authorization: eyJhbGzd9.NYHXPv-vXUIoNr7qtA" http://123.45.6782.910:8080/categories/pets/
This all works fine.
Now, I want to use API Gateway to access the /categories/pets/ Resource.
I have setup GET - Method execution's Method request, Integration Request sections. But, when I try to Test the setup, I get 403.
{
"timestamp": 1498392625274,
"status": 403,
"error": "Forbidden",
"message": "Access Denied",
"path": "/categories/pets/"
}
I think this is expected because I am directly trying to access the backend api without the bearer token. I want to know how can I do the POST on http://123.45.6782.910:8080/login to get the Bearer token and then make the call to /categories/pets/ ?
UPDATE: As per #KaHouIeong suggestion, I created a POST endpoint /login on the API gateway to get the bearer token, When I test is in the test console in the API Gateway, I am getting the Authorization →Bearer eyJhbGzd9 but when I try it from postman, I am getting the status 200 OK but not the Authorization →Bearer eyJhbGzd9 token.
content-length →0
content-type →application/json
status →200
via →1.1 swfbfbbaf3fb6c32bdccb152354539e473d.cloudfront.net (CloudFront)
x-amz-cf-id →K9V3XUxHOretrza0kCM5dk_G5eZgePrtrBziyVTxptrePD7wjsWqk-l0kCQQ==
x-amzn-requestid →5ac81024-5c27-11e7-af9a-9f3c8494c542
x-amzn-trace-id →Root=1-5953e77f-ed76d15b5bfre9374c9
Your client should send a request to /login and get the bearer token from the response, then re-use the token to access your /categories/pets/ API.
The workflow should be same as you hit your EC2 backend directly.
For your API setup on API Gateway, you need to setup a /login resource and point to the http://123.45.6782.910:8080/login
Then, you need to setup the integration response header mapping to map the Authorization header back to the method response, then API Gateway will pass through the header to the client.
integration.response.header.Authorization -> method.response.header.Authorization