401 Unauthorized error on Graphl Query

Hi, i’m trying to use the app vtex.orders-graphql@0.93.2 , specifically the customerOrders query.

query myQuery{
 customerOrders{
  list{
  orderId
  creationDate
  status
  totalValue
  orderIsComplete
  }
 }
}

This works and succesfully returns the orders on the frontend of the mystore.myvtex.com domain.

But when testing this query in the frontend of the production domain (mystore.com.ar), the query returns 401 Unauthorized

code: "E_HTTP_401"
isAxiosError: true
message: "Request failed with status code 401"
name: "Error"

Is there any way to make this query work? It shouldn’t need any special permission because this query only accesses the current logged user orders.

Thank you in advance!

2 Likes

Hi!! Did you manage to find a solution? I’m going through the same problem

Hello
I had the same problema recently trying to call some logistics graphql queries.
After some tickets, VTEX replied me that there are some queries that are privates and that is not possible to use then in production.
My solution was refactor the entire component to use REST APIs instead of graphql.

Hi!

One of the main differences between myvtex and production environments is that in myvtex, there is always an authentication cookie present in every request, since it is a private environment that you must be logged in to access.

Because of that, some requests that require authentication work fine there, but stop working on prod since the authentication cookie is absent when the user is not logged in to the store. Even if they are logged, their cookie might not be enough to the request, which might require admin permissions.

In your specific scenario, are you sure that users are always logged in production when that query is executed? If not, that might be the problem.

If they are, you might have to create your own backend to handle the frontend requests in a way that the store user’s token is enough to get the data they need.
There is a OMS client ready to use that you could try using in your custom backend (and it has the listOrders method)

VTEX IO Clients

I hope that helps!

1 Like

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