Pre-flight not handled for API V2
I am trying to get data for my app using wild apricot.Im using hybrid app. Currently when I am trying to access
events.
https://api.wildapricot.org/v2/Accounts/209675/Events
This is my url.
Then I have to send authorization as header in the GET request.
But whenever I send authorization as header in GET request. It comes as a pre-flight and first OPTIONS request is sent.
But the server is not handling OPTIONS request. How do I get over this scenario.
Request URL:https://api.wildapricot.org/v2/Accounts/209675/Events
Request Method:OPTIONS
Status Code:405 Method Not Allowed
Remote Address:96.43.192.222:443
Response Headers
view source
Cache-Control:no-cache
Connection:close
Content-Length:76
Content-Type:application/json; charset=utf-8
Date:Tue, 02 Aug 2016 07:51:30 GMT
Expires:-1
Pragma:no-cache
X-Backend-Server:M51
X-LB-Server:sslfront1
X-Powered-By:ASP.NET
Request Headers
view source
Accept:/
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Access-Control-Request-Headers:authorization, content-type
Access-Control-Request-Method:GET
Connection:keep-alive
Host:api.wildapricot.org
Origin:http://evil.com/
Referer:http://localhost:8100/
User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
That happens because your try to access API from web browser (possibly Ionic builder). The web app makes cross origin requests, which are not supported in API.
There is no problem to access API from mobile app, our own mobile app for admins works exactly this way. However if you try to access API from ionic builder, then you will face CORS error. Here is a detailed explanation of reasons and possible workaround: blog.ionic.io/handling-cors-issues-in-ionic.
Please let me know if the tutorial helps or not.
Dmitry
-
Bala commented
same happens for contacts as well..
Request URL:https://api.wildapricot.org/v2/Accounts/209675/Contacts/me
Request Method:OPTIONS
Status Code:405 Method Not Allowed
Remote Address:96.43.192.222:443
Response Headers
view source
Cache-Control:no-cache
Connection:close
Content-Length:76
Content-Type:application/json; charset=utf-8
Date:Tue, 02 Aug 2016 11:07:03 GMT
Expires:-1
Pragma:no-cache
X-Backend-Server:M52
X-LB-Server:sslfront1
X-Powered-By:ASP.NET
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Access-Control-Request-Headers:authorization, content-type
Access-Control-Request-Method:GET
Connection:keep-alive
Host:api.wildapricot.org
Origin:http://evil.com/
Referer:http://localhost:8100/
User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1