# Channel Metrics

In order to query message metrics you must have a channel and perform a HTTP request to the following endpoints with a valid access key.

#### Fetch message metrics by channel ID

Retrieve a TimeSeries of metrics for the given **FilterType** and **FilterId**

| Filter Types | Filter ID                         |
| ------------ | --------------------------------- |
| Channel      | The **Channel ID** of the Channel |
| Platform     | Currently Unused                  |
| Status       | Currently Unused                  |

| Group By | Notes                                                                            |
| -------- | -------------------------------------------------------------------------------- |
| status   | Groups the results by the channel status, such as "queued, sent, delivered" etc. |

## Fetch message metrics

> Fetch message metrics for a platform or channel

```json
{"openapi":"3.0.3","info":{"title":"Reporting","version":"v1"},"tags":[{"name":"metrics","description":"Provide metrics to the customers"}],"security":[{"user":[]},{"accessKey":[]}],"components":{"securitySchemes":{"user":{"description":"Provide the token that is returned upon login","scheme":"bearer","type":"http","bearerFormat":"jwt"},"accessKey":{"description":"Uses the Authorization header: 'AccessKey ' followed by your access key token (e.g., 'Authorization: AccessKey AbCdEfGhIjKlMnOpQrStUvWxYzAbCdEfGhIj')","scheme":"AccessKey","type":"http"}},"schemas":{"MessageCreate":{"type":"object","title":"CreateMessageMetrics","additionalProperties":false,"required":["periodStart","periodEnd","periodGroup"],"properties":{"periodStart":{"$ref":"#/components/schemas/PeriodTime"},"periodEnd":{"$ref":"#/components/schemas/PeriodTime"},"periodGroup":{"type":"string","enum":["minute","hour","day","month"]},"select":{"type":"array","maxLength":1,"nullable":true,"items":{"type":"string","enum":["count"]}},"filterBy":{"type":"object","additionalProperties":false,"nullable":true,"properties":{"direction":{"$ref":"#/components/schemas/Direction","default":"out"},"status":{"$ref":"#/components/schemas/MessageStatus"},"messageType":{"$ref":"#/components/schemas/MessageType"},"channelId":{"type":"string"},"platformId":{"type":"string"},"contextEnabled":{"type":"boolean","description":"Allows querying for stats with the context info provided"},"contextType":{"type":"string","description":"The type of context we want to use in our query"},"contextId":{"type":"string","description":"The relevant ID for the specified context type"},"interaction":{"$ref":"#/components/schemas/MessageInteraction"}}},"groupBy":{"type":"array","uniqueItems":true,"nullable":true,"items":{"type":"string","enum":["status","messageType","direction","interaction"]}}}},"PeriodTime":{"type":"string","format":"date-time"},"Direction":{"type":"string","enum":["out","in",""]},"MessageStatus":{"type":"string","enum":["accepted","processing","sent","sending_failed","delivered","delivery_failed",""]},"MessageType":{"type":"string","enum":["text","image","file","gif","location","carousel","list",""]},"MessageInteraction":{"type":"string","enum":["read","opened","clicked","delete","reported_as_spam","unsubscribe_request","reaction",""]},"MessageResult":{"type":"object","title":"MetricsList","description":"A list of metrics","required":["dataColumns"],"properties":{"periodGroup":{"type":"string","enum":["minute","hour","day","month"]},"dataColumns":{"type":"array","items":{"type":"string","enum":["messageType","status","direction","interaction"]}},"results":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["periodTime"],"properties":{"periodTime":{"type":"string","format":"date-time"},"count":{"type":"integer","format":"int64"},"data":{"type":"array","nullable":true,"items":{"type":"string"}}}}}}},"ValidationError":{"type":"object","properties":{"code":{"type":"string"},"message":{"type":"string"},"details":{"type":"object","additionalProperties":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]}}},"required":["code","message"]}},"responses":{"validationError":{"description":"The request did not pass validation","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}}}},"paths":{"/workspaces/{workspaceId}/reporting/messages/{filterType}/{filterId}/metrics":{"post":{"summary":"Fetch message metrics","operationId":"getMessageMetricsByFilter","description":"Fetch message metrics for a platform or channel","tags":["metrics"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageCreate"}}}},"responses":{"200":{"description":"List of results","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResult"}}}},"422":{"$ref":"#/components/responses/validationError"}}}}}}
```

#### Fetch channel metrics using query parameter filters

## Fetch channel metrics

> Fetch channel metrics using various query parameters

```json
{"openapi":"3.0.3","info":{"title":"Reporting","version":"v1"},"tags":[{"name":"metrics","description":"Provide metrics to the customers"}],"security":[{"user":[]},{"accessKey":[]}],"components":{"securitySchemes":{"user":{"description":"Provide the token that is returned upon login","scheme":"bearer","type":"http","bearerFormat":"jwt"},"accessKey":{"description":"Uses the Authorization header: 'AccessKey ' followed by your access key token (e.g., 'Authorization: AccessKey AbCdEfGhIjKlMnOpQrStUvWxYzAbCdEfGhIj')","scheme":"AccessKey","type":"http"}},"schemas":{"ChannelsMetricsResult":{"type":"array","items":{"type":"object","properties":{"summary":{"type":"object","properties":{"channelId":{"type":"string","format":"uuid"},"channelName":{"type":"string"},"channelPlatformId":{"type":"string"},"channelStatus":{"type":"string"},"messageType":{"type":"string"},"direction":{"type":"string"},"queued":{"type":"integer","format":"int64","nullable":true},"skipped":{"type":"integer","format":"int64","nullable":true},"scheduled":{"type":"integer","format":"int64","nullable":true},"delivered":{"type":"integer","format":"int64","nullable":true},"bounced":{"type":"integer","format":"int64","nullable":true},"opened":{"type":"integer","format":"int64","nullable":true},"readOrOpened":{"type":"integer","format":"int64","nullable":true},"clicked":{"type":"integer","format":"int64","nullable":true},"unsubscribed":{"type":"integer","format":"int64","nullable":true},"checkoutAbandonedCount":{"type":"integer","format":"int64","nullable":true},"orderConfirmedCount":{"type":"integer","format":"int64","nullable":true},"formViewedCount":{"type":"integer","format":"int64","nullable":true},"formSubmittedCount":{"type":"integer","format":"int64","nullable":true},"pageViewedCount":{"type":"integer","format":"int64","nullable":true},"productViewedCount":{"type":"integer","format":"int64","nullable":true},"attributedRevenue":{"type":"number","format":"float","nullable":true},"currency":{"type":"string","nullable":true}}},"timeSeries":{"type":"array","items":{"type":"object","properties":{"periodDate":{"type":"string","format":"date-time","nullable":false},"queued":{"type":"integer","format":"int64","nullable":true},"skipped":{"type":"integer","format":"int64","nullable":true},"scheduled":{"type":"integer","format":"int64","nullable":true},"delivered":{"type":"integer","format":"int64","nullable":true},"bounced":{"type":"integer","format":"int64","nullable":true},"opened":{"type":"integer","format":"int64","nullable":true},"clicked":{"type":"integer","format":"int64","nullable":true},"unsubscribed":{"type":"integer","format":"int64","nullable":true}}}}}}},"ValidationError":{"type":"object","properties":{"code":{"type":"string"},"message":{"type":"string"},"details":{"type":"object","additionalProperties":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]}}},"required":["code","message"]}},"responses":{"validationError":{"description":"The request did not pass validation","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}}}},"paths":{"/workspaces/{workspaceId}/reporting/channels/metrics":{"get":{"summary":"Fetch channel metrics","operationId":"getChannelMetrics","description":"Fetch channel metrics using various query parameters","tags":["metrics"],"parameters":[{"name":"periodStart","in":"query","description":"The start of the period for which to fetch metrics","required":true,"schema":{"type":"string","format":"date-time","description":"The date and time in the format 'YYYY-MM-DDTHH:MM:SSZ' or 'YYYY-MM-DDTHH:MM:SS-HH:MM'."}},{"name":"periodEnd","in":"query","description":"The end of the period for which to fetch metrics","required":false,"schema":{"type":"string","format":"date-time","description":"The date and time in the format 'YYYY-MM-DDTHH:MM:SSZ' or 'YYYY-MM-DDTHH:MM:SS-HH:MM'."}},{"name":"periodGroup","in":"query","description":"The time grouping of the period for which to fetch metrics. If provided time series will be returned and grouped by this period.","required":false,"schema":{"type":"string","enum":["minute","hour","day","month"]}},{"name":"filter","in":"query","description":"Filter conditions for which to fetch metrics. Each condition is a string in the format of 'equals(`field`,`value`)'. \n Available field-value pairs are\n - `channelID` - UUID, can supply multiple equals conditions for multiple channelIds\n - `platformID` - string, can supply multiple equals conditions for multiple platforms\n   - Common values are 'sms-messagebird', 'email-sparkpost', 'whatsapp', 'rcs-google'. More are possible and are specified in the summary response for a channel\n - `status` - string, can supply multiple equals conditions for multiple statuses\n     - Allowed values are 'invalid', 'pending', 'setting_up', 'active', 'inactive', 'failed', 'deleted'\n - `name` - string, only one condition allowed\n - `messageType` - string, can supply multiple equals conditions for multiple messageTypes\n   - Allowed values are 'invalid', 'text', 'html', 'image', 'file', 'gif', 'location', 'carousel', 'list', 'section', 'authentication', 'contact', 'template'\n - `direction` - string, only one condition allowed\n   - Allowed values are 'in', 'out', 'unknown'\n","required":false,"schema":{"type":"string"}}],"responses":{"200":{"description":"List of results","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChannelsMetricsResult"}}}},"422":{"$ref":"#/components/responses/validationError"}}}}}}
```
