How to get currently logged in customer details from a Shopify store using the API

Is there a way to get the logged in customer from any store?

1 Like

@w1am

Yes, if you have Generated the token while installing the Custom app.
then you can get all the details of any store.

Here is a link,
https://shopify.dev/api/admin-rest/2022-04/resources/customer#top

What I’m trying to do is use the id field of the customer who has logged into my Shopify store to fetch data from my server. Any idea how?

Ideally, you would use a customerAccessToken and replace the ID with that. Customer mutations allow for either ID or customerAccessToken. Here is an example query:

const queryCust = `{
customer(customerAccessToken: "${token}"){
id
firstName
lastName
defaultAddress{
address1
}
}
}
`

Thanks for replying. Where do I get the token?

You need to generate it at user login. It’ll look something like this:

const query = `
      mutation customerAccessTokenCreate($input: CustomerAccessTokenCreateInput!) {
        customerAccessTokenCreate(input: $input) {
        customerAccessToken {
            accessToken,
            expiresAt
      }
      customerUserErrors { 
              field
              message
              code 
          }

      }
    }
    `
    const variables = {
        "input": {
            "email": email,
            "password": password,
        }
      }