I used an error token to call an API, it response an error message as below(already changed to json format).
I hope I can change the fixed payload, which configuration file can I modify in APIM? Thank you.
{
"fault": {
"code": 900901,
"message": "Invalid Credentials",
"description": "Access failure for API: /test/v1/check, version: v1 status: (900901) - Invalid Credentials. Make sure you have given the correct access token"
}
}
This cannot be modified from a configuration file. What you can do is engage a sequence and change the error message as described in http://sanjeewamalalgoda.blogspot.com/2015/06/how-to-send-specific-status-code-and.html
Related
I am facing an exception when trying to use Instagram OEmbed.
As stated in this page:
https://developers.facebook.com/docs/graph-api/reference/instagram-oembed/
I sent an HTTP GET request to this endpoint:
https://graph.facebook.com/v12.0/instagram_oembed?url=https://www.instagram.com/p/CUsIdc5ql2b/&app
As stated in the documentation, I am using the "url" querystring parameter. However, I am getting an exception such as:
{
"error": {
"message": "(#200) Provide valid app ID",
"type": "OAuthException",
"code": 200,
"fbtrace_id": "Acr4on4TtEYPIc2RQwqNmDL"
}
}
So there is an error clearly stating that I need to "Provide valid app ID". However, there is no information about how to provide that app ID. I've tried a few, including:
https://graph.facebook.com/{app_id}/v12.0/instagram_oembed?url=https://www.instagram.com/p/CUsIdc5ql2b/
and
https://graph.facebook.com/v12.0/{app_id}/instagram_oembed?url=https://www.instagram.com/p/CUsIdc5ql2b/
with no luck. I am looking forward for solutions.
As CBroe pointed out in the comments, you need a valid access token, which you could add at the end of your url like this:
https://graph.facebook.com/v12.0/instagram_oembed?url=https://www.instagram.com/p/CUsIdc5ql2b?access_token=YOURTOKEN
You can look up further documentation here:
https://developers.facebook.com/docs/graph-api/overview/
Since this did not solve the issue for me, I will post my solution.
One key difference is that I am using the SDK while the poster appears to be handling the url themselves.
FacebookAdsApi.init(
access_token=credentials.password
)
response = AdAccount(self.ad_account_id).get_insights(
**request_kwargs
)
If you're handling requests like this, make sure that you're specifying access_token=xxx as the token is a kwarg. Passing the token directly during initialization without specifying access_token will not throw an error until you actually make a request. However, most other issues with initialization DO throw errors. So it's very easy to get mislead into believing the initialization is not the issue when in fact it is.
I've read other similar posts with exact same error message, however my question is different.
I have an AWS ApiGateway in https://XXXXXXXX.execute-api.us-east-1.amazonaws.com/xxxx/users (from now I will call it as /users ).
I have implemented my ApiGateway to Lambda scripts with Cognito authorization, they work without problems, for example:
/users/me -> returns data of current logged user
The problem is when I call an unexistent route in ApiGateway, for example:
/users/mine123 -> it returns
{ "message":
"'my-cognito-user-id-token' not a
valid key=value pair (missing equal-sign) in Authorization header:
'Bearer my-cognito-user-id-token'." }
My question is... Is there a way to return a NotFound or BadRequest error when route in ApiGateway doesn't exist?
I think is possible implementing resource ANY, but, is there a "clean" way to do it without resource ANY?
Edit 1:
I tried Api Gateway response as well. I set a custom response, an status error code 404 for Resource Not Found but Api Gateway still returns 403 Forbidden.
Edit 2
I already have 4XX responses configured too:
And API Gateway always returns 403 error with this message (as expected for a generic 4XX error), however I think it doesn't make sense because is not a real Forbidden error it's a NotFound or BadRequest error.
For example,
A request to nonexistent route in Github API https://api.github.com/ROUTE_THAT_DOESNT_EXIST returns 404 NotFound.
A request to nonexistent route in StackExchange API https://api.stackexchange.com/ROUTE_THAT_DOESNT_EXIST returns 400 BadRequest.
None of them return 403 Forbidden.
Error message { "message": "token not a valid key=value pair Authorization header: 'Bearer token'. is thrown when "Resource path doesn't exist" with status 403 with a response header "x-amzn-ErrorType" = "IncompleteSignatureException"
A request with an "Authorization" header is sent to an API resource
path that doesn't exist.
We can customize response body in 'Gateway Response' section. There doesn't seem to specific Gateway Response like Unauthorized, Invalid Signature, etc for this scenario, Hence we need to configure Default 4XX
We can update status code and Response Templates. Unlike Integration Response on a successful request process, error gateway response template doesn't support full VTL template but only supports simple place holders.
Example configuration for application/json
{"message":"Invalid Resource","type": "$context.error.responseType","stage": "$context.stage"}
Will return
{
"message": "Invalid Resource",
"type": "DEFAULT_4XX",
"stage": "qa"
}
Not sure whether it is a cleaner way than your suggestion, however you can configure specific gateway response for the missing authentication token - https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-gateway-response-using-the-console.html
In the Gateway Responses pane, choose a response type. In this walkthrough, we use Missing Authentication Token (403) as an example.
You can change the API Gateway-generated Status Code to return a different status code that meets your API's requirements. In this example, the customization changes the status code from the default (403) to 404 because this error message occurs when a client calls an unsupported or invalid resource that can be thought of as not found.
I get the following error message when calling actions for CloudWatch in API Gateway.
"Error": {
"Code": "InvalidAction",
"Message": "Could not find operation DescribeAlarms for version 2009-05-15",
"Type": "Sender"
}
I've been using DescribeAlarms for testing. My setup is as follows.
Integration Type = AWS Service
AWS Service = CloudWatch
HTTP method = POST
Action = DescribeAlarms
The error references the API Version 2009-05-15, which only has ListMetrics and GetMetricStatistics according to it's documentation on page 54. ListMetrics does indeed work as expected with my setup.
The current version is 2010-08-01 but I don't see anyway to reference that in API Gateway. In an example of a POST request in the documentation it shows a header labeled x-amz-target with a value of GraniteServiceVersion20100801.API_Name.
My interpretation is I can put Name = x-amz-target and value 'GraniteServiceVersion20100801.DescribeAlarms' in my http header for the Integration Request in API Gateway.
This doesn't change the response and gives the same error message.
I also used the --debug in CLI when calling describe-alarms, and in the body it shows...
"body": {
"Action":"DescribeAlarms",
"Version":"2010-08-01"
}
So I also set http headers to include Content-Type with a value of 'application/x-amz-json-1.1' and then put in
{
"Action":"DescribeAlarms",
"Version":"2010-08-01"
}
but nothing changed with that either.
Any help or guidance would be greatly appreciated.
Under Method Integration -> URL Query String Parameters
I added Version as the Name and '2010-08-01' under Mapped From.
All actions are now working as expected.
I'm trying to PutMetrics directly from Api Gateway -> Cloudwatch using PutMetricData, Version in the query string params didn't work for me.
These 3 HTTP headers in the Integration Request solved it for me:
Content-Type 'application/json'
X-Amz-Target 'GraniteServiceVersion20100801.PutMetricData'
Content-Encoding 'amz-1.0'
I have an API Gateway POST endpoint that takes in a JSON request body. I have turned on the body request validator and added the request body model. However the error response I'm getting is only some generic message: "message": "Invalid request body" as defined in the Gateway responses. I'm wondering if it is possible to include the specific validation error in the response? In the logs it says specifically
Request body does not match model schema for content type application/json:
[object has missing required properties (["property1","property2",...])]
Is it possible to have something similar to this in the actual response? Thank you.
In Gateway response for error type BAD_REQUEST_BODY error status 400
set Application/json to {"message":$context.error.validationErrorString}
Ref
https://stackoverflow.com/a/48014686
AWS API Gateway will include more details only if the request payload format is valid, but parameters format is invalid:
{
"message": "Missing required request parameters: [p1]"
}
If the request payload is invalid, you will always receive the same message:
{
"message": "Invalid request body"
}
See the bottom of following page:
http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-request-validation-test.html
The only way you can get more details is through logs.
By the way, why do you want to send more details through your API, is it for development and debugging only? If yes, using logs is the way to go. You may have some log processing and storage solution to make your debugging easier (e.g. Splunk, Data Dog, Sumo Logic, etc.)
Otherwise, in general, returning too much of technical details in your API error messages is something to avoid.
When I use the graph api to get public data from pages, I get for some pages a warning and other pages work fine.
The warning is: file_get_contents(http://graph.facebook.com/318993554879922) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in ....
When I look at the data of this company in the graph tool on Facebook, I can see everything I need. Everything look fine
How can I prevent this (or better: what advice can I give to the page owbers whose data I want to show on my website to change)?
I used to think that it was a setting in the profile picture because all pages that went wrong had a "custom" setting. That setting could not be changed. But I asked a page owner to upload a new picture and the problem stayed.
It's because the request is unsupported.
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
So the API will return an HTTP 400 response to you.
It's either this object doesn't exist, was deleted or is a bug.