Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

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

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 110

@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 16

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 16

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