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

Order query is returning null #352

Closed
pmventura opened this issue Oct 22, 2020 · 11 comments
Closed

Order query is returning null #352

pmventura opened this issue Oct 22, 2020 · 11 comments

Comments

@pmventura
Copy link

Describe the bug
I'm trying to extract a particular order via Postman but it's returning a null order. However, when trying to query via GraphiQL, it works as expected.

Query:

query Orders {
  order(orderId: 7400) {
    orderId
    metaData {
      key
      value
    }
    billing {
      firstName
      address1
      address2
      postcode
      state
      phone
      email
      country
      company
      city
    }
    lineItems {
      nodes {
        product {
          name
          productId
          productCategories {
            edges {
              node {
                name
              }
            }
          }
          productTags {
            nodes {
              name
            }
          }
        }
      }
    }
  }
}

Expected behavior
Should return order

Screenshots
Screenshot 2020-10-22 at 1 52 51 PM

@jacobarriola
Copy link
Contributor

Sounds like you need to add authentication, since the Order type isn't publicly accessible. It works in your GraphiQL because you're logged into WordPress while making those queries.

@kidunot89
Copy link
Member

kidunot89 commented Oct 23, 2020

@pmventura The orders root-level query is inaccessible for unauthenticated users. If the order was made by a guest, the user need at least a session token to query their own orders, and the billing email must be set on the session. You can set it with the updateCustomer() mutation.

@pmventura
Copy link
Author

@jacobarriola @kidunot89 I see. Thank you for the explanation

@brianpereradap
Copy link

@kidunot89 I'm trying the get an order of a guest user and its returning null. I updated the billing email of the guest user is already updated on the session and I'm passing the woocommerce-session token on the request header. But still, the order query is returning null. Im using the plugin version 0.10.4. Am I passing the session correctly?

The same query for logged-in users are working as expected.

Any help will be appreciated.

@kidunot89
Copy link
Member

kidunot89 commented Jan 19, 2022

@brianpereradap How are you creating the guest order? checkout, createOrder, or passing to a hosted checkout page? And can you confirm that the billing email on the order matches the guest's assigned billing email in the WC

@brianpereradap
Copy link

@kidunot89 Im using the checkout mutation to create the order and then use Paypal to collect the payment. Once the payment is completed I used the updateOrder mutation to update the status from Pending to Processing (had to add graphql_woocommerce_authorized_to_update_orders filter to get past auth).
Once all this done, I'm redirect the user the order confirmation page to show the order details.

I can confirm that the customer->billing->email and order billing email are the same
image
image

Pleas note that for guest users get order query request my authorization header is empty. Is this the reason? If so how do I get the auth token for guest users?
image

@kidunot89
Copy link
Member

@brianpereradap Can you try removing the authorization header entirely from the request? Not even an empty authorization header.

@brianpereradap
Copy link

@kidunot89 tried adding an empty auth header, but it didn't work. I was using the order query.

I was able to get the guest customer order information using the customer query instead. I was referring to the following ticket #432.

image

I guess this would be sufficient for now. @kidunot89 thanks for responding to my queries. Really appreciate your contribution.

@kidunot89
Copy link
Member

@brianpereradap Your not supposed to use the orders query for guest orders.

@alexkey89
Copy link

alexkey89 commented Jan 22, 2022

Hi all, I'm trying to create a headless admin panel using WPGRAPHQL for my client. I've done it already using rest api (with some hacks to add featured image url in function.php etc) & woocommerce oauth. It works with REST API but it doesn't seem to work with WPGRAPHQL. I'm simply trying to "GET" the orders but always returns null even with correct jwt token authorization there. Is there anything that could be conflicting? I'm using JWT Auth plugin for that. Do I have to use https://github.com/wp-graphql/wp-graphql-jwt-authentication for it to work? (GRAPHiQL works fine when i'm logged in in wordpress)

    Authorization: Bearer the-token
    Content-Type: application/json

body:

query GET_RECENT_ORDERS {
  orders(first:5){
    edges{
      node{
        orderNumber
        total
        customer{
          firstName
          lastName
        }
      }
    }
  }
}

response:

{
    "data": {
        "orders": null
    },
    "extensions": {
        "debug": []
    }
}

@FullstackWEB-developer
Copy link

@kidunot89 tried adding an empty auth header, but it didn't work. I was using the order query.

I was able to get the guest customer order information using the customer query instead. I was referring to the following ticket #432.

image

I guess this would be sufficient for now. @kidunot89 thanks for responding to my queries. Really appreciate your contribution.

Hi @brianpereradap
I think you tried in Graphql IDE in admin page.
But did you test it in postman?
I tried but I got like this result:
image
I used woocommerce-session correctly.

Furthermore we can see that this issue is still unresolved.
If you have resolved this issue, please kindly let me know.

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

6 participants