# Keep getting an undefined promise

**URL:** <https://community.hubspot.com/t/keep-getting-an-undefined-promise/63311>\
**Category:** APIs & Integrations\
**Created:** [August 19, 2022, 7:47am UTC](https://community.hubspot.com/t/keep-getting-an-undefined-promise/63311 "2022-08-19T07:47:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebasluke](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sebasluke/32/29572_2.png) [@Sebasluke](https://community.hubspot.com/u/Sebasluke)\
**Post date:** [August 19, 2022, 7:47am UTC](https://community.hubspot.com/t/keep-getting-an-undefined-promise/63311/1 "2022-08-19T07:47:25Z")

</div>

Sorry if the question is too simple, but my function keeps getting an empty promise… can you please help me?

const request = require(‘request-promise’);

const hubspot = require(‘@hubspot/api-client’);

const hubspotClient = new hubspot.Client({“accessToken”:“THE ACCESS TOKEN”});

const contactId = ‘51’;

const properties = [“firstname”,

“cedula”,

“email”];

const propertiesWithHistory = [];

const associations = undefined;

const archived = false;

async function f() {

```
console.log('\*\*bleep\*\*ing work')

try {

    const apiResponse = await hubspotClient.crm.contacts.basicApi.getById(contactId, properties, propertiesWithHistory, associations, archived);

    console.log(JSON.stringify(apiResponse.body, null, 2));

    const a = JSON.stringify(apiResponse.body, null, 2);

    return a;

  } catch (e) {

    e.message === 'HTTP request failed'

      ? console.error(JSON.stringify(e.response, null, 2))

      : console.error(e)

  }

```

}

const a = f()

console.log(a)

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [August 22, 2022, 8:40pm UTC](https://community.hubspot.com/t/keep-getting-an-undefined-promise/63311/2 "2022-08-22T20:40:12Z")

</div>

Hi, @Sebasluke 👋 Hey, @JBeatty @taran42 do you have any thoughts on what @Sebasluke can try to troubleshoot their function?

Thank you! — Jaycee

---

<div class="post-metadata">

**Author:** ![JBeatty](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jbeatty/32/52252_2.png) [@JBeatty](https://community.hubspot.com/u/JBeatty)\
**Post date:** [August 22, 2022, 11:25pm UTC](https://community.hubspot.com/t/keep-getting-an-undefined-promise/63311/3 "2022-08-22T23:25:39Z")

</div>

Hi @Sebasluke,

You have a small javascript error here:

```lia-code-sample
const a = f()
console.log(a)

```

Becuase f is an async function it is returning a promise so you need to await it like so:

```lia-code-sample
const a = await f()
console.log(a)

```

Except you are in the top level so you actually need to so something like this:

```lia-code-sample
(async ()=>{
 const a = await f()
 console.log(a)
})();

```

Here I am just defining an async function then imedieatly calling it.

Best,
