Requires write_customers access scope or write_companies access scope. Also: The API client must be installed on a Shopify Plus store.

Creates a company.


The fields to use when creating the company.


Was this section helpful?

The created company.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation CompanyCreate($input: CompanyCreateInput!) {
  companyCreate(input: $input) {
    company {
      id
      name
      externalId
      mainContact {
        id
        customer {
          id
          email
          firstName
          lastName
        }
      }
      contacts(first: 5) {
        edges {
          node {
            id
            customer {
              email
              firstName
              lastName
            }
          }
        }
      }
      contactRoles(first: 5) {
        edges {
          node {
            id
            name
          }
        }
      }
      locations(first: 5) {
        edges {
          node {
            id
            name
            shippingAddress {
              firstName
              lastName
              address1
              city
              province
              zip
              country
            }
          }
        }
      }
    }
    userErrors {
      field
      message
      code
    }
  }
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CompanyCreate($input: CompanyCreateInput!) { companyCreate(input: $input) { company { id name externalId mainContact { id customer { id email firstName lastName } } contacts(first: 5) { edges { node { id customer { email firstName lastName } } } } contactRoles(first: 5) { edges { node { id name } } } locations(first: 5) { edges { node { id name shippingAddress { firstName lastName address1 city province zip country } } } } } userErrors { field message code } } }",
 "variables": {
    "input": {
      "company": {
        "name": "Postal Cards Inc",
        "externalId": "01456606-0001"
      },
      "companyLocation": {
        "name": "Ottawa Postal Cards",
        "shippingAddress": {
          "firstName": "Avery",
          "lastName": "Brown",
          "address1": "150 Elgin Street",
          "address2": "8th Floor",
          "city": "Ottawa",
          "zoneCode": "ON",
          "zip": "K2P 1L4",
          "countryCode": "CA"
        },
        "billingSameAsShipping": true
      },
      "companyContact": {
        "email": "avery.brown@example.com",
        "firstName": "Avery",
        "lastName": "Brown"
      }
    }
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation CompanyCreate($input: CompanyCreateInput!) {
    companyCreate(input: $input) {
      company {
        id
        name
        externalId
        mainContact {
          id
          customer {
            id
            email
            firstName
            lastName
          }
        }
        contacts(first: 5) {
          edges {
            node {
              id
              customer {
                email
                firstName
                lastName
              }
            }
          }
        }
        contactRoles(first: 5) {
          edges {
            node {
              id
              name
            }
          }
        }
        locations(first: 5) {
          edges {
            node {
              id
              name
              shippingAddress {
                firstName
                lastName
                address1
                city
                province
                zip
                country
              }
            }
          }
        }
      }
      userErrors {
        field
        message
        code
      }
    }
  }`,
  {
    variables: {
      "input": {
        "company": {
          "name": "Postal Cards Inc",
          "externalId": "01456606-0001"
        },
        "companyLocation": {
          "name": "Ottawa Postal Cards",
          "shippingAddress": {
            "firstName": "Avery",
            "lastName": "Brown",
            "address1": "150 Elgin Street",
            "address2": "8th Floor",
            "city": "Ottawa",
            "zoneCode": "ON",
            "zip": "K2P 1L4",
            "countryCode": "CA"
          },
          "billingSameAsShipping": true
        },
        "companyContact": {
          "email": "avery.brown@example.com",
          "firstName": "Avery",
          "lastName": "Brown"
        }
      }
    },
  },
);

const data = await response.json();
session = ShopifyAPI::Auth::Session.new(
  shop: "your-development-store.myshopify.com",
  access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
  session: session
)

query = <<~QUERY
  mutation CompanyCreate($input: CompanyCreateInput!) {
    companyCreate(input: $input) {
      company {
        id
        name
        externalId
        mainContact {
          id
          customer {
            id
            email
            firstName
            lastName
          }
        }
        contacts(first: 5) {
          edges {
            node {
              id
              customer {
                email
                firstName
                lastName
              }
            }
          }
        }
        contactRoles(first: 5) {
          edges {
            node {
              id
              name
            }
          }
        }
        locations(first: 5) {
          edges {
            node {
              id
              name
              shippingAddress {
                firstName
                lastName
                address1
                city
                province
                zip
                country
              }
            }
          }
        }
      }
      userErrors {
        field
        message
        code
      }
    }
  }
QUERY

variables = {
  "input": {
    "company": {
      "name": "Postal Cards Inc",
      "externalId": "01456606-0001"
    },
    "companyLocation": {
      "name": "Ottawa Postal Cards",
      "shippingAddress": {
        "firstName": "Avery",
        "lastName": "Brown",
        "address1": "150 Elgin Street",
        "address2": "8th Floor",
        "city": "Ottawa",
        "zoneCode": "ON",
        "zip": "K2P 1L4",
        "countryCode": "CA"
      },
      "billingSameAsShipping": true
    },
    "companyContact": {
      "email": "avery.brown@example.com",
      "firstName": "Avery",
      "lastName": "Brown"
    }
  }
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation CompanyCreate($input: CompanyCreateInput!) {
      companyCreate(input: $input) {
        company {
          id
          name
          externalId
          mainContact {
            id
            customer {
              id
              email
              firstName
              lastName
            }
          }
          contacts(first: 5) {
            edges {
              node {
                id
                customer {
                  email
                  firstName
                  lastName
                }
              }
            }
          }
          contactRoles(first: 5) {
            edges {
              node {
                id
                name
              }
            }
          }
          locations(first: 5) {
            edges {
              node {
                id
                name
                shippingAddress {
                  firstName
                  lastName
                  address1
                  city
                  province
                  zip
                  country
                }
              }
            }
          }
        }
        userErrors {
          field
          message
          code
        }
      }
    }`,
    "variables": {
      "input": {
        "company": {
          "name": "Postal Cards Inc",
          "externalId": "01456606-0001"
        },
        "companyLocation": {
          "name": "Ottawa Postal Cards",
          "shippingAddress": {
            "firstName": "Avery",
            "lastName": "Brown",
            "address1": "150 Elgin Street",
            "address2": "8th Floor",
            "city": "Ottawa",
            "zoneCode": "ON",
            "zip": "K2P 1L4",
            "countryCode": "CA"
          },
          "billingSameAsShipping": true
        },
        "companyContact": {
          "email": "avery.brown@example.com",
          "firstName": "Avery",
          "lastName": "Brown"
        }
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation CompanyCreate($input: CompanyCreateInput!) {
    companyCreate(input: $input) {
      company {
        id
        name
        externalId
        mainContact {
          id
          customer {
            id
            email
            firstName
            lastName
          }
        }
        contacts(first: 5) {
          edges {
            node {
              id
              customer {
                email
                firstName
                lastName
              }
            }
          }
        }
        contactRoles(first: 5) {
          edges {
            node {
              id
              name
            }
          }
        }
        locations(first: 5) {
          edges {
            node {
              id
              name
              shippingAddress {
                firstName
                lastName
                address1
                city
                province
                zip
                country
              }
            }
          }
        }
      }
      userErrors {
        field
        message
        code
      }
    }
  }
QUERY;

$variables = [
  "input" => [
    "company" => [
      "name" => "Postal Cards Inc",
      "externalId" => "01456606-0001",
    ],
    "companyLocation" => [
      "name" => "Ottawa Postal Cards",
      "shippingAddress" => [
        "firstName" => "Avery",
        "lastName" => "Brown",
        "address1" => "150 Elgin Street",
        "address2" => "8th Floor",
        "city" => "Ottawa",
        "zoneCode" => "ON",
        "zip" => "K2P 1L4",
        "countryCode" => "CA",
      ],
      "billingSameAsShipping" => true,
    ],
    "companyContact" => [
      "email" => "avery.brown@example.com",
      "firstName" => "Avery",
      "lastName" => "Brown",
    ],
  ],
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "input": {
    "company": {
      "name": "Postal Cards Inc",
      "externalId": "01456606-0001"
    },
    "companyLocation": {
      "name": "Ottawa Postal Cards",
      "shippingAddress": {
        "firstName": "Avery",
        "lastName": "Brown",
        "address1": "150 Elgin Street",
        "address2": "8th Floor",
        "city": "Ottawa",
        "zoneCode": "ON",
        "zip": "K2P 1L4",
        "countryCode": "CA"
      },
      "billingSameAsShipping": true
    },
    "companyContact": {
      "email": "avery.brown@example.com",
      "firstName": "Avery",
      "lastName": "Brown"
    }
  }
}
Hide code
Response
JSON
{
  "companyCreate": {
    "company": {
      "id": "gid://shopify/Company/1059559575",
      "name": "Postal Cards Inc",
      "externalId": "01456606-0001",
      "mainContact": {
        "id": "gid://shopify/CompanyContact/1059341835",
        "customer": {
          "id": "gid://shopify/Customer/1073339466",
          "email": "avery.brown@example.com",
          "firstName": "Avery",
          "lastName": "Brown"
        }
      },
      "contacts": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/CompanyContact/1059341835",
              "customer": {
                "email": "avery.brown@example.com",
                "firstName": "Avery",
                "lastName": "Brown"
              }
            }
          }
        ]
      },
      "contactRoles": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/CompanyContactRole/1007033458",
              "name": "Location admin"
            }
          },
          {
            "node": {
              "id": "gid://shopify/CompanyContactRole/1007033459",
              "name": "Ordering only"
            }
          }
        ]
      },
      "locations": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/CompanyLocation/966871284",
              "name": "Ottawa Postal Cards",
              "shippingAddress": {
                "firstName": "Avery",
                "lastName": "Brown",
                "address1": "150 Elgin Street",
                "city": "Ottawa",
                "province": "Ontario",
                "zip": "K2P 1L4",
                "country": "Canada"
              }
            }
          }
        ]
      }
    },
    "userErrors": []
  }
}