How can I fetch companyLocationId using company ID in GraphQL?

Topic summary

Goal: fetch companyLocationId by company ID and also obtain CompanyContactId and CompanyContactRoleId to assign ordering permission during customer creation via GraphQL.

Proposed approach: a responder suggested a generic GraphQL pattern querying company(id) to return companyLocationId and nested companyContact { companyContactId, companyContactRoleId }, noting the query must match the actual schema.

Latest update: the requester tried a companies(first:10) query returning name, id, contactRoles, locations, and contacts. The query succeeds without the contacts field, but fails to retrieve contactId when including contacts { nodes { name id } }.

Key points:

  • The provided example is schema-agnostic and may not reflect the Shopify schema used.
  • The blocker is specifically fetching contacts/contactId; other fields (locations, contactRoles) return as expected.

Status: unresolved. Further schema-specific guidance is needed (e.g., correct field/connection names and nesting for contacts) or clarification on whether contacts are accessible via the chosen endpoint.

Terms: companyLocationId, CompanyContactId, CompanyContactRoleId are identifiers for a company’s location, contact, and contact role, respectively.

Summarized with AI on January 6. AI used: gpt-5.

I am trying to write a query to fetch the companyLocationId based on the company ID.

I need the CompanyContactId, CompanyContactRoleId, and CompanyLocationId to add the ordering permission to the customer while creating them through GraphQL.

Please advise if anyone has any thoughts on this.

@NovaModule1

Certainly! To fetch the CompanyLocationId based on the CompanyId in GraphQL, you’d need to construct a query. Assuming you have a schema similar to this:

query {
company(id: "your_company_id") {
companyLocationId
companyContact {
companyContactId
companyContactRoleId
}
}
}

Replace "your_company_id" with the actual ID you’re querying for. This assumes a structure where a company has a location, and a contact associated with it.

Make sure to adapt the query based on your specific GraphQL schema. If you encounter any issues or have a different schema, feel free to provide more details for a more accurate response.

Hi Sam, Thanks for your input.

I tried writing the below query and it looks like I’m unable to get the contactId. But without the contacts in the query, I get the response.

Could you please let me know what am I missing?

Thanks.

{
companies(first: 10){
nodes{
name

id

contactRoles(first: 5){
nodes{
name

id
}
}

locations(first: 5){
nodes{
name

id
}
}

contacts(first: 5){
nodes{
name

id
}
}
}
}
}