data-src=../../../../../includes/commerce-only.md

company query

The company query returns details about the user's company. The request must include the customer token of a company user.

A company structure can contain multiple levels of teams, with company users assigned at each level. To query on a company structure, specify fragments on the Customer and CompanyTeam objects. The application returns a union of these objects. Specify the __typename attribute to distinguish the object types in the response.

The CompanyCredit output object contains the company's available_credit and outstanding_balance values. These values cannot be changed with a mutation. The available_credit amount is the sum of the credit limit and the outstanding balance. If the company has exceeded the credit limit, the amount is as a negative value. The outstanding_balance amount is the amount reimbursed, less the total due from all orders placed using the Payment on Account payment method. The amount can be a positive or negative value.

This query requires a valid customer authentication token.

Syntax

{company: {Company}}

Reference

The company reference provides detailed information about the types and fields defined in this query.

Example usage

Return information about a newly-created company

The following call returns basic information about the customer's company.

Request:

query{
  company{
    company_admin {
      firstname
      lastname
      email
    }
    email
    id
    legal_address {
      street
       city
      region {
        region_id
        region_code
      }
      postcode
      country_code
      telephone
    }
    legal_name
    name
  }
}

Response:

{
  "data": {
    "company": {
      "company_admin": {
        "firstname": "Taina",
        "lastname": "Garofalo",
        "email": "tgarofalo@example.com"
      },
      "email": "tgarofalo@example.com",
      "id": "MQ==",
      "legal_address": {
        "street": [
          "265 Cambridge Ave"
        ],
        "city": "Palo Alto",
        "region": {
          "region_id": 12,
          "region_code": "CA"
        },
        "postcode": "94306",
        "country_code": "US",
        "telephone": "555 867-5309"
      },
      "legal_name": "TestCo Inc.",
      "name": "TestCo"
    }
  }
}

Return the company structure

The following query returns the customer's company structure.

<!--- To do: Replace the response after creating a proper structure and add a tree depicting the structure -->

Request:

query{
  company{
    id
    name
    structure{
      items {
        entity {
          __typename
          ... on Customer {
            firstname
            lastname
            email
            id  
          }
          ... on CompanyTeam {
            name
            description
            id
          }
        }
      }
    }
  }
}

Response:

{
  "data": {
    "company": {
      "id": "Ng==",
      "name": "TestCo2",
      "structure": {
        "items": [
          {
            "entity": {
              "__typename": "Customer",
              "firstname": "Taina",
              "lastname": "Garofalo",
              "email": "donadmin@example.com",
              "id": "Ng=="
            }
          },
          {
            "entity": {
              "__typename": "CompanyTeam",
              "name": "Y Team",
              "description": "Y Team description",
              "id": "Ng=="
            }
          },
          {
            "entity": {
              "__typename": "Customer",
              "firstname": "B",
              "lastname": "BB",
              "email": "bbb@example.com",
              "id": "Nw=="
            }
          },
          {
            "entity": {
              "__typename": "CompanyTeam",
              "name": "X team",
              "description": "X team description",
              "id": "Nw=="
            }
          },
          {
            "entity": {
              "__typename": "Customer",
              "firstname": "A",
              "lastname": "AA",
              "email": "aa@example.com",
              "id": "NQ=="
            }
          },
          {
            "entity": {
              "__typename": "CompanyTeam",
              "name": "Z Team",
              "description": "Z team description",
              "id": "NQ=="
            }
          },
          {
            "entity": {
              "__typename": "Customer",
              "firstname": "C",
              "lastname": "CC",
              "email": "ccc@example.com",
              "id": "NQ=="
            }
          }
        ]
      }
    }
  }
}

Return the company credit history

The following query returns a company's current company credit balance as well as a record of all company credit events.

Request:

query{
  company{
    name
    id
    credit {
      available_credit {
        value
        currency
      }
      credit_limit {
        value
        currency
      }
      outstanding_balance {
        value
        currency
      }
    }
    credit_history{
      items {
        date
        type
        amount {
          value
          currency
        }
        balance {
          outstanding_balance {
            value
            currency
          }
          available_credit {
            value
            currency
          }
          credit_limit {
            value
            currency
          }
        }
      }
    }

    payment_methods

  }
}

Response:

{
  "data": {
    "company": {
      "name": "TestCo",
      "id": "MQ==",
      "credit": {
        "available_credit": {
          "value": 436,
          "currency": "USD"
        },
        "credit_limit": {
          "value": 500,
          "currency": "USD"
        },
        "outstanding_balance": {
          "value": -64,
          "currency": "USD"
        }
      },
      "credit_history": {
        "items": [
          {
            "date": "2020-12-02 16:38:11",
            "type": "ALLOCATION",
            "amount": {
              "value": 0,
              "currency": "USD"
            },
            "balance": {
              "outstanding_balance": {
                "value": 0,
                "currency": "USD"
              },
              "available_credit": {
                "value": 500,
                "currency": "USD"
              },
              "credit_limit": {
                "value": 500,
                "currency": "USD"
              }
            }
          },
          {
            "date": "2020-12-02 17:05:12",
            "type": "PURCHASE",
            "amount": {
              "value": -192,
              "currency": "USD"
            },
            "balance": {
              "outstanding_balance": {
                "value": -192,
                "currency": "USD"
              },
              "available_credit": {
                "value": 308,
                "currency": "USD"
              },
              "credit_limit": {
                "value": 500,
                "currency": "USD"
              }
            }
          },
          {
            "date": "2020-12-02 17:27:57",
            "type": "PURCHASE",
            "amount": {
              "value": -64,
              "currency": "USD"
            },
            "balance": {
              "outstanding_balance": {
                "value": -256,
                "currency": "USD"
              },
              "available_credit": {
                "value": 244,
                "currency": "USD"
              },
              "credit_limit": {
                "value": 500,
                "currency": "USD"
              }
            }
          },
          {
            "date": "2020-12-02 17:35:47",
            "type": "REIMBURSEMENT",
            "amount": {
              "value": 192,
              "currency": "USD"
            },
            "balance": {
              "outstanding_balance": {
                "value": -64,
                "currency": "USD"
              },
              "available_credit": {
                "value": 436,
                "currency": "USD"
              },
              "credit_limit": {
                "value": 500,
                "currency": "USD"
              }
            }
          }
        ]
      },
      "payment_methods": []
    }
  }
}

Return the company addresses and config

The following query returns a list of company's addresses and a config object related to addresses.

Request:

query{
  company{
    id
      config {
          address_book_enabled
          address_book_custom_shipping_address_enabled
      }
      addresses(pageSize: 20, currentPage: 1) {
          total_count
          page_info {
              page_size
              current_page
              total_pages
          }
          items {
              id
              nickname
              company_id
              address_type
              is_default
              firstname
              lastname
              company
              street
              city
              country_code
              region_id
              region {
                  region_id
                  region
                  region_code
              }
              postcode
              telephone
              fax
              vat_id
              custom_attributes {
                  code
                  ... on AttributeValue {
                      value
                  }
              }
          }
      }
  }
}

Response:

{
  "data": {
    "company": {
      "config": {
        "address_book_enabled": true,
        "address_book_custom_shipping_address_enabled": true
      },
      "addresses": {
        "total_count": 2,
        "page_info": {
          "page_size": 20,
          "current_page": 1,
          "total_pages": 1
        },
        "items": [
          {
            "id": "MTI=",
            "nickname": "HQ Billing",
            "company_id": "Mw==",
            "address_type": "BILLING",
            "is_default": true,
            "firstname": "John",
            "lastname": "Doe",
            "company": "Acme Corp",
            "street": ["123 Main St"],
            "city": "Austin",
            "country_code": "US",
            "region_id": 57,
            "region": {
              "region_id": 57,
              "region": "Texas",
              "region_code": "TX"
            },
            "postcode": "78701",
            "telephone": "5551234567",
            "fax": null,
            "vat_id": "US123456789",
            "custom_attributes": []
          },
          {
            "id": "MTM=",
            "nickname": "Warehouse",
            "company_id": "Mw==",
            "address_type": "SHIPPING",
            "is_default": false,
            "firstname": "Jane",
            "lastname": "Smith",
            "company": "Acme Corp",
            "street": ["456 Oak Ave"],
            "city": "Dallas",
            "country_code": "US",
            "region_id": 57,
            "region": {
              "region_id": 57,
              "region": "Texas",
              "region_code": "TX"
            },
            "postcode": "75201",
            "telephone": "5559876543",
            "fax": null,
            "vat_id": null,
            "custom_attributes": []
          }
        ]
      }
    }
  }
}