Title: NextJS &amp; Headless WordPress api function returning undefined
Last modified: November 14, 2023

---

# NextJS & Headless WordPress api function returning undefined

 *  Resolved [isaacmtait](https://wordpress.org/support/users/isaacmtait/)
 * (@isaacmtait)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/nextjs-headless-wordpress-api-function-returning-undefined/)
 * Using the GraphIQL IDE I generated a query to collect the information I needed
   from my WordPress blog and inject it into a nextjs component that I import into
   a test page of my nextjs app. The query works in the IDE but returns undefined
   when console.log it in development. I cannot figure out why. I have these two
   files where the code for this implementation is: 
   [https://github.com/Isaac-Tait/wordpress_nextjs/blob/main/src/lib/api.js](https://github.com/Isaac-Tait/wordpress_nextjs/blob/main/src/lib/api.js)&&
   [https://github.com/Isaac-Tait/wordpress_nextjs/blob/main/src/components/Blog.js](https://github.com/Isaac-Tait/wordpress_nextjs/blob/main/src/components/Blog.js)
 * I am not sure what I am doing wrong, or why the function getAllPosts is not returning
   the data in the NextJS app but is working fine in the IDE.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fnextjs-headless-wordpress-api-function-returning-undefined%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Jason Bahl](https://wordpress.org/support/users/jasonbahl/)
 * (@jasonbahl)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/nextjs-headless-wordpress-api-function-returning-undefined/#post-17201370)
 * [@isaacmtait](https://wordpress.org/support/users/isaacmtait/) I’m not sure why
   the code isn’t working for you. 
   I pasted the code in my browser console and 
   I was able to execute and get results back. see: [https://cloudup.com/cGL2sdtWC-b](https://cloudup.com/cGL2sdtWC-b)
   Maybe double check your API_URL?I’m going to mark this as resolved as I don’t
   believe this appears to be an issue with the WPGraphQL plugin. For general questions
   and discussions like this, I recommend checking out the WPGraphQL Slack ([join here](https://join.slack.com/t/wp-graphql/shared_invite/zt-3vloo60z-PpJV2PFIwEathWDOxCTTLA))
 *  Thread Starter [isaacmtait](https://wordpress.org/support/users/isaacmtait/)
 * (@isaacmtait)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/nextjs-headless-wordpress-api-function-returning-undefined/#post-17202137)
 * Thank you for taking a look at it Jason. The cloudup video was pretty cool too.
   I had a great debugging session with a user from the NextJS Discord server and
   he helped me ascertain what was going on (de-structuring issues and I was also
   not passing through the right parameters to the components) Here is the commit
   that got me squared away in case anyone else in the future experiences this issue
   or a similar one 
   [https://github.com/Isaac-Tait/wordpress_nextjs/commit/fdbf7142ecb5138565b7d34181f1dabc3e6951a8](https://github.com/Isaac-Tait/wordpress_nextjs/commit/fdbf7142ecb5138565b7d34181f1dabc3e6951a8)
 * You are correct – the issue is resolved and it was not a WPGraphQL issue either.
    -  This reply was modified 2 years, 6 months ago by [isaacmtait](https://wordpress.org/support/users/isaacmtait/).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘NextJS & Headless WordPress api function returning undefined’ is closed
to new replies.

 * ![](https://ps.w.org/wp-graphql/assets/icon-256x256.png?rev=3561150)
 * [WPGraphQL](https://wordpress.org/plugins/wp-graphql/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-graphql/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-graphql/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-graphql/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-graphql/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-graphql/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [isaacmtait](https://wordpress.org/support/users/isaacmtait/)
 * Last activity: [2 years, 6 months ago](https://wordpress.org/support/topic/nextjs-headless-wordpress-api-function-returning-undefined/#post-17202137)
 * Status: resolved