# GET data inside serverless function

**URL:** <https://community.hubspot.com/t/get-data-inside-serverless-function/55092>\
**Category:** APIs & Integrations\
**Tags:** professional\
**Created:** [April 15, 2022, 10:01pm UTC](https://community.hubspot.com/t/get-data-inside-serverless-function/55092 "2022-04-15T22:01:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jules53](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@Jules53](https://community.hubspot.com/u/Jules53)\
**Post date:** [April 15, 2022, 10:01pm UTC](https://community.hubspot.com/t/get-data-inside-serverless-function/55092/1 "2022-04-15T22:01:44Z")

</div>

Hello,

I have a website built with Gatsby/React and am trying to create a CMS with Hubspot to manage the blog. I’ve tried the Gatsby/Hubspot plugin for this but the problem is that it will only do a GraphQL query on each build. So if new content is created in Hubspot, I would need to manually rebuild the site each time. That led me to reading about serverless functions in Hubspot and the idea of getting all of the blog posts from Hubspot on page load rather than the single query. I’ve followed these guides:

> **[Get started with serverless functions - HubSpot docs](https://developers.hubspot.com/docs/cms/start-building/features/serverless-functions/getting-started-with-serverless-functions)**
>
> Create your first serverless function on the HubSpot CMS, and get a response from it.

[https://community.hubspot.com/t5/APIs-Integrations/How-to-fix-cors-is-not-allowing-API-request-issue/m-p/459610](https://community.hubspot.com/t5/APIs-Integrations/How-to-fix-cors-is-not-allowing-API-request-issue/m-p/459610)

I cannot figure out how to get data from an api endpoint from my serverless function and return it. I keep getting 500 errors when I hit my endpoint and errors like this:

Runtime.UnhandledPromiseRejection: TypeError: Cannot read property ‘data’ of undefined.

and

UNHANDLED\_ERROR - Execution Time: 445msRuntime.UnhandledPromiseRejection: TypeError: sendResponse is not a function

Here is my serverless.json:

{

“runtime”: “nodejs12.x”,

“version”: “1.0”,

“endpoints”: {

“congratulation”: {

“method”: “GET”,

“file”: “congratulation.js”

},

“getBlogs”: {

“method”: “GET”,

“file”: “getBlogs.js”

},

“getDogs”: {

“method”: “GET”,

“file”: “getDogs.js”

}

}

}

Here is getDogs.js:

exports.main = (sendResponse) =\> {

const getBreeds = async () =\> {

try {

return await axios.get(‘[https://dog.ceo/api/breeds/list/all](https://dog.ceo/api/breeds/list/all)’)

} catch (error) {

console.error(error)

}

}

const countBreeds = async () =\> {

const breeds = await getBreeds()

if (breeds) {

sendResponse({body: “success”, statusCode: 200});

console.log(breeds)

}

}

countBreeds()

}

Any help would be greatly appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [April 18, 2022, 7:32pm UTC](https://community.hubspot.com/t/get-data-inside-serverless-function/55092/2 "2022-04-18T19:32:08Z")

</div>

[@Mark\_Ryba](https://community.hubspot.com/t5/user/viewprofilepage/user-id/138856) , maybe you have some thoughts on this 😀
