GraphQL mutation on Api Endpoints for our Store - not Working

GraphQL mutation on Api Endpoints for our Store - not Working

PenguinDev
Shopify Partner
5 0 0

Hello,

I’m creating a custom app for our store and have set up a REST API since we store some information in a separate database. I need to perform a GraphQL mutation on one of these endpoints.

I’ve tested this mutation within the app by directly modifying the code of the "Generate a Product" button that comes by default when creating a new app, and it works. However, when testing the mutation via the API endpoint, I’m getting a 404 status error.

Any idea why this might be happening?

This is the GraphQL mutation:

 
`#graphql
        mutation customerUpdate($input: CustomerInput!) {
          customerUpdate(input: $input) {
            userErrors {
              field
              message
            }
            customer {
              id
              firstName
              lastName
              email
              phone
            }
          }
        }`,
        {
          variables: {
            input: {
              id: `gid://shopify/Customer/${customerShopifyId}`,
              firstName: firstName,
              lastName: lastName,
              email: email,
              phone: phone
            },
          },
        },
      );
 
Replies 5 (5)

Liam
Community Manager
3108 340 871

Do you have a x-request-id for the failing API call? Also can you explain this a bit more:

 

"a REST API since we store some information in a separate database. I need to perform a GraphQL mutation on one of these endpoints."

 

Are you using both our REST and GraphQL APIs together?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

PenguinDev
Shopify Partner
5 0 0

Sorry, I think I worded that incorrectly—my fault. The REST API I mentioned is a custom one, using the app proxy to connect our Shopify store with the custom app. The REST functions primarily use Prisma to connect to our separate database.

To clarify, I’m only using the GraphQL API. The x-request-id is: caacc58a-15ec-4b8b-9702-9554a6d26b1d-1723823640.

Here’s a picture of the POST request: it shows a 200 status, but the response is null. Previously, I was getting a 302 status, followed by a second POST request to Auth/login with a 404 status. I’m not sure what I did to cause the status change.

PenguinDev_0-1723823818544.png

 

Liam
Community Manager
3108 340 871

Have you resolved this? If you're getting a 200 then the API call should be okay/

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Liam
Community Manager
3108 340 871

Also - if you need to store data, have you looked into using metafields or metaobjects to store this data instead of a separate database? I've seen some devs recently use metaobjects instead of databases. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

PenguinDev
Shopify Partner
5 0 0

The reason for the separate database is that it already contains a lot of data. Regarding the issue, while I now receive a 200 status, when I check on GraphQL Admin, the mutation doesn't actually apply any changes, and no error is returned, which I find strange. Previously, I was receiving a 302 status that only returned null.