Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unauthenticated graphql admin api request results in a GraphQL Client: Unauthorized error #884

Open
javangriff opened this issue Nov 8, 2024 · 3 comments

Comments

@javangriff
Copy link

Starting with a fresh app, making an unauthenticated admin request as below, where example.myshopify.com is the shop url of a store where the app has been successfully installed, results in a GraphQL Client: Unauthorized error.

import { ActionFunctionArgs } from "@remix-run/node";
import { unauthenticated } from "../shopify.server";

export async function action({ request }: ActionFunctionArgs) {
 const { admin } = await unauthenticated.admin("example.myshopify.com");

 const response = await admin.graphql(
   `#graphql
     mutation populateProduct($input: ProductInput!) {
       productCreate(input: $input) {
         product {
           id
         }
       }
    }`,
    { variables: { input: { title: "Product Name" } } }
  );

 const productData = await response.json();
 return json({ data: productData.data });
}
@lizkenyon
Copy link
Contributor

Hi there 👋

I was not able to reproduce your error.

Could you confirm that your app has the required scopes to make that GraphQL mutation? (write_products).

@javangriff
Copy link
Author

javangriff commented Nov 9, 2024

Hi @lizkenyon thanks for taking a look!

Yep, it does have the write_products scope. I scaffolded the app using the shopify app init command and added a route with the above graphql query, so everything is pretty standard other than that.

@sle-c
Copy link
Contributor

sle-c commented Nov 13, 2024

Hi @javangriff,

I've tried to replicate the issue by creating a new remix app, installing to my dev shop, and adding a new route with the code you shared. The unauthenticated request worked fine. Is there any reason you use unauthenticated instead of authenticate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants