# I Can't use local Ghost Content Ap

**URL:** <https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502>\
**Category:** Integrations & API\
**Created:** [November 6, 2023, 11:58am UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502 "2023-11-06T11:58:40Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![turkgenciyim](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/turkgenciyim/32/26286_2.png) [@turkgenciyim](https://forum.ghost.org/u/turkgenciyim)\
**Post date:** [November 6, 2023, 11:58am UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502/1 "2023-11-06T11:58:40Z")

</div>

```auto
.env file

GHOST_URL="https://api. ********.com"
GHOST_KEY="fbd***"

```

 ![Ekran görüntüsü 2023-11-06 145529](https://us1.discourse-cdn.com/flex015/uploads/ghost2/original/3X/b/f/bfd3f5ad2fbaa6a9b638743ad2544d81c64c13e5.png)  
 ![Ekran görüntüsü 2023-11-06 145513](https://us1.discourse-cdn.com/flex015/uploads/ghost2/original/3X/b/0/b07e7b33e0bbf61da94bf9afd3b2e61d669996dc.png)  
Why?

Also, this is web site already running. [sigortamglobal.com](https://api.sigortamglobal.com)

---

<div class="post-metadata">

**Author:** ![Cathy\_Sarisky](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/cathy_sarisky/32/25750_2.png) [@Cathy\_Sarisky](https://forum.ghost.org/u/Cathy_Sarisky)\
**Post date:** [November 6, 2023, 1:14pm UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502/2 "2023-11-06T13:14:28Z")

</div>

What do the imports/requires for that first file in the screenshot above look like?

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/kevin/32/32_2.png) [@Kevin](https://forum.ghost.org/u/Kevin)\
**Post date:** [November 6, 2023, 1:30pm UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502/3 "2023-11-06T13:30:20Z")

</div>

The problem is listed in your screenshot:

 ![Screenshot 2023-11-06 at 13.12.55](https://us1.discourse-cdn.com/flex015/uploads/ghost2/original/3X/5/c/5c90d89b66342346cf54216765b27ca50b361027.png)

It’s saying `xhr` isn’t available in the server-side environment in which you’re trying to use the content API library.

I think your options are either providing a [custom `makeRequest` function](https://github.com/TryGhost/SDK/blob/main/packages/content-api/lib/content-api.js#L36-L47) to the Content API library with a http library that’s supported in your environment in place of `axios` or making requests to the API directly without using the library wrapper.

Example of supplying a custom request function that uses `fetch` in place of `axios` (I’ve not tested this, it’s just an example to work from for your own use-case):

```auto
const api = new GhostContentAPI({
  url: process.env.GHOST_URL,
  key: process.env.GHOST_KEY,
  makeRequest: ({url, method, params, headers}) => {
    const apiUrl = new URL(url);

    Object.keys(params).map(key => apiUrl.searchParams.set(key, encodeURIComponent(params[key]);

    return fetch(apiUrl, {method, headers}).then(res => res.json());
  }
};

```

---

<div class="post-metadata">

**Author:** ![fabio-carvalho88](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/fabio-carvalho88/32/27830_2.png) [@fabio-carvalho88](https://forum.ghost.org/u/fabio-carvalho88)\
**Post date:** [December 12, 2023, 9:05pm UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502/4 "2023-12-12T21:05:08Z")

</div>

hey there!

I had the same issue with the Next.js 14 server side environment. How can I use the makeRequest method you mentioned?

 ![image](https://us1.discourse-cdn.com/flex015/uploads/ghost2/original/3X/b/6/b693fa5aae85d55219d13c23ca06833e47ce03d8.png)

---

<div class="post-metadata">

**Author:** ![RyanF](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/ryanf/32/17448_2.png) [@RyanF](https://forum.ghost.org/u/RyanF)\
**Post date:** [December 12, 2023, 9:51pm UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502/5 "2023-12-12T21:51:01Z")

</div>

This looks like a Typescript error. It shouldn’t prevent you from using the makeRequest option. The types are community-supplied and they might not have included the possibility of specifying a custom function as an option.

---

<div class="post-metadata">

**Author:** ![fabio-carvalho88](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/fabio-carvalho88/32/27830_2.png) [@fabio-carvalho88](https://forum.ghost.org/u/fabio-carvalho88)\
**Post date:** [December 13, 2023, 11:39am UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502/7 "2023-12-13T11:39:54Z")

</div>

thanks for replying!

I’ve extended the default interface like so:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/ghost2/original/3X/9/4/943e23cd7550e5f52aaad068e85ac45aa84ed39d.png)

but right now i’m getting this error at line 36:

> TypeError: Cannot read properties of undefined (reading ‘posts’)

Can you help me understand why? Thanks!

---

<div class="post-metadata">

**Author:** ![fabio-carvalho88](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/fabio-carvalho88/32/27830_2.png) [@fabio-carvalho88](https://forum.ghost.org/u/fabio-carvalho88)\
**Post date:** [December 13, 2023, 12:26pm UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502/8 "2023-12-13T12:26:34Z")

</div>

it seems to me this is an error that occurs with the new next.js version 14.

in version 13.4.12, without adding the makeRequest method, everything works as expected.

do you know why this is happening at the latest next.js version? i’m using v14.0.4

---

<div class="post-metadata">

**Author:** ![RyanF](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/ryanf/32/17448_2.png) [@RyanF](https://forum.ghost.org/u/RyanF)\
**Post date:** [December 13, 2023, 2:11pm UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502/9 "2023-12-13T14:11:16Z")

</div>

I’m not sure. I’d log the `api` object to see if it has the shape that’s expected.

Alternatively, if Next.js has more native ways of fetching data (like just using `fetch` directly), then you could opt to bypass the SDK altogether and do that: [Ghost Content API Documentation](https://ghost.org/docs/content-api/)

---

<div class="post-metadata">

**Author:** ![sensei85](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/sensei85/32/22678_2.png) [@sensei85](https://forum.ghost.org/u/sensei85)\
**Post date:** [January 9, 2024, 12:11pm UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502/10 "2024-01-09T12:11:57Z")

</div>

I also have some issue connecting using the sdk. I’m using sveltekit and this is the error I get.

```auto
cause: Error: connect ECONNREFUSED ::1:2368
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) {
    errno: -4078,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '::1',
    port: 2368
  }

```

---

<div class="post-metadata">

**Author:** ![Cathy\_Sarisky](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/cathy_sarisky/32/25750_2.png) [@Cathy\_Sarisky](https://forum.ghost.org/u/Cathy_Sarisky)\
**Post date:** [January 9, 2024, 2:49pm UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502/11 "2024-01-09T14:49:55Z")

</div>

Looks like you’re trying to connect to the ipv6 address. Is Ghost listening on ipv6, or only on ipv4?

---

<div class="post-metadata">

**Author:** ![alyatwa](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/alyatwa/32/28479_2.png) [@alyatwa](https://forum.ghost.org/u/alyatwa)\
**Post date:** [January 19, 2024, 1:15am UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502/12 "2024-01-19T01:15:44Z")

</div>

just add data to return json

```auto
const api = new GhostContentAPI({
	url: "https://ali-atwa.digitalpress.blog",
	key: "bef5171833fd701e51903f181e",
	// @ts-ignore
	makeRequest: ({ url, method, params, headers }) => {
		const apiUrl = new URL(url);
		// @ts-ignore
		Object.keys(params).map((key) =>
			apiUrl.searchParams.set(key, encodeURIComponent(params[key]))
		);

		return fetch(apiUrl.toString(), { method, headers })
			.then(async (res) => {
				// Check if the response was successful.
				if (!res.ok) {
					// You can handle HTTP errors here
					throw new Error(`HTTP error! status: ${res.status}`);
				}
				return { data: await res.json() };
			})
			.catch((error) => {
				console.error("Fetch error:", error);
			});
	},
	version: "v5.0",
});

```

---

<div class="post-metadata">

**Author:** ![rz-codes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/rz-codes/32/29948_2.png) [@rz-codes](https://forum.ghost.org/u/rz-codes)\
**Post date:** [April 17, 2024, 10:31am UTC](https://forum.ghost.org/t/i-cant-use-local-ghost-content-ap/42502/13 "2024-04-17T10:31:52Z")

</div>

The issue still persists. Maybe it has something to do with `next@v14` and `tryghost-content-api@v1.11.7` I’m using `next@v14.1.4` and tried @alyatwa method but couldn’t get it to work. I defaulted to Next `v13.1.3` and it works without issues
