# Company - admin-graphql - OBJECT Version: 2024-04 ## Description Represents information about a company which is also a customer of the shop. ### Access Scopes `read_customers` access scope or `read_companies` access scope. Also: The API client must be installed on a Shopify Plus store. ## Fields * [contactCount](/docs/api/admin-graphql/2024-04/scalars/Int): Int! - The number of contacts that belong to the company. * [contactsCount](/docs/api/admin-graphql/2024-04/objects/Count): Count - The number of contacts that belong to the company. * [createdAt](/docs/api/admin-graphql/2024-04/scalars/DateTime): DateTime! - The date and time ([ISO 8601 format](http://en.wikipedia.org/wiki/ISO_8601)) at which the company was created in Shopify. * [customerSince](/docs/api/admin-graphql/2024-04/scalars/DateTime): DateTime! - The date and time ([ISO 8601 format](http://en.wikipedia.org/wiki/ISO_8601)) at which the company became the customer. * [defaultCursor](/docs/api/admin-graphql/2024-04/scalars/String): String! - A default [cursor](https://shopify.dev/api/usage/pagination-graphql) that returns the single next record, sorted ascending by ID. * [defaultRole](/docs/api/admin-graphql/2024-04/objects/CompanyContactRole): CompanyContactRole - The role proposed by default for a contact at the company. * [externalId](/docs/api/admin-graphql/2024-04/scalars/String): String - A unique externally-supplied ID for the company. * [hasTimelineComment](/docs/api/admin-graphql/2024-04/scalars/Boolean): Boolean! - Whether the merchant added a timeline comment to the company. * [id](/docs/api/admin-graphql/2024-04/scalars/ID): ID! - A globally-unique ID. * [lifetimeDuration](/docs/api/admin-graphql/2024-04/scalars/String): String! - The lifetime duration of the company, since it became a customer of the shop. Examples: `2 days`, `3 months`, `1 year`. * [locationsCount](/docs/api/admin-graphql/2024-04/objects/Count): Count - The number of locations that belong to the company. * [mainContact](/docs/api/admin-graphql/2024-04/objects/CompanyContact): CompanyContact - The main contact for the company. * [metafield](/docs/api/admin-graphql/2024-04/objects/Metafield): Metafield - A [custom field](https://shopify.dev/docs/apps/build/custom-data), including its `namespace` and `key`, that's associated with a Shopify resource for the purposes of adding and storing additional information. * [name](/docs/api/admin-graphql/2024-04/scalars/String): String! - The name of the company. * [note](/docs/api/admin-graphql/2024-04/scalars/String): String - A note about the company. * [ordersCount](/docs/api/admin-graphql/2024-04/objects/Count): Count - The total number of orders placed for this company, across all its locations. * [privateMetafield](/docs/api/admin-graphql/2024-04/objects/PrivateMetafield): PrivateMetafield - Returns a private metafield by namespace and key that belongs to the resource. * [totalSpent](/docs/api/admin-graphql/2024-04/objects/MoneyV2): MoneyV2! - The total amount spent by this company, across all its locations. * [updatedAt](/docs/api/admin-graphql/2024-04/scalars/DateTime): DateTime! - The date and time ([ISO 8601 format](http://en.wikipedia.org/wiki/ISO_8601)) at which the company was last modified. ## Connections * [contactRoles](/docs/api/admin-graphql/2024-04/connections/CompanyContactRoleConnection): CompanyContactRoleConnection! * [contacts](/docs/api/admin-graphql/2024-04/connections/CompanyContactConnection): CompanyContactConnection! * [draftOrders](/docs/api/admin-graphql/2024-04/connections/DraftOrderConnection): DraftOrderConnection! * [events](/docs/api/admin-graphql/2024-04/connections/EventConnection): EventConnection! * [locations](/docs/api/admin-graphql/2024-04/connections/CompanyLocationConnection): CompanyLocationConnection! * [metafieldDefinitions](/docs/api/admin-graphql/2024-04/connections/MetafieldDefinitionConnection): MetafieldDefinitionConnection! * [metafields](/docs/api/admin-graphql/2024-04/connections/MetafieldConnection): MetafieldConnection! * [orders](/docs/api/admin-graphql/2024-04/connections/OrderConnection): OrderConnection! * [privateMetafields](/docs/api/admin-graphql/2024-04/connections/PrivateMetafieldConnection): PrivateMetafieldConnection! ## Related queries * [company](/docs/api/admin-graphql/2024-04/queries/company) Returns a `Company` object by ID. * [companies](/docs/api/admin-graphql/2024-04/queries/companies) Returns the list of companies in the shop. ## Related mutations * [companyAssignMainContact](/docs/api/admin-graphql/2024-04/mutations/companyAssignMainContact) Assigns the main contact for the company. * [companyCreate](/docs/api/admin-graphql/2024-04/mutations/companyCreate) Creates a company. * [companyRevokeMainContact](/docs/api/admin-graphql/2024-04/mutations/companyRevokeMainContact) Revokes the main contact from the company. * [companyUpdate](/docs/api/admin-graphql/2024-04/mutations/companyUpdate) Updates a company. ## Related Unions * [MetafieldReference](/docs/api/admin-graphql/2024-04/unions/MetafieldReference) The resource referenced by the metafield value. * [MetafieldReferencer](/docs/api/admin-graphql/2024-04/unions/MetafieldReferencer) Types of resources that may use metafields to reference other resources. ## Examples ### Get a company by its ID Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query { company(id: \\\"gid://shopify/Company/426793626\\\") { id name note externalId totalSpent { amount currencyCode } } }\"\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: `query {\n company(id: \"gid://shopify/Company/426793626\") {\n id\n name\n note\n externalId\n totalSpent {\n amount\n currencyCode\n }\n }\n }`,\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query {\n company(id: \"gid://shopify/Company/426793626\") {\n id\n name\n note\n externalId\n totalSpent {\n amount\n currencyCode\n }\n }\n }\nQUERY\n\nresponse = client.query(query: query)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query {\n company(id: \"gid://shopify/Company/426793626\") {\n id\n name\n note\n externalId\n totalSpent {\n amount\n currencyCode\n }\n }\n }`,\n);\n\nconst data = await response.json();\n" Graphql query: "query {\n company(id: \"gid://shopify/Company/426793626\") {\n id\n name\n note\n externalId\n totalSpent {\n amount\n currencyCode\n }\n }\n}" #### Graphql Input null #### Graphql Response { "data": { "company": { "id": "gid://shopify/Company/426793626", "name": "Fancy Pants Inc.", "note": "test notes", "externalId": "external_id1", "totalSpent": { "amount": "120.0", "currencyCode": "USD" } } } } ### Get a metafield attached to a company Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query CompanyMetafield($namespace: String!, $key: String!, $ownerId: ID!) { company(id: $ownerId) { industry: metafield(namespace: $namespace, key: $key) { value } } }\",\n \"variables\": {\n \"namespace\": \"my_fields\",\n \"key\": \"industry\",\n \"ownerId\": \"gid://shopify/Company/426793626\"\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `query CompanyMetafield($namespace: String!, $key: String!, $ownerId: ID!) {\n company(id: $ownerId) {\n industry: metafield(namespace: $namespace, key: $key) {\n value\n }\n }\n }`,\n \"variables\": {\n \"namespace\": \"my_fields\",\n \"key\": \"industry\",\n \"ownerId\": \"gid://shopify/Company/426793626\"\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query CompanyMetafield($namespace: String!, $key: String!, $ownerId: ID!) {\n company(id: $ownerId) {\n industry: metafield(namespace: $namespace, key: $key) {\n value\n }\n }\n }\nQUERY\n\nvariables = {\n \"namespace\": \"my_fields\",\n \"key\": \"industry\",\n \"ownerId\": \"gid://shopify/Company/426793626\"\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query CompanyMetafield($namespace: String!, $key: String!, $ownerId: ID!) {\n company(id: $ownerId) {\n industry: metafield(namespace: $namespace, key: $key) {\n value\n }\n }\n }`,\n {\n variables: {\n \"namespace\": \"my_fields\",\n \"key\": \"industry\",\n \"ownerId\": \"gid://shopify/Company/426793626\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "query CompanyMetafield($namespace: String!, $key: String!, $ownerId: ID!) {\n company(id: $ownerId) {\n industry: metafield(namespace: $namespace, key: $key) {\n value\n }\n }\n}" #### Graphql Input { "namespace": "my_fields", "key": "industry", "ownerId": "gid://shopify/Company/426793626" } #### Graphql Response { "data": { "company": { "industry": { "value": "retail" } } } } ### Get metafields attached to a company Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query CompanyMetafields($ownerId: ID!) { company(id: $ownerId) { metafields(first: 3) { edges { node { namespace key value } } } } }\",\n \"variables\": {\n \"ownerId\": \"gid://shopify/Company/426793626\"\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `query CompanyMetafields($ownerId: ID!) {\n company(id: $ownerId) {\n metafields(first: 3) {\n edges {\n node {\n namespace\n key\n value\n }\n }\n }\n }\n }`,\n \"variables\": {\n \"ownerId\": \"gid://shopify/Company/426793626\"\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query CompanyMetafields($ownerId: ID!) {\n company(id: $ownerId) {\n metafields(first: 3) {\n edges {\n node {\n namespace\n key\n value\n }\n }\n }\n }\n }\nQUERY\n\nvariables = {\n \"ownerId\": \"gid://shopify/Company/426793626\"\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query CompanyMetafields($ownerId: ID!) {\n company(id: $ownerId) {\n metafields(first: 3) {\n edges {\n node {\n namespace\n key\n value\n }\n }\n }\n }\n }`,\n {\n variables: {\n \"ownerId\": \"gid://shopify/Company/426793626\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "query CompanyMetafields($ownerId: ID!) {\n company(id: $ownerId) {\n metafields(first: 3) {\n edges {\n node {\n namespace\n key\n value\n }\n }\n }\n }\n}" #### Graphql Input { "ownerId": "gid://shopify/Company/426793626" } #### Graphql Response { "data": { "company": { "metafields": { "edges": [ { "node": { "namespace": "my_fields", "key": "industry", "value": "retail" } } ] } } } } ### Get pinned metafield definitions associated with a company Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"query CompanyMetafieldDefinitions($ownerId: ID!, $first: Int, $pinnedStatus: MetafieldDefinitionPinnedStatus, $sortKey: MetafieldDefinitionSortKeys) { company(id: $ownerId) { metafieldDefinitions(first: $first, pinnedStatus: $pinnedStatus, sortKey: $sortKey) { edges { node { name namespace key type { name } } } } } }\",\n \"variables\": {\n \"pinnedStatus\": \"PINNED\",\n \"ownerId\": \"gid://shopify/Company/426793626\",\n \"first\": 10,\n \"sortKey\": \"PINNED_POSITION\"\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `query CompanyMetafieldDefinitions($ownerId: ID!, $first: Int, $pinnedStatus: MetafieldDefinitionPinnedStatus, $sortKey: MetafieldDefinitionSortKeys) {\n company(id: $ownerId) {\n metafieldDefinitions(first: $first, pinnedStatus: $pinnedStatus, sortKey: $sortKey) {\n edges {\n node {\n name\n namespace\n key\n type {\n name\n }\n }\n }\n }\n }\n }`,\n \"variables\": {\n \"pinnedStatus\": \"PINNED\",\n \"ownerId\": \"gid://shopify/Company/426793626\",\n \"first\": 10,\n \"sortKey\": \"PINNED_POSITION\"\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n query CompanyMetafieldDefinitions($ownerId: ID!, $first: Int, $pinnedStatus: MetafieldDefinitionPinnedStatus, $sortKey: MetafieldDefinitionSortKeys) {\n company(id: $ownerId) {\n metafieldDefinitions(first: $first, pinnedStatus: $pinnedStatus, sortKey: $sortKey) {\n edges {\n node {\n name\n namespace\n key\n type {\n name\n }\n }\n }\n }\n }\n }\nQUERY\n\nvariables = {\n \"pinnedStatus\": \"PINNED\",\n \"ownerId\": \"gid://shopify/Company/426793626\",\n \"first\": 10,\n \"sortKey\": \"PINNED_POSITION\"\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n query CompanyMetafieldDefinitions($ownerId: ID!, $first: Int, $pinnedStatus: MetafieldDefinitionPinnedStatus, $sortKey: MetafieldDefinitionSortKeys) {\n company(id: $ownerId) {\n metafieldDefinitions(first: $first, pinnedStatus: $pinnedStatus, sortKey: $sortKey) {\n edges {\n node {\n name\n namespace\n key\n type {\n name\n }\n }\n }\n }\n }\n }`,\n {\n variables: {\n \"pinnedStatus\": \"PINNED\",\n \"ownerId\": \"gid://shopify/Company/426793626\",\n \"first\": 10,\n \"sortKey\": \"PINNED_POSITION\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "query CompanyMetafieldDefinitions($ownerId: ID!, $first: Int, $pinnedStatus: MetafieldDefinitionPinnedStatus, $sortKey: MetafieldDefinitionSortKeys) {\n company(id: $ownerId) {\n metafieldDefinitions(first: $first, pinnedStatus: $pinnedStatus, sortKey: $sortKey) {\n edges {\n node {\n name\n namespace\n key\n type {\n name\n }\n }\n }\n }\n }\n}" #### Graphql Input { "pinnedStatus": "PINNED", "ownerId": "gid://shopify/Company/426793626", "first": 10, "sortKey": "PINNED_POSITION" } #### Graphql Response { "data": { "company": { "metafieldDefinitions": { "edges": [ { "node": { "name": "Website", "namespace": "my_fields", "key": "website", "type": { "name": "single_line_text_field" } } }, { "node": { "name": "Industry", "namespace": "my_fields", "key": "industry", "type": { "name": "single_line_text_field" } } } ] } } } }