# Ionic with Magento API call

**URL:** <https://forum.ionicframework.com/t/ionic-with-magento-api-call/81537>\
**Category:** ionic-v3\
**Created:** [March 2, 2017, 8:07am UTC](https://forum.ionicframework.com/t/ionic-with-magento-api-call/81537 "2017-03-02T08:07:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dilipwk](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dilipwk](https://forum.ionicframework.com/u/dilipwk)\
**Post date:** [March 2, 2017, 8:07am UTC](https://forum.ionicframework.com/t/ionic-with-magento-api-call/81537/1 "2017-03-02T08:07:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [March 2, 2017, 9:54am UTC](https://forum.ionicframework.com/t/ionic-with-magento-api-call/81537/2 "2017-03-02T09:54:25Z")

</div>

> [@dilipwk](#):
>
> Response for preflight has invalid HTTP status code 400

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?

---

<div class="post-metadata">

**Author:** ![nirgoldman](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nirgoldman/32/90218_2.png) [@nirgoldman](https://forum.ionicframework.com/u/nirgoldman)\
**Post date:** [May 16, 2017, 1:32pm UTC](https://forum.ionicframework.com/t/ionic-with-magento-api-call/81537/3 "2017-05-16T13:32:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![molayac](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/molayac/32/111985_2.png) [@molayac](https://forum.ionicframework.com/u/molayac)\
**Post date:** [July 25, 2017, 8:27pm UTC](https://forum.ionicframework.com/t/ionic-with-magento-api-call/81537/4 "2017-07-25T20:27:35Z")

</div>

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/](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](https://forum.ionicframework.com/t/proxy-problems-with-ionic-2/43354/10)

Regards,  
Marlon Olaya
