Table of Contents

Query

How to use our query endpoint

The query section of the Delivery API provides access to an endpoint that delivers search results from a specific query that has been configured.

The QueryName parameter and the RepositoryName parameter are used in conjunction to search the given repository for results:

  • QueryName: The name of the predefined query as described above - e.g. Users
  • RepositoryName: The name of the repository or source index from which to retrieve the data - e.g. SecondaryUsers
  • Example: GET <yourhost>/dwapi/query?QueryName=Users&RepositoryName=Secondary%20users

The parameters defined in the query can be used as additional parameters on the endpoint to further filter the search results. The available parameters are returned as an array at the end of the response body.

As an example, the query Users has a parameter called UserName, allowing us to search the SecondaryUsers repository for users with a particular username: GET <yourhost>/dwapi/query?QueryName=Users&RepositoryName=SecondaryUsers&UserName=test1

Important

Please note that in a headless setup, macros are not available as they depend on a frontend context to run. Instead set a parameter and call it as a custom parameter.

Results from the GET /dwapi/query endpoint

The return of this endpoint is a QueryResultViewModel which contains information about the result count and pagination, the search results themselves, and the available parameters:

{
  "pageSize": 10,
  "pageCount": 1,
  "currentPage": 1,
  "totalCount": 1,
  "spellCheckerSuggestions": [],
  "results": [
    {
      "_score": 0,
      "AutoUpdateID": "1229",
      "UserID": 1229,
      "UserName": "test1",
      "UserPassword": "password",
      "Name": "test365",
      "UserEmail": "test@dk.com",
      "IsAdmin": false,
      "Type": 5,
      "ValidFrom": "2024-06-10T10:08:31.227",
      "ValidTo": "2999-12-31T23:59:59",
      "Address": "test 10",
      "Zip": "8250",
      "City": "Aarhus",
      "Active": true,
      "AllowBackend": false,
      "GeolocationLatitude": 0,
      "GeolocationLongitude": 0,
      "UserEmailAllowed": false,
      "CreatedOn": "2024-06-10T10:08:31.23",
      "UpdatedOn": "2024-06-10T10:08:31.23",
      "CreatedBy": -1,
      "UpdatedBy": -1,
      "EmailPermissionUpdatedOn": "2024-06-10T10:08:31.23",
      "StockLocationID": 0,
      "CountryCode": "DK",
      "CombinedOrderTotals": 954.27,
      "LargestOrderPrice": 954.27,
      "OrderCountForLast30Days": 0,
      "BoughtProducts": [
        "6110867155M"
      ],
      "Groups": [
          4
      ],
      "GroupNames": [
        "Accounts"
      ],
      "CanImpersonate": [
        2,
        187
      ],
      "CanBeImpersonatedBy": [
        2
      ],
      "SearchField": "1229 test@dk.com test365 test@dk.com"
    }
  ],
  "facetGroups": [],
  "parameters": [
    {
      "name": "UserName",
      "defaultValue": "",
      "value": [
        "test1"
      ],
      "isHandledAsFacet": false,
      "typeName": "System.String"
    }
  ]
}
    

Paging and sorting

There are a number of parameters available to limit and/or sort the results:

  • To limit the number of results returned, set a value in the PageSize parameter
  • CurrentPage allows you to determine which page of a result set is returned. For example, if there are 20 results in total, PageSize is 5 and CurrentPage is 2, result items 6 to 10 will be returned
  • The SortBy parameter allows you to sort the results by a specific field. For example, ID will sort the results in order of their ID number (if applicable)
  • Results are sorted in ascending order by default. To change the sort direction to descending, use the SortOrder parameter with the value DESC

Example endpoint: GET /dwapi/query?QueryName=Users&RepositoryName=SecondaryUsers&SortBy=UserID&PageSize=2&CurrentPage=3

{
  "pageSize": 2,
  "pageCount": 8,
  "currentPage": 3,
  "totalCount": 16,
  "spellCheckerSuggestions": [],
  "results": [
    {
      "_score": 0,
      "AutoUpdateID": "2",
      "UserID": 2,
      "ParentID": 1,
      "UserName": "Test1",
      "UserPassword": "password1",
      "Name": "Test Order",
      "IsAdmin": true,
      "Type": 1,
      "ValidFrom": "2016-10-31T15:03:00",
      "ValidTo": "2100-01-01T00:00:00",
      "Address": "test 13",
      "Zip": "8250",
      "City": "Aarhus",
      "Active": true,
      "AllowBackend": true,
      "GeolocationLatitude": 0,
      "GeolocationLongitude": 0,
      "UserEmailAllowed": false,
      "UpdatedOn": "2024-08-07T08:48:40.783",
      "CreatedBy": 0,
      "UpdatedBy": -1,
      "StockLocationID": 0,
      "CountryCode": "DK",
      "CombinedOrderTotals": 11.86,
      "LargestOrderPrice": 11.86,
      "OrderCountForLast30Days": 0,
      "BoughtProducts": [
        "10063"
      ],
      "Groups": [
        4
      ],
      "GroupNames": [
        "Accounts"
      ],
      "CanImpersonate": [
        4,
      ],
      "CanBeImpersonatedBy": [
        4,
      ],
      "SearchField": "2 Test1 Test Order"
    },
    {
      "_score": 0,
      "AutoUpdateID": "3",
      "UserID": 3,
      "ParentID": 0,
      "UserName": "Test2",
      "UserPassword": "password2",
      "Name": "Test",
      "IsAdmin": true,
      "Type": 3,
      "ValidFrom": "2016-10-31T15:03:00",
      "ValidTo": "2100-01-01T00:00:00",
      "Active": true,
      "AllowBackend": true,
      "GeolocationLatitude": 0,
      "GeolocationLongitude": 0,
      "UserEmailAllowed": false,
      "UpdatedOn": "2022-05-05T15:08:52.78",
      "CreatedBy": 0,
      "UpdatedBy": 1,
      "StockLocationID": 0,
      "SearchField": "3 Admin Admin"
    }
  ],
  "facetGroups": [],
  "parameters": [
    {
      "name": "UserName",
      "defaultValue": "",
      "value": null,
      "isHandledAsFacet": false,
      "typeName": "System.String"
    }
  ]
}

Facet Groups

If the query has facet group(s) associated with it, the FacetGroupNames parameter can be used to see what facets are available within the facet group, providing information about each facet, its options, and the number of items associated with that facet.

Example endpoint: GET <yourhost>/dwapi/query?QueryName=User&RepositoryName=SecondaryUsers&FacetGroupNames=UserGroups

{
  "pageSize": 1,
  "pageCount": 16,
  "currentPage": 1,
  "totalCount": 16,
  "spellCheckerSuggestions": [],
  "results": [
    {
      "AutoUpdateID": "2",
      "UserID": 2,
      "ParentID": 1,
      "UserName": "Test",
      "UserPassword": "password",
      "Name": "Test Order",
      "IsAdmin": true,
      "Type": 1,
      "ValidFrom": "2016-10-31T15:03:00",
      "ValidTo": "2100-01-01T00:00:00",
      "Address": "test 13",
      "Zip": "8250",
      "City": "Aarhus",
      "Active": true,
      "AllowBackend": true,
      "GeolocationLatitude": 0,
      "GeolocationLongitude": 0,
      "UserEmailAllowed": false,
      "UpdatedOn": "2024-08-07T08:48:40.783",
      "CreatedBy": 0,
      "UpdatedBy": -1,
      "StockLocationID": 0,
      "CountryCode": "DK",
      "CombinedOrderTotals": 11.86,
      "LargestOrderPrice": 11.86,
      "OrderCountForLast30Days": 0,
      "BoughtProducts": [
        "10063"
      ],
      "Groups": [
        4
      ],
      "GroupNames": [
        "Accounts"
      ],
      "CanImpersonate": [
        4,
      ],
      "CanBeImpersonatedBy": [
        4,
      ],
      "SearchField": "2 Administrator Test Order"
    }
  ],
  "facetGroups": [
    {
      "name": "UserGroups",
      "description": null,
      "facets": [
        {
          "name": "Groups",
          "queryParameter": "Groups",
          "queryParameterType": "System.String",
          "queryParameterDefaultValue": "",
          "renderType": "Select",
          "field": "GroupNames",
          "type": "Field",
          "value": "",
          "facetOptions": [
            {
              "name": "Accounts",
              "label": "Accounts",
              "value": "Accounts",
              "sort": 0,
              "selected": false,
              "count": 5
            },
            {
              "name": "Find dealers",
              "label": "Find dealers",
              "value": "Find dealers",
              "sort": 0,
              "selected": false,
              "count": 5
            },
            {
              "name": "Logins",
              "label": "Logins",
              "value": "Logins",
              "sort": 0,
              "selected": false,
              "count": 3
            },
            {
              "name": "Roles",
              "label": "Roles",
              "value": "Roles",
              "sort": 0,
              "selected": false,
              "count": 2
            },
            {
              "name": "Test",
              "label": "Test",
              "value": "Test",
              "sort": 0,
              "selected": false,
              "count": 2
            },
            {
              "name": "Account managers",
              "label": "Account managers",
              "value": "Account managers",
              "sort": 0,
              "selected": false,
              "count": 1
            }
          ],
          "optionCount": 6,
          "minimumValue": 0,
          "maximumValue": 0,
          "optionWithResultCount": 6,
          "optionResultTotalCount": 18
        }
      ]
    }
  ],
  "parameters": [
    {
      "name": "UserName",
      "defaultValue": "",
      "value": null,
      "isHandledAsFacet": false,
      "typeName": "System.String"
    },
    {
      "name": "Groups",
      "defaultValue": "",
      "value": null,
      "isHandledAsFacet": true,
      "typeName": "System.String"
    }
  ]
}
To top