# Channels

A team's channels: create one, find channels by name with $filter and see which query options the channel list refuses.

A channel is a named place for a team's posts. Load the `teams_launch_hub` scenario, create a channel and find it by the start of its name:

```bash
H='Authorization: Bearer placeholder-token'
J='Content-Type: application/json'
curl -s -o /dev/null -w '%{http_code}\n' -X POST "$RYSTIC_URL/_rystic/scenario" -d '{"name":"teams_launch_hub"}'
# -> 204
CHANNELS="$RYSTIC_URL/v1.0/teams/3dd52548-ef0b-41b9-896b-e62254b098ed/channels"
curl -s "$CHANNELS" -H "$H" -H "$J" -d '{"displayName":"Launch Retro","description":"Retro notes","membershipType":"standard"}' | jq -c '{id, displayName}'
# -> {"id":"19:00000000000000000000000000000001@thread.tacv2","displayName":"Launch Retro"}
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=startswith(displayName,'Launch')" | jq -c '{names: [.value[].displayName], count: ."@odata.count"}'
# -> {"names":["Launch Leads","Launch Retro"],"count":2}
```

`@odata.count` is the number of channels the filter matched.

### Find a channel by name

`$filter` reads one property, `displayName`. The value matches in its exact case, while the property name matches in any case:

```bash
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=displayName eq 'General'" | jq -c '[.value[].displayName]'
# -> ["General"]
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=displayName eq 'general'" | jq -c '[.value[].displayName]'
# -> []
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=DisplayName eq 'General'" | jq -c '[.value[].displayName]'
# -> ["General"]
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=displayName in ('General','Launch Retro')" | jq -c '[.value[].displayName]'
# -> ["General","Launch Retro"]
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=endswith(displayName,'Readiness')" | jq -c '[.value[].displayName]'
# -> ["Release Readiness"]
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=contains(displayName,'Retro')" | jq -c '[.value[].displayName]'
# -> ["Launch Retro"]
```

| Form | Example |
|---|---|
| equals | `displayName eq 'General'` |
| one of | `displayName in ('General','Launch Retro')` |
| starts with | `startswith(displayName,'Launch')` |
| ends with | `endswith(displayName,'Readiness')` |
| contains | `contains(displayName,'Retro')` |

**Differs from Microsoft Graph:** these filters return 400 `BadRequest`, where Microsoft Graph returns 200:

- a comparison or function on another property that Microsoft Graph accepts, such as `membershipType eq 'standard'`, `startswith(description,'Retro')` or `createdDateTime gt 2020-01-01T00:00:00Z`
- a `ne` comparison
- clauses joined with `and` or `or`
- a clause wrapped in `not(...)` or `not` before a function, such as `not(displayName eq 'General')` or `not startswith(displayName,'Gen')`

```bash
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=membershipType eq 'standard'" | jq -c '.error.code'
# -> "BadRequest"
curl -s -o /dev/null -w '%{http_code}\n' -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=startswith(description,'Retro')"
# -> 400
curl -s -o /dev/null -w '%{http_code}\n' -G "$CHANNELS" -H "$H" --data-urlencode '$filter=createdDateTime gt 2020-01-01T00:00:00Z'
# -> 400
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=displayName ne 'General'" | jq -c '.error.code'
# -> "BadRequest"
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=displayName eq 'General' or displayName eq 'Launch Retro'" | jq -c '.error'
# -> {"code":"BadRequest","message":"Invalid filter clause: or"}
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=not(displayName eq 'General')" | jq -c '.error'
# -> {"code":"BadRequest","message":"Invalid filter clause: not"}
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=not startswith(displayName,'Gen')" | jq -c '.error'
# -> {"code":"BadRequest","message":"Invalid filter clause: not"}
```

### Test a refused list query

The channel list returns 400 for `$orderby` on any property, for `$top` and for `$count=true`:

```bash
curl -s -G "$CHANNELS" -H "$H" --data-urlencode '$orderby=displayName' | jq -c '.error | {code, message}'
# -> {"code":"BadRequest","message":"The query specified in the URI is not valid. Query option 'OrderBy' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings."}
curl -s -G "$CHANNELS" -H "$H" --data-urlencode '$top=1' | jq -c '.error.code'
# -> "BadRequest"
curl -s -G "$CHANNELS" -H "$H" --data-urlencode '$count=true' | jq -c '.error | {code, message}'
# -> {"code":"","message":"The query specified in the URI is not valid. Query option 'Count' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings."}
```

**Differs from Microsoft Graph:** the `$orderby` refusal has `error.code` `BadRequest`, where Microsoft Graph's is empty.

**Differs from Microsoft Graph:** these return 400 with a different `error.message` from Microsoft Graph's:

- a filter on an unknown property or a malformed filter
- a comparison Microsoft Graph also refuses, such as `membershipType gt 'a'`
- `$orderby` on an unknown property or with a malformed direction

```bash
curl -s -G "$CHANNELS" -H "$H" --data-urlencode "\$filter=membershipType gt 'a'" | jq -c '.error'
# -> {"code":"BadRequest","message":"Invalid filter clause: not a filterable property"}
```

---

Source: https://www.rystic.ai/docs/simulators/teams/features/channels · Markdown: https://www.rystic.ai/docs/simulators/teams/features/channels.md
