Amazon API Gateway 403 Forbidden - java

Recently, I used the Amazon API Gateway .I created an api ,but the API failed all the time.
At the beginning,I didn't add request headers.The result that API responsed is as follows:
HTTP/1.1 403 Forbidden
{"message":null, "type": "ACCESS_DENIED", "status":"", "other":"" }
Then ,I added a header which named host,the result changed.
HTTP/1.1 403 Forbidden
{"message":"Forbidden"}
I didn't use other AWS.
I set the authorization is none and the API key required is false.
enter image description here
Could you help me?
Thanks!

A cause of {"message":"Forbidden"} which I had which had me stumped was that I had not deployed my API.
For anyone having this issue, check if your gateway has been deployed.
First you will need a Stage, with which you can click Deploy API from the Actions dropdown, selecting your stage.
Deploying will give you an invoke_url, (which ends in /{stage-name}.
For those using Terraform....
You can define an aws_api_gateway_stage which depends on aws_api_gateway_deployment. There is a known issue, at the time of writing, where the deployment doesn't re-trigger, which was the original cause of my forbidden error.
To fix this and get the deployment to run everytime a change has been made, add to aws_api_gateway_deployment:
resource "aws_api_gateway_deployment" "gateway-deployment" {
...
stage_description = "Terraform hash ${md5(join(",", local.all_resources))}"
lifecycle {
create_before_destroy = true
}
}
locals {
all_resources = [
"${aws_api_gateway_resource.simulator-gateway-resource.path}:${aws_api_gateway_method.simulator-gateway-method.http_method}:${aws_api_gateway_integration.simulator-gateway-integration.uri}",
]
}```

Related

Accessing the edit method from google play developer rest api

I successfully authenticated to google play developer rest api and I am getting also the refresh token but I can figure out how to make an edit requests.
I have method signature at the following link:
https://developers.google.com/android-publisher/api-ref/edits/insert
I added the following header
Authorization:{{token_type}} {{access_token}}
but i cant figure out where to put the package name:
POST https://www.googleapis.com/androidpublisher/v2/applications/packageName/edits
I putted packageName like above using get and also as post parameter and in both cases i am encountered "404 not found" error.
Please help.
You can try
POST https://www.googleapis.com/androidpublisher/v2/applications/edits?id = packageid && expiryTimeSeconds = 20
GET https://www.googleapis.com/androidpublisher/v2/applications/**packageName**/edits/**editId**
according to
https://developers.google.com/android-publisher/api-ref/edits#methods
Please verify if you have followed all steps for authentication and authorization as shown here.
Since you are not getting 401 or 403, you might be sending the token correctly.
To call the api:
put your package name as a path paramters and specify the edit resource in the body. Please note that the edit resource is ignored but needs to be provided.
send your request like this:
POST https://www.googleapis.com/androidpublisher/v2/applications/yourPackageNameHere/edits
in the body:
{
"id": "abcd",
"expiryTimeSeconds": "asd"
}
make sure u provide content type in header as well.
Authorization is also required in the headers as you mentioned.
Hope this helps. :)

Microsoft Graph returns 403 Forbidden on a second attempt to create a subscribtion

I did manage to subscribe to Microsoft Graph push notifications for one time for the following resources:
me/calendars;
me/calendars/{id}/events
However, when I try to do the same now, I get:
403 Forbidden https://graph.microsoft.com/v1.0/subscriptions
{
"error": {
"code": "ExtensionError",
"message": "Operation: Create; Exception: [Status Code: Forbidden; Reason: Forbidden]",
"innerError": {
"request-id": "7afa93f6-f616-4ea7-9bbe-c977ffd1e239",
"date": "2017-07-14T16:23:35"
}
}
}
My request looks as follows:
{
"resource": "me/calendars/{ID}/events",
"notificationUrl": "https://myapp/MyService/notifications/",
"clientState": null,
"changeType": "created,updated,deleted",
"expirationDateTime": "2017-07-17T14:53:33Z"
}
Docs that I use:
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/webhooks
I suspect Microsoft Graph to give such an error because of the fact that there is a currently working subscription after me first time subscribing. However, when I worked with outlook API, I could get as many subscriptions as I wanted to.
The question is, does Graph API support multiple subscriptions for one resource and if yes, what can be the cause of the 403 Forbidden in such a case?
yes, Microsoft graph supports multiple subscription for one resource. We investigated this request. Exchange is denying the access. Please make sure you are using right credentials. Please reactive this issue if necessary. Thank you.
The error was fixed after adding additional scopes.
Before:
Calendars.ReadWrite.Shared Files.ReadWrite.All User.Read openid offline_access profile
After:
Calendars.Read Calendars.ReadWrite.Shared Calendars.ReadWrite Files.ReadWrite.All User.Read openid offline_access profile

XPages and REST : Error 500 from IBM Notes Client

i'm trying to get a JSON representation of a view with an ajax request from a XPage.
First of all, i did it with the following url https://myserver/mydb/myview?readviewentries&outputformat=JSON&count=-1.
It works in browsers but not in IBM Notes Client (my application have to work in the both), i got an error 404, i read on internet that we can't use that syntax in the Notes client. So i tried to use the restService element from XPages to get my JSON.
I create a XPage with the following code :
<xe:restService id="restService1" pathInfo="JoursFeries">
<xe:this.service>
<xe:viewJsonService defaultColumns="true"
databaseName="Applis/JoursFeries.nsf" viewName="JoursFeries">
</xe:viewJsonService>
</xe:this.service>
</xe:restService>
I changed my URL to call my Rest service like that : myXpage.xsp/JoursFeries (My new XPage is on the same database as the calling XPage). One more time, it works on browsers but still not in IBM Notes client. I called it like that :
var feries = {
url : "xRestJoursFeries.xsp/JoursFeries",
handleAs : "json",
sync : true,
preventCache : this.urlPreventCache,
load : function(json) {
// My callback function
}
}
dojo.xhrGet(feries);
When I activate my XPage debugger in Notes client, I just can see that the page returns an error 500, my console just said that :
WARNING CLFAD####W: State data not available for /xRestJoursFeries because no control tree was found in the cache. ::class.methot=com.ibm.xsp.application.ViewHandlerExImpl_restoreView() ::thread=Thread-348 ::loggername=anonymous
I tried many parameters on my XPages which provides the REST service, but without success.
Thank you in advance.
The URL's in xPINC are different. You will need to change the URL's. Check this page for some info.
http://xomino.com/2013/02/03/xpinc-browser-url-format-and-why-my-demo-failed-at-ibmconnect-part-2/
You could utilize #ClientType() in an if statement to choose onee URL over another.
You could also run xpages on the server and the app would work in both.

Error while using part="...,processingDetails" in a youtube.videos.insert() request

We're developing in java 7 and YouTube Data API v3.
When we are calling the upload service with "processingDetails" part, we are getting a 503 Service Unavailable Error. What are we doing wrong? If we remove it, we can upload the video just fine. But we want/need to know about processingDetails.
Here is the code:
YouTube.Videos.Insert videoInsert = this.youtube.videos().insert("snippet,statistics,status,processingDetails", videoObjectDefiningMetadata, mediaContent);
everything else it's the same as the java client provided in google API.
Here is the request:
https://www.googleapis.com/upload/youtube/v3/videos?part=snippet,statistics,status,processingDetails
And here is the exception stack trace:
2013-06-14 17:50:40,375 ERROR [] [main] (...)despegar.client.impl.YouTubeMediaClient (YouTubeMediaClient.java:264) : Error
com.google.api.client.googleapis.json.GoogleJsonResponseException: 503 Service Unavailable
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:111)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:38)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.despegar.client.impl.YouTubeMediaClient.uploadVideoWithFailureRecovery(YouTubeMediaClient.java:285)
at com.despegar.client.impl.YouTubeMediaClient.uploadAttempt(YouTubeMediaClient.java:260)
Thanks!
Two things:
The part parameter values you include in your youtube.videos.insert() request should correspond to the parts you're specifying in the upload metadata. Normally this would be snippet (since that's the part containing the required title and description) and sometimes status (if you're also setting the public/private status of the video). You can't set statistics or processingDetails during an upload, so you shouldn't include them in the list of parts. You can still request the statistics or processingDetails parts after the upload completes, via a youtube.videos.list() call.
The API should return a meaningful error message explaining this to you instead of returning a generic 503. I'll file a bug with the engineering team asking them to take care of that.

SOAP web service calls from Javascript

I'm struggling to successfully make a web service call to a SOAP web service from a web page. The web service is a Java web service that uses JAX-WS.
Here is the web method that I'm trying to call:
#WebMethod
public String sayHi(#WebParam(name="name") String name)
{
System.out.println("Hello "+name+"!");
return "Hello "+name+"!";
}
I've tried doing the web service call using the JQuery library jqSOAPClient (http://plugins.jquery.com/project/jqSOAPClient).
Here is the code that I've used:
var processResponse = function(respObj)
{
alert("Response received: "+respObj);
};
SOAPClient.Proxy = url;
var body = new SOAPObject("sayHi");
body.ns = ns;
body.appendChild(new SOAPObject("name").val("Bernhard"));
var sr = new SOAPRequest(ns+"sayHi",body);
SOAPClient.SendRequest(sr,processResponse);
No response seems to be coming back. When in jqSOAPClient.js I log the xData.responseXML data member I get 'undefined'. In the web service I see the warning
24 Mar 2011 10:49:51 AM com.sun.xml.ws.transport.http.server.WSHttpHandler handleExchange
WARNING: Cannot handle HTTP method: OPTIONS
I've also tried using a javascript library, soapclient.js (http://www.codeproject.com/kb/Ajax/JavaScriptSOAPClient.aspx). The client side code that I use here is
var processResponse = function(respObj)
{
alert("Response received: "+respObj);
};
var paramaters = new SOAPClientParameters();
paramaters.add("name","Bernhard");
SOAPClient.invoke(url,"sayHi",paramaters,true,processResponse);
I've bypassed the part in soapclient.js that fetches the WSDL, since it doesn't work
(I get an: IOException: An established connection was aborted by the software in your host machine on the web service side). The WSDL is only retrieved for the appropriate name space to use, so I've just replaced the variable ns with the actual name space.
I get exactly the same warning on the web service as before (cannot handle HTTP method: OPTIONS) and in the browser's error console I get the error "document is null". When I log the value of req.responseXML in soapclient.js I see that it is null.
Could anyone advise on what might be going wrong and what I should do to get this to work?
I found out what was going on here. It is the same scenario as in this thread: jQuery $.ajax(), $.post sending "OPTIONS" as REQUEST_METHOD in Firefox.
Basically I'm using Firefox and when one is doing a cross domain call (domain of the address of the web service is not the same as the domain of the web page) from Firefox using AJAX, Firefox first sends an OPTIONS HTTP-message (before it transmits the POST message), to determine from the web service if the call should be allowed or not. The web service must then respond to this OPTIONS message to tell if it allows the request to come through.
Now, the warning from JAX-WS ("Cannot handle HTTP method: OPTIONS") suggests that it won't handle any OPTIONS HTTP-messages. That's ok - the web service will eventually run on Glassfish.
The question now is how I can configure Glassfish to respond to the OPTIONS message.
In the thread referenced above Juha says that he uses the following code in Django:
def send_data(request):
if request.method == "OPTIONS":
response = HttpResponse()
response['Access-Control-Allow-Origin'] = '*'
response['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
response['Access-Control-Max-Age'] = 1000
response['Access-Control-Allow-Headers'] = '*'
return response
if request.method == "POST":
# ...
Access-Control-Allow-Origin gives a pattern which indicates which origins (recipient addresses) will be accepted (mine might be a bit more strict than simply allowing any origin) and Access-Control-Max-Age tells after how many seconds the client will have to request permission again.
How do I do this in Glassfish?
Have you actually tested that ws is working properly?
You can use SoapUI for inspecting request/response etc.
When you confirm that ws is working from SoapUI, inspect what is format of raw Soap message. Then try to inspect how it looks before sending with .js method, and compare them.
It might help you understand what is wrong.
Check if this helps
http://bugs.jquery.com/attachment/ticket/6029/jquery-disable-firefox3-cross-domain-magic.patch
it's marked as invalid
http://bugs.jquery.com/ticket/6029
but it might give you some hint
On the other hand, instead to override proper settings for cross-domain scripting might be better if you can create and call local page that will do request to ws and return result.
Or even better, you can create page that will receive url as param and do request to that url and just return result. That way it will be more generic and reusable.

Categories