> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# QuerySections

# Package: onlinePrograms

# Namespace: SectionsService

# Method link: https://dev.wix.com/docs/api-reference/business-management/online-programs/sections/query-sections.md

## Permission Scopes:
Manage Online Programs: SCOPE.CHALLENGES.MANAGE

## Introduction

Retrieves a list of up to 1,000 sections, given the provided paging, filtering, and sorting.

Use this method when you need to filter sections, apply custom sorting or paging, or query across programs.
When you know the program ID and need all sections in program order, call [List Sections](https://dev.wix.com/docs/api-reference/business-management/online-programs/sections/list-sections.md).

Query Sections runs with these defaults, which you can override:

- `createdDate` is sorted in `DESC` order.
- `paging.limit` is `1000`.
- `paging.offset` is `0`.

Supported filter fields are `programId`, `id`, and `delayInDays`.
Supported sorting fields are `id`, `delayInDays`, `createdDate`, and `ordering`. When sorting by a field other than `programId`, also filter by `programId`.
Section extended fields aren't supported for filtering or sorting. Queries that reference them are rejected.

To learn about working with Query methods, see [API Query Language](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-the-wix-api-query-language.md), [Sorting and Paging](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-sorting-and-paging.md), and [Field Projection](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-field-projection.md).

---

## REST API

### Schema

```
 Method: querySections
 Description: Retrieves a list of up to 1,000 sections, given the provided paging, filtering, and sorting.  Use this method when you need to filter sections, apply custom sorting or paging, or query across programs. When you know the program GUID and need all sections in program order, call [List Sections](https://dev.wix.com/docs/api-reference/business-management/online-programs/sections/list-sections.md).  Query Sections runs with these defaults, which you can override:  - `createdDate` is sorted in `DESC` order. - `paging.limit` is `1000`. - `paging.offset` is `0`.  Supported filter fields are `programId`, `id`, and `delayInDays`. Supported sorting fields are `id`, `delayInDays`, `createdDate`, and `ordering`. When sorting by a field other than `programId`, also filter by `programId`. Section extended fields aren't supported for filtering or sorting. Queries that reference them are rejected.  To learn about working with Query methods, see [API Query Language](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-the-wix-api-query-language.md), [Sorting and Paging](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-sorting-and-paging.md), and [Field Projection](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-field-projection.md).
 URL: https://www.wixapis.com/online-programs/v3/sections/query
 Method: POST
 Method parameters:
   param name: query | type: CursorQuery    
     - name: cursorPaging | type: CursorPaging | description: Cursor paging options.  Learn more about [cursor paging](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#cursor-paging).  
        - name: limit | type: integer | description: Maximum number of items to return in the results.  | validation: minimum 0, maximum 100, format int32
        - name: cursor | type: string | description: Pointer to the next or previous page in the list of results.  Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request.  | validation: maxLength 16000
        - name: filter | type: object | description: Filter object.  Learn more about [filtering](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#filters).  
        - name: sort | type: array<Sorting> | description: Sort object.  Learn more about [sorting](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#sorting).  | validation: maxItems 5
           - name: fieldName | type: string | description: Name of the field to sort by.  | validation: maxLength 512
           - name: order | type: SortOrder | description: Sort order.  
                 - enum: ASC, DESC
           - name: origin | type: AddressLocation | description: Origin point for geo-distance sorting on a GEO field results are ordered by distance from this point (ASC = nearest first, DESC = farthest first).  
              - name: latitude | type: number | description: Address latitude.  | validation: format double
              - name: longitude | type: number | description: Address longitude.  | validation: format double
 Query fields:
   - field: programId | operators: $eq | sort: none | aggregatable: undefined | searchable: undefined
   - field: id | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: delayInDays | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: createdDate | operators: none | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: ordering | operators: none | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
 Return type: QuerySectionsResponse
  - name: sections | type: array<Section> | description: Matching sections.  
     - name: id | type: string | description: Section GUID.  | read-only: true | validation: format GUID
     - name: revision | type: string | description: Revision number, which increments by 1 each time the section is updated. To prevent conflicting changes, the current `revision` must be passed when updating the section.  | read-only: true | validation: format int64
     - name: createdDate | type: string | description: Date and time the section was created.  | read-only: true | validation: format date-time
     - name: updatedDate | type: string | description: Date and time the section was last updated.  | read-only: true | validation: format date-time
     - name: programId | type: string | description: Program GUID of the parent program. Provide it when creating a section. After creation, this value can't be changed.  | read-only: true | validation: format GUID, immutable
     - name: description | type: Description | description: Section title.  
        - name: title | type: string | description:   | validation: maxLength 500
     - name: totalSteps | type: integer | description: Total number of steps in the section.  | read-only: true | validation: format int32
     - name: ordering | type: number | description: Position rank used to order sections within a program. To reorder sections, call Move Section.  | read-only: true 
     - name: delayInDays | type: integer | description: Number of days before the section becomes available. The count starts from the program's start date for scheduled programs, or from the participant's enrollment date for self-paced ones. Someone joining a scheduled program after it began may find several sections already open. Use `0` for a section available from the start.  | validation: minimum 0, maximum 5000
     - name: extendedFields | type: ExtendedFields | description: Custom field data for the section. [Extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md) must be configured in the app dashboard before they can be accessed with API calls.  
        - name: namespaces | type: object | description: Extended field data. Each key corresponds to the namespace of the app that created the extended fields. The value of each key is structured according to the schema defined when the extended fields were configured.  You can only access fields for which you have the appropriate permissions.  Learn more about [extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md).  | validation: format map
  - name: pagingMetadata | type: CursorPagingMetadata | description: Paging metadata.  
     - name: count | type: integer | description: Number of items returned in current page.  | validation: format int32
     - name: cursors | type: Cursors | description: Cursor strings that point to the next page, previous page, or both.  
        - name: next | type: string | description: Cursor string pointing to the next page in the list of results.  | validation: maxLength 16000
        - name: prev | type: string | description: Cursor pointing to the previous page in the list of results.  | validation: maxLength 16000
     - name: hasNext | type: boolean | description: Whether there are more pages to retrieve following the current page.  + `true`: Another page of results can be retrieved. + `false`: This is the last page.  


```

### Examples

### Query sections
Filters and sorts sections in a program with cursor-based paging.

```curl
curl -X POST \
'https://www.wixapis.com/online-programs/v3/sections/query' \
-H 'Authorization: <AUTH>' \
-H 'Content-Type: application/json' \
-d '{
  "query": {
    "filter": {
      "programId": "f68c8cf0-95aa-4949-984e-efe800ede364"
    },
    "sort": [
      {
        "fieldName": "ordering",
        "order": "ASC"
      }
    ],
    "cursorPaging": {
      "limit": 10
    }
  }
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.onlinePrograms.sections.querySections(query)
 Description: Retrieves a list of up to 1,000 sections, given the provided paging, filtering, and sorting.  Use this method when you need to filter sections, apply custom sorting or paging, or query across programs. When you know the program GUID and need all sections in program order, call [List Sections](https://dev.wix.com/docs/api-reference/business-management/online-programs/sections/list-sections.md).  Query Sections runs with these defaults, which you can override:  - `createdDate` is sorted in `DESC` order. - `paging.limit` is `1000`. - `paging.offset` is `0`.  Supported filter fields are `programId`, `id`, and `delayInDays`. Supported sorting fields are `id`, `delayInDays`, `createdDate`, and `ordering`. When sorting by a field other than `programId`, also filter by `programId`. Section extended fields aren't supported for filtering or sorting. Queries that reference them are rejected.  To learn about working with Query methods, see [API Query Language](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-the-wix-api-query-language.md), [Sorting and Paging](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-sorting-and-paging.md), and [Field Projection](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-field-projection.md).
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  query
 Method parameters: 
   param name: query | type: SectionQuery   | required: true 
     - name: cursorPaging | type: CursorPaging | description: Cursor paging options.  Learn more about [cursor paging](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#cursor-paging).  
        - name: limit | type: integer | description: Maximum number of items to return in the results.  | validation: minimum 0, maximum 100, format int32
        - name: cursor | type: string | description: Pointer to the next or previous page in the list of results.  Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request.  | validation: maxLength 16000
        - name: filter | type: object | description: Filter object.  Learn more about [filtering](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#filters).  
        - name: sort | type: array<Sorting> | description: Sort object.  Learn more about [sorting](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#sorting).  | validation: maxItems 5
           - name: fieldName | type: string | description: Name of the field to sort by.  | validation: maxLength 512
           - name: order | type: SortOrder | description: Sort order.  
                 - enum: ASC, DESC
           - name: origin | type: AddressLocation | description: Origin point for geo-distance sorting on a GEO field results are ordered by distance from this point (ASC = nearest first, DESC = farthest first).  
              - name: latitude | type: number | description: Address latitude.  
              - name: longitude | type: number | description: Address longitude.  
 Query fields:
   - field: programId | operators: $eq | sort: none | aggregatable: undefined | searchable: undefined
   - field: _id | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte, $startsWith | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: delayInDays | operators: $eq, $ne, $in, $exists, $gt, $gte, $lt, $lte | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: _createdDate | operators: none | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
   - field: ordering | operators: none | sort: ASC, DESC | aggregatable: undefined | searchable: undefined
 Return type: PROMISE<QuerySectionsResponse>
  - name: sections | type: array<Section> | description: Matching sections.  
     - name: _id | type: string | description: Section GUID.  | read-only: true | validation: format GUID
     - name: revision | type: string | description: Revision number, which increments by 1 each time the section is updated. To prevent conflicting changes, the current `revision` must be passed when updating the section.  | read-only: true | validation: format int64
     - name: _createdDate | type: Date | description: Date and time the section was created.  | read-only: true 
     - name: _updatedDate | type: Date | description: Date and time the section was last updated.  | read-only: true 
     - name: programId | type: string | description: Program GUID of the parent program. Provide it when creating a section. After creation, this value can't be changed.  | read-only: true | validation: format GUID, immutable
     - name: description | type: Description | description: Section title.  
        - name: title | type: string | description:   | validation: maxLength 500
     - name: totalSteps | type: integer | description: Total number of steps in the section.  | read-only: true | validation: format int32
     - name: ordering | type: number | description: Position rank used to order sections within a program. To reorder sections, call Move Section.  | read-only: true 
     - name: delayInDays | type: integer | description: Number of days before the section becomes available. The count starts from the program's start date for scheduled programs, or from the participant's enrollment date for self-paced ones. Someone joining a scheduled program after it began may find several sections already open. Use `0` for a section available from the start.  | validation: minimum 0, maximum 5000
     - name: extendedFields | type: ExtendedFields | description: Custom field data for the section. [Extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md) must be configured in the app dashboard before they can be accessed with API calls.  
        - name: namespaces | type: object | description: Extended field data. Each key corresponds to the namespace of the app that created the extended fields. The value of each key is structured according to the schema defined when the extended fields were configured.  You can only access fields for which you have the appropriate permissions.  Learn more about [extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md).  | validation: format map
  - name: pagingMetadata | type: CursorPagingMetadata | description: Paging metadata.  
     - name: count | type: integer | description: Number of items returned in current page.  | validation: format int32
     - name: cursors | type: Cursors | description: Cursor strings that point to the next page, previous page, or both.  
        - name: next | type: string | description: Cursor string pointing to the next page in the list of results.  | validation: maxLength 16000
        - name: prev | type: string | description: Cursor pointing to the previous page in the list of results.  | validation: maxLength 16000
     - name: hasNext | type: boolean | description: Whether there are more pages to retrieve following the current page.  + `true`: Another page of results can be retrieved. + `false`: This is the last page.  


```

### Examples

### Filter and sort sections in a program
```javascript
import { sections } from "@wix/online-programs";

async function querySections() {
  const response = await sections
    .querySections()
    .eq("programId", "f68c8cf0-95aa-4949-984e-efe800ede364")
    .ascending("ordering")
    .limit(10)
    .find();

  return response;
}

/* Promise resolves to:
 * {
 *   "items": [
 *     { "_id": "ead4f8aa-7cd7-462b-a0a9-f9e83b161792", "description": { "title": "Section 1" } }
 *   ],
 *   "length": 1,
 *   "pageSize": 10,
 *   "cursors": {}
 * }
 */
// The result also provides hasNext() and hasPrev() methods.

```

### querySections (self-hosted)
Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { sections } from '@wix/online-programs';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { sections },
  // Include the auth strategy and host as relevant
});


async function querySections(query) {
  const response = await myWixClient.sections.querySections(query);
};
```

---