Ionic with Magento API call

Hi,

I am developing an Ecommerce mobile application with Magento backend. When I try to call API from ionic 2 I am getting

XMLHttpRequest cannot load http://amaz4u.com/index.php/rest/V1/customers. Response for preflight has invalid HTTP status code 400

I am getting proper response in postman but when I call from ionic2, getting above error.

Kindly provide me a solution for this.

Response is right there.

Did you research what the “preflight” is?
Did you look at all requests your app is doing to see which one repsonds with a code 400?

I got this issue to… i cant send Authorization header with headers … this is more angularJS 2-4 issue

This problem only is present on Browser, cause on Android and IOS devices works without errors, you must add a proxy config on ionic json config file.

-> ionic.config.json file

“type”: “ionic-angular”,
“proxies”: [
{
“path”: “/magentoAPI”,
“proxyUrl”: “http://magento.docker.local/rest/V1/
}
]
}

and use the path as your url from http
example:
class …
private magentoAPI:string ="/magentoAPI";

customerInfoService() {
let headers = this.headers;
headers.append(‘Authorization’, "Bearer " + this.token);
let options = new RequestOptions({ headers: headers });
return this.http.get(this.magentoAPI + “customers/me”, options)
.map(response => response.json());

}

You can find more info here: Proxy Problems with Ionic

Regards,
Marlon Olaya