# Call ES API from angular

**URL:** <https://discuss.elastic.co/t/call-es-api-from-angular/213899>\
**Category:** Elasticsearch\
**Created:** [January 6, 2020, 2:15pm UTC](https://discuss.elastic.co/t/call-es-api-from-angular/213899 "2020-01-06T14:15:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DILIP\_SHARMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilip_sharma/32/42672_2.png) [@DILIP\_SHARMA](https://discuss.elastic.co/u/DILIP_SHARMA)\
**Post date:** [January 6, 2020, 2:15pm UTC](https://discuss.elastic.co/t/call-es-api-from-angular/213899/1 "2020-01-06T14:15:16Z")

</div>

hi i am trying to call ES API from angular JS , but i am getting the error

> localhost/:1 Access to XMLHttpRequest at '' from origin '[http://localhost:4200](http://localhost:4200)' has been blocked by CORS policy:  
> Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

i am running ES cloud 7x version  
there is any setting i need to change server side ?

adding my js code also

```
const userDetails = {
      "grant_type": "password",
      "username": "***",
      "password": "***"
    };
    let headers = {headers: new HttpHeaders({ 
      'Authorization': "Basic " + btoa(' ***:***'),
      'Content-Type': 'application/json',
      // "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept",
      'Access-Control-Allow-Origin': '*'
    })};

    this.http.post("https: ********", userDetails, headers).subscribe(
            (val) => {
                console.log("POST call successful value returned in body", val);
            },
            response => {
                console.log("POST call in error", response);
            },
            () => {
                console.log("The POST observable is now completed.");
        });
    }

```

Please help me on this .  
Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 3, 2020, 2:15pm UTC](https://discuss.elastic.co/t/call-es-api-from-angular/213899/2 "2020-02-03T14:15:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
