# Calling a provider function returns undefined

**URL:** <https://forum.ionicframework.com/t/calling-a-provider-function-returns-undefined/113987>\
**Category:** ionic-v3\
**Created:** [November 30, 2017, 8:43pm UTC](https://forum.ionicframework.com/t/calling-a-provider-function-returns-undefined/113987 "2017-11-30T20:43:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cypaubr](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/cypaubr/32/115494_2.png) [@Cypaubr](https://forum.ionicframework.com/u/Cypaubr)\
**Post date:** [November 30, 2017, 8:43pm UTC](https://forum.ionicframework.com/t/calling-a-provider-function-returns-undefined/113987/1 "2017-11-30T20:43:42Z")

</div>

Hello, I have a provider for consuming my REST API but I have a problem when I try to get the response from it.

Here is the method of my provider:

```auto
getBusinesses(token: string){
    return new Promise((resolve,reject) => {
      let request = new HttpRequest('GET',this.listBusinesses,{
        headers: new HttpHeaders({
          'X-AUTH-TOKEN': token
        })
      });

      this.http.request(request).subscribe(data => {
        console.log(data['body']); //works, show my JSON array
        resolve(data);
      }, err => {
        reject(err);
      })
    });
  }

```

And here is the method called by my view:

```auto
private getBusinesses() {
    this.cityfidAPI.getBusinesses(token).then(res => {
      this.businesses = res['body'];
      console.log(this.businesses); //undefined
    });
}

```

As you see, I have 2 console.log() on dispays the list and the second displays ‘undefined’ and I don’t know why…

Cheers!

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 10:01pm UTC](https://forum.ionicframework.com/t/calling-a-provider-function-returns-undefined/113987/2 "2021-07-19T22:01:15Z")

</div>


