How can I fetch companyLocationId using company ID in GraphQL?

NovaModule1
Visitor
2 0 0

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.

Replies 3 (3)

Samia_Akram22
Shopify Partner
60 10 14

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

```graphql
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.

Problem Solved? ✔Accept and Like solutions to help future merchants.
NovaModule1
Visitor
2 0 0

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

Samia_Akram22
Shopify Partner
60 10 14

@NovaModule1 

It seems like you're experiencing an issue fetching the `contactId` when including the `contacts` field in your query. To troubleshoot, you can check the following:

1. Field Existence: Confirm that the `id` field is indeed present in your `contacts` node. It's possible that the field name might be different in your GraphQL schema.

2. Data Availability: Ensure that the contacts you're trying to fetch have the `id` field populated. If the field is empty or null, it won't be included in the response.

3. Pagination: If there are more than 5 contacts associated with a company, you might need to paginate through the results using the `after` or `cursor` parameter.

Here's an updated query structure with a focus on contacts:

```graphql
{
companies(first: 10) {
nodes {
name
id

contactRoles(first: 5) {
nodes {
name
id
}
}

locations(first: 5) {
nodes {
name
id
}
}

contacts(first: 5) {
nodes {
name
id
}
}
}
}
}
```

If the issue persists, consider checking your GraphQL schema documentation or contacting your backend team to ensure the correct field names and relationships are being used in your query.

Problem Solved? ✔Accept and Like solutions to help future merchants.