User related data from admin request

Hi Guys,

we are currently trying to build a custom shopify app that features user role based access. Is there any way to use the request from the app-admin or some other way to check which access level the currently logged in user has on the shopify admin?

If anyone has ideas or a solution would be great!

Hey again @Tim_Dehler :waving_hand: - right now, there’s not too much staff member /user data available to query via the API, but we do surface some info that might be helpful:

You can use the StaffMember object to pull their account type (the most relevant enums would be to see if they’re restricted members or if they can access the admin) and to see if they’re the shop owner.

At one point, I believe we did offer more user data on the object, but that has been deprecated. Hope this helps - more than happy to set up a feature request on my end here if you’d like to share a use case, definitely understand how this would be useful!

Hi @Alan_G, this insight helped a lot thanks!

1 Like

No worries - glad this helped, let me know if any can clarify anything as always! :slight_smile:

Hello Sir, I’m building a custom embedded app on Shopify POS, and I also want to get logged in User’s data. Could you please tell me that will this API work for me, or is there anything else I can use?

Hey @Banibrata_Manna :waving_hand: with Shopify POS, access to the user data is a bit more limited, but using the POS UI Extension’s available APIs you could get some session information that could tell you about the user/device/session history:

The API with the most user-related info would be the Session API, which should let you get the user and staff member IDs for a specific POS tracking session. You could then cross reference that staff member Id to get more data using the StaffMember Admin API object Tim and I were talking about above.

Hope this helps - let me know if I can help out further!

Thanks, @Alan_G , Is there any way to use these but avoid registering extension because my app will not include toml files, I want locationId, that could help me.

Hey again @Banibrata_Manna :waving_hand: - you should be able to get the location ID through the Session API as an extension app, without creating a “full” app, if that makes sense. It wouldn’t allow you to cross reference the Admin API to get the plain language name of the location, but if you did just need the numerical ID of a location, that might work for your use case.

Hope this helps, again, let me know if I can clarify anything :slight_smile:

Okay Thanks @Alan_G Sir, I only need the numerical ID, but we do need to create an extension, and my project plan doesn’t include making any extension.

And could you please tell me if the user id(the one In JWT token we get from getSessionToken api of app-bridge) can be same for two users from two different shops. I think it is the unique identifier for an user in context of a each shop on Shopify.

@Banibrata_Manna :waving_hand: great questions!

For the JWT token user IDs, the user ID from getSessionToken is technically unique within each shop’s context, so you’re definitely on point there. While it uniquely identifies a user within a specific shop, the same numerical ID could potentially exist in different shops since they’re shop-scoped rather than globally unique across all of Shopify. You should be able to use other fields like iss to determine which shop a session ID belongs too though:

For your question about accessing the location ID without extensions, unfortunately for POS embedded apps, extensions are really the only supported way to access device and session data like location IDs. The POS environment has tighter security restrictions, and extensions provide the necessary APIs to safely interact with POS data.

It does look like you’ve looked into seeing if your app would work as an embedded admin app instead (through App Bridge) though? If you wanted to go with that route, that would give you access to App Bridge APIs which might better suit your needs. Also, just to mention - the TOML configuration approach is actually designed to simplify app development, so it might be worth reconsidering if it could work for your use case.

Hope this helps clarify things! Let me know if you have any other questions :slight_smile:

Thanks @Alan_G Sir, I really appreciate your effort with my queries.

Can you please tell me, will the @shopify/app-bridge-react dependency work in Vue app to get shopify object.

I’m trying to log shopify object but getting an error that says “shopify global not defined” and I want to get location ID from it, I think this could work.

Hey @Banibrata_Manna :waving_hand: - usually that “shopify global not defined” error pops up when an app is being initiated outside of a Shopify App Bridge iframe. There’s a bit more info here that might help with troubleshooting the issue:

Let me know if I can clarify anything or help out further if you’re still encountering any blockers/issues, though!

Thanks @Alan_G, But I’m always accessing my app from Shopify Admin. Also

import { ClientApplication } from '../../client/types';
import { ActionSet } from '../ActionSet';
import { Group, MetaAction, SimpleDispatch } from '../types';
/**
 * Pos action type enum
 * @remarks includes the action prefix and group
 *
 */
export declare enum Action {
    CLOSE = "APP::POS::CLOSE",
    LOCATION_UPDATE = "APP::POS::LOCATION::UPDATE",
    USER_UPDATE = "APP::POS::USER::UPDATE",
    DEVICE_UPDATE = "APP::POS::DEVICE::UPDATE"
}
export interface Location {
    id: number;
    active: boolean;
    name: string;
    locationType?: string;
    address1?: string;
    address2?: string;
    zip?: string;
    city?: string;
    province?: string;
    countryCode?: string;
    countryName?: string;
    phone?: string;
}
export interface User {
    id: number;
    firstName: string;
    lastName: string;
    email: string;
    accountOwner: boolean;
    userType: string;
}
export interface Device {
    name: string;
    serialNumber: string;
}
export interface CloseAction extends MetaAction {
    readonly group: typeof Group.Pos;
    readonly type: typeof Action.CLOSE;
}
export declare function close(): CloseAction;
export declare class Pos extends ActionSet implements SimpleDispatch {
    constructor(app: ClientApplication);
    dispatch(action: Action): this;
}

Please tell me, How can I access this Location Interface’s object.

Hey again @Banibrata_Manna, happy to help with this. I just want to clarify if you’re building a POS extension or an Admin-based app using app bridge? If you’re using app bridge, the App Bridge POS API (more info here), currently you can only retrieve location data, not modify it:

You’d want to run something like this:

await shopify.pos.location();

We do reccommend using POS UI extensions though if you want more on-device control: POS UI extensions

Hope I’m understanding things correctly, let me know if I can help out further!

Thanks @Alan_G Sir, The Embedded App I’m building runs on Admin and Shopify POS both using app bridge, but it doesn’t use any extensions because extensions are not the part of our plan.

also I’m getting a compailation error that says the Cannot find name ‘shopify’.

And FYI, my app is built on Ionic + Vue, TypeScript

Hey @Banibrata_Manna :waving_hand:

For your immediate TypeScript/Vue issue there, the shopify global usually isn’t available until App Bridge is properly initialized. Usually, we can’t assist with non-Shopify library related code assistance, but for Vue with TypeScript, you’d generally need to set up something like this:

import { createApp } from '@shopify/app-bridge';

const app = createApp({
  apiKey: 'your-api-key',
  host: 'your-host-parameter',
});

// For TypeScript, you may need to declare the global
declare global {
  interface Window {
    shopify: any;
  }
}

Since you’re using TypeScript, I’d recommend using this library here as it should help with getting App Bridge set up more smoothly:

Hope this helps, let me know if I can clarify anything more on my end here.

Thanks @Alan_G Sir, I also logged the isShopifyPos() in console, it says true and app bridge is created properly because I’m sucessfully getting the session token from app bridge. The app is always accessed either from admin panel or a Shopify POS app.

I couldn’t figure out what actually is going wrong.

Thanks, I’ll reach out again if I get stuck with any other question.

1 Like

Hello @Alan_G Sir, Please tell me about Organizations on Shopify.

  • Can Multiple Shops(stores having different domains) exist under an organization?
  • Can a User in an Organization have same Shopify’s internal user Id(which I get from App Bridge’s Library’s Session Token) accross different Shops in an Organization?

Hey @Banibrata_Manna :waving_hand: - good to hear from you again! It is possible for multiple shops with separate domains to exist under an organization that is tied to a single account. There’s a bit more info here:

https://help.shopify.com/en/manual/your-account/manage-orgs-and-stores/manage-orgs/group-store

When it comes to the user ID though, these would be on a shop by shop basis even if the user is present on multiple shops. Hope this helps as well, let me know if I can help out further as always. :slight_smile:

1 Like

Hey @Alan_G Sir, I’m Using below dependencies

import { toastController } from '@ionic/vue';
import { getSessionToken } from '@shopify/app-bridge-utils';
import createAppBridge from '@shopify/app-bridge';

and Initializing app-bridge like this:

const createShopifyAppBridge = async () => {
  try {
  const host = new URLSearchParams(location.search).get('host') || "";
  const shop = new URLSearchParams(location.search).get('shop') || "";

  const apiKey = JSON.parse(process.env.VUE_APP_SHOPIFY_SHOP_CONFIG)[shop].apiKey;  
  const shopifyAppBridgeConfig = {
    apiKey: apiKey || '',
    host: host || '',
    forceRedirect: true,
  };
    
  const appBridge = createAppBridge(shopifyAppBridgeConfig);
  
  return Promise.resolve(appBridge);      
  } catch (error) {
    return Promise.reject(error);
  }
}

All this in an Ionic+Vue App written in TypeScript.

I want to get the User details, and the POS location as well.
I can share the whole code, if you want.
Please guide me on this.