Getting started with GraphQL queries

We will explore the schema shortly. However, to get started with the API and understand how easy it is to query data from Business NXT, we will look at several simple examples.

In the first example, we fetch the general ledger account numbers and names from the company with the ID 9112233. To access a company table you need a company context. To get one, you have to query from useCompany(no: ...).

Query

{  
  useCompany(no: 9112233)
  {
    # get general ledger accounts
    generalLedgerAccount
    {
      items
      {
        accountNo
        name
      }
    }
  }
}
Result

{
  "data": {
    "useCompany": {
      "generalLedgerAccount": {
        "items": [
          {
            "accountNo": 1000,
            "name": "Forskning og utvikling"
          },
          {
            "accountNo": 1020,
            "name": "Konsesjoner"
          },
          ...
        ]
      }
    }
  }
}

GraphQL allows you to combine multiple table queries in a single request. In the following example, we fetch both the general ledger accounts and the tax codes from the company with the ID 9112233.

Query

{  
  useCompany(no: 9112233)
  {
    # get general ledger accounts
    generalLedgerAccount
    {
      items
      {
        accountNo
        name
      }
    }

    # get tax codes
    taxCode 
    {
      items
      {
        taxCode
        description
      }
    }
  }
}
Result

{
  "data": {
    "useCompany": {
      "generalLedgerAccount": {
        "items": [
          {
            "accountNo": 1000,
            "name": "Forskning og utvikling"
          },
          {
            "accountNo": 1020,
            "name": "Konsesjoner"
          },
          ...
        ]
      },
      "taxCode": {
        "items": [
          {
            "taxCode": 1,
            "description": "Inngående MVA - høy sats"
          },
          {
            "taxCode": 3,
            "description": "Utgående MVA - høy sats"
          },
          ...
        ]
      }
    }
  }
}

In these examples we read data from company tables. But you can also perform operations on system tables. Such a table is Company that stores information about all the companies of a customer.

In the next example, we ask for the list of all the companies in the system, and, for each company, the companyNo and the name fields. To access a company table you need a customer context. To get one, you have to query from useCustomer(no: ...), as follows:

Query

{

# get all companies

  useCustomer(no: 1111111)
  {
    company
    {
      items
      {
        companyNo
        name
        companyBusinessNo
        vismaNetCompanyId
      }
    }
  }
}
Result

{
  "data": {
    "useCustomer" : {
      "company": {
        "items": [
          {
            "companyNo": 1,
            "name": "Visma Test AS"
            "companyBusinessNo": "91421001",
            "vismaNetCompanyId": 9112233
          },
          {
            "companyNo": 2,
            "name": "Visma Demo AS"
            "companyBusinessNo": "91421002",
            "vismaNetCompanyId": 9445566
          }
        ]
      }
    }
  }
}

With the Business NXT GraphQL API you can execute both queries to read data and mutations to create, update, and delete data, as the API is supporting the full range of CRUD operations (create, read, update, and delete). In addition, you are able to execute Business NXT specific operations such as processings, reports, and aggregates. All these operations will be detailed later in this tutorial.

Last modified September 24, 2024