# Errors with getStaticPaths for dynamic pages

**URL:** <https://community.prismic.io/t/errors-with-getstaticpaths-for-dynamic-pages/2425>\
**Category:** Developing with Prismic\
**Tags:** nextjs\
**Created:** [October 25, 2020, 4:14pm UTC](https://community.prismic.io/t/errors-with-getstaticpaths-for-dynamic-pages/2425 "2020-10-25T16:14:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![remi](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@remi](https://community.prismic.io/u/remi)\
**Post date:** [October 25, 2020, 4:14pm UTC](https://community.prismic.io/t/errors-with-getstaticpaths-for-dynamic-pages/2425/1 "2020-10-25T16:14:09Z")

</div>

Hi,

I have a `lib/api.js` file where I fetch all the data that I want from the Prismic API using gql. I am currently working on dynamic pages, where `[position].js` will have the uid for documents of this type.

However, I am getting this error in my terminal: `{"message":"Error during variable coercion. Violations:\n\nVariable '$slug' expected value of type 'String!' but value is undefined. Reason: Expected non-null value, found null. (line 2, column 26):\n query PositionBySlug($slug: String!, $lang: String!) {\n ^"}`.

I get that it's undefined but I cannot wrap my head around why. I'm new to NextJS and the React universe, and also GraphQL.

Let's start at the beginning. I use two async functions in `lib/api.js` that I import in `[position].js`. These are:

```
export async function getAllPositionSlugs() {
    const data = await fetchApi(`
        {
            allPositions {
                edges {
                    node {
                        _meta {
                            uid
                        }
                    }
                }
            }
        }
    `)

    return data.allPositions.edges
}

```

This simply returns the uid ("slug") of all the documents that are of type position.

Now for the position data:

```
export async function getAllPositions(slug, previewData) {
    const data = await fetchApi(`
    query PositionBySlug($slug: String!, $lang: String!) {
        position(uid: $slug, lang: $lang) {
            position_title
            _meta {
                uid
            }
        }
    }`,
    {
        previewData,
        variables: {
            slug,
            lang: API_LOCALE,
        },
    })

    return data
}

```

And here is where the error is. With the slug being undefined.

Here are some relevant `[position].js` code, `getStaticProps` and `getStaticPaths`:

```
export async function getStaticProps({ params, preview = false, previewData }) {
    const data = await getAllPositions(params.slug, previewData)
    return {
        props: {
            preview,
            position: data.position ?? null
        },
    }
}

export async function getStaticPaths() {
    const allPositions = await getAllPositionSlugs()
    return {
        paths: allPositions.map(({ node }) => `/position/${node._meta.uid}`) || [],
        fallback: false,
    }
}

```

Thanks for the help! And sorry for the wall of text.

---

<div class="post-metadata">

**Author:** ![samlittlefair](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/samlittlefair/32/696_2.png) [@samlittlefair](https://community.prismic.io/u/samlittlefair)\
**Post date:** [October 29, 2020, 10:21am UTC](https://community.prismic.io/t/errors-with-getstaticpaths-for-dynamic-pages/2425/3 "2020-10-29T10:21:47Z")

</div>

Hey Remi,

Thanks for posting! I think we can work through this together.

The first thing that stands out to me is the name of your param. Your file is called `[position].js`, so I would expect the param to be `params.position`, not `params.slug`.

If you change this line:

```auto
const data = await getAllPositions(params.slug, previewData)

```

To:

```auto
const data = await getAllPositions(params.position, previewData)

```

Does that solve te error?

---

<div class="post-metadata">

**Author:** ![remi](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@remi](https://community.prismic.io/u/remi)\
**Post date:** [October 29, 2020, 4:23pm UTC](https://community.prismic.io/t/errors-with-getstaticpaths-for-dynamic-pages/2425/4 "2020-10-29T16:23:00Z")

</div>

Yes it does, thank you so much for the help 😇

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [October 30, 2020, 4:23pm UTC](https://community.prismic.io/t/errors-with-getstaticpaths-for-dynamic-pages/2425/5 "2020-10-30T16:23:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [December 9, 2021, 5:14pm UTC](https://community.prismic.io/t/errors-with-getstaticpaths-for-dynamic-pages/2425/6 "2021-12-09T17:14:21Z")

</div>


