Fetching user's available companies

Retrieve a list of companies available to an authenticated user using the availableCompanies GraphQL field, with optional filtering and sorting arguments.

The list of companies available to the authenticated user is available with a special field available under the Query type. This field is called availableCompanies. It is similar to the connection types seen so far, except that the pageInfo field is missing.

availableCompanies field

Here is a query example:

Query

{
  availableCompanies
  {
    totalCount
    items
    {
      name
      vismaNetCompanyId
      vismaNetCustomerId
    }
  }
}
Result

{
  "data": {
    "availableCompanies": {
      "totalCount": 2,
      "items": [
        {
          "name": "Marius Test AS",
          "vismaNetCompanyId": 5280...
          "vismaNetCustomerId": 9123...
        },
        {
          "name": "JAM&WAFFLES",
          "vismaNetCompanyId": 5199...
          "vismaNetCustomerId": 9456...
        }
      ]
    }
  }
}

The availableCompanies field has several optional arguments:

  • an argument called customerNo that indicates the Visma.net number of the customer for which available companies should be retrieved
  • an argument called first that indicates the number of elements to be fetched from the top of the companies list
  • an argument called last that indicates the number of elements to be fetched from the back of the companies list; if both first and last are present, first is used and last is ignored
  • an argument called sortOrder that defines the sorting order of the result

To fetch companies specific to a particular customer, pass its Visma.net identifier in the customerNo parameter, as shown in the following example:

Query

{
  availableCompanies(customerNo : 12345678)
  {
    totalCount
    items
    {
      name
      vismaNetCompanyId
    }
  }
}
Result

{
  "data": {
    "availableCompanies": {
      "totalCount": 2,
      "items": [
        {
          "name": "Marius Test AS",
          "vismaNetCompanyId": 5280...
        },
        {
          "name": "JAM&WAFFLES",
          "vismaNetCompanyId": 5199...
        }
      ]
    }
  }
}

If the customerNo parameter is missing, the companies available to all the available customers in the list are returned.

To retrieve the list of available customers see Fetching user’s available customers.

Service context

When you authenticate with client credentials (using a client ID and a client secret), fetching the list of available companies requires specifying a customer no (as described earlier).

You can find out the customer number in two ways:

To do the latter:

Visma.Net Admin Configuration

When then customer ID is not provided, an error is returned, as follows:

{
  "errors": [
    {
      "message": "GraphQL.ExecutionError: Could not fetch the list of available companies. Customer number is mandatory."
    }
  ],
  "data": {
    "availableCompanies": null
  },
  "extensions": {
    "vbnxt-trace-id": "..."
  }
}
Last modified September 24, 2024