Error Creating Page Using Shopify API in My App (400 Bad Request)

Hello Shopify Community,

I am currently developing an app that interacts with the Shopify API, and I’m facing an issue while trying to create a new page using a GraphQL mutation.

The issue is that when I try to create a page through my app, I receive the following error message:

Error creating page: HttpResponseError: Received an error response (400 Bad Request) from Shopify:
If you report this error, please include this id: 9243ca13-7490-495c-a4e5-5c45888e7a4e-1740049199

However, when I run the same mutation directly via the Shopify GraphQL app, it successfully creates the page without any issues.

Here is the controller code where I’m making the API request:

async function createPage(req, res) {
    try {
      const client = new shopify.api.clients.Graphql({
        session: res.locals.shopify.session,
      });
      
      const data = await client.request({
        data: {
          "query": `mutation CreatePage($page: PageCreateInput!) {
            pageCreate(page: $page) {
              page {
                id
                title
                handle
              }
              userErrors {
                code
                field
                message
              }
            }
          }`,
          "variables": {
            "page": {
              "title": "New Page Title",
              "handle": "new-page-title",
              "body": "This is the content of the page.",
              "isPublished": true,
              "templateSuffix": "custom"
            }
          },
        },
      });
  
      res.status(200).send({
        shopInfo: data,
      });
  
    } catch (error) {
      console.error("Error creating page:", error);
      res.status(500).send({
        error: "An error occurred while creating the page.",
        details: error.message,
      });
    }
}

Route file code:

router.post('/create', createPage);

The error suggests a 400 Bad Request, but I cannot determine the exact cause of the issue. The same GraphQL query works fine when I use the Shopify GraphQL app, so I’m wondering if there is something in the way I’m making the request from my app that might be causing the error.

Has anyone else experienced a similar issue, or can anyone suggest what might be going wrong? Any help or guidance would be greatly appreciated!

Thank you!