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

w1am
Shopify Partner
9 0 3

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

Replies 5 (5)

Mr_RaviRaj
Shopify Partner
505 57 108

@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

 

 

banned
w1am
Shopify Partner
9 0 3

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?

Liquidator3358
Explorer
44 1 15

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
}
}
}
`

 

w1am
Shopify Partner
9 0 3

Thanks for replying. Where do I get the token?

Liquidator3358
Explorer
44 1 15

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,
        }
      }