ActivitySubscriptions API
The ActivitySubscriptions API provides endpoints to retrieve Activity entities from the Subscriptions and Activity Feed Framework.
This API requires activation of the Subscriptions and Activity Feed Framework (com.snc.activity_subscriptions) plugin. Activate the Customer Central (com.sn_csm_customer_central) plugin to seed configuration in all required tables. For more information on customer central configuration settings, see Configure customer central.
ActivitySubscriptions - GET /now/actsub/activities
Retrieves activity records from the Subscriptions and Activity Feed Framework.
No role is required to access this endpoint, but data returned is limited by user access settings.
URL format
Versioned URL: /api/now/{api_version}/actsub/activities
Default URL: /api/now/actsub/activities
Supported request parameters
| Name | Description |
|---|---|
| api_version | Optional. Version of the endpoint to access. For example, v1 or v2. Only specify this value to use an endpoint version other than the
latest.
Data type: String |
| Name | Description |
|---|---|
| before | Date/time value. The request returns only records created prior to this date and time. Data type: String Format: YYYY-MM-DD hh:mm:ss or YYYY-MM-DD |
| context | Required. Sys_id of an activity context. Predefined activity contexts include Consumer and Contact. Data type: String Table: Activity Context [sn_actsub_activity_context] |
| context_instance | Required. Sys_id of an instance of the specified activity context, representing the initiator of the activities you want to retrieve. Located in the appropriate table for the activity context. As an example, if you set context to the sys_id of the Consumer activity context, set this parameter to the sys_id of the Consumer [csm_consumer] table record for the consumer whose activities you want to retrieve. Data type: String |
| end_date | Date/time value. The request returns only records created during the time
period defined by start_date and this parameter. Must be set
along with start_date. Data type: String Format: YYYY-MM-DD hh:mm:ss or YYYY-MM-DD |
| facets | Comma-separated list of sys_ids of activity facet types to retrieve for the specified activity context. For more details on activity facets, see Create facets for activity contexts. Data type: String Default: Return all activity facet types configured for the activity context. Table: Activity Facet [sn_actsub_facet] |
| last | Index value of the first result row omitted from the response body. The result row index starts at 0, so the last row included in the response body is the one with the index last-1. For
example, setting Data type: Number (integer) Default: The value of the com.snc.actsub.activities.api.fetch.limit system property (10 by default). |
| record_id | Sys_id of a record to use when rendering dynamic facets. Located in the appropriate table for the activity type you want to retrieve. For example, if you want to fetch activities for a Case record, set this parameter to the sys_id of the Case record in question. For more details on dynamic facets, see Create facets for activity contexts. Data type: String |
| start_date | Date/time value. The request returns only records created during the time
period defined by this parameter and end_date. Must be set
along with end_date. Data type: String Format: YYYY-MM-DD hh:mm:ss or YYYY-MM-DD |
| stFrom | Index value of the first result row to include in the response body. The result row index starts at 0. For example, Data type: Number (integer) Default: 0 |
| Name | Description |
|---|---|
| None |
Headers
The following request and response headers apply to this HTTP action only, or apply to this action in a distinct way. For a list of general headers used in the REST API, see Supported REST API headers.
| Header | Description |
|---|---|
| Accept | Data format of the response
body. Supported types: application/json or
application/xml.
Default: application/json |
| Header | Description |
|---|---|
| None |
Status codes
The following status codes apply to this HTTP action. For a list of possible status codes used in the REST API, see REST API HTTP response codes.
| Status code | Description |
|---|---|
| 200 | Successful. The request was successfully processed. |
| 400 | Bad Request. A bad request type or malformed request
was detected. The response body result.message parameter
describes the nature of the error. Example error messages:
|
| 401 | Unauthorized. The user credentials are incorrect or have not been passed. |
| 500 | Internal server error. An unexpected error occurred while processing the request. The response contains additional information about the error. |
Response body parameters (JSON or XML)
| Name | Description |
|---|---|
| result | Result object. Data type: Object |
| result.activities | Array of objects in which each object represents an activity record from the specified activity context and context instance. Data type: Array of Objects |
| result.activities.activity_type_id | Sys_id of the record from the Activity Types [sn_actsub_activity_type] table
that corresponds to the type of this activity record. Data type: String |
| result.activities.content_fields | Array of objects in which each object represents a field to display as content in the tile for the activity record. Data type: Array of Objects |
| result.activities.content_fields.deeplink_to_subobject | Flag indicating whether or not the content field displays as a hyperlink to the record for the object on which this activity was performed. Valid values:
Data type: String |
| result.activities.content_fields.display_as_timeago | Flag indicating whether or not the content field displays in time ago format. Valid values:
Data type: String |
| result.activities.content_fields.label | Label for the content field. Data type: String |
| result.activities.content_fields.show_label | Flag indicating whether or not the content field label displays for content field values in the tile for this activity record. Valid values:
Data type: String |
| result.activities.content_fields.type | Type of the content field. Data type: String |
| result.activities.content_fields.value | Value of the content field. Data type: String |
| result.activities.created | Creation date/time for this activity record. Data type: String Format: YYYY-DD-MM hh:mm:ss |
| result.activities.icon | Name of the icon displayed on the tile for this activity record. Data type: String |
| result.activities.source_table_name | Name of the table in which this activity record is located. Determined by the Activity Source defined in the Activity Types [sn_actsub_activity_type] table for the type associated with this activity record. Data type: String |
| result.activities.subheader_fields | Array of objects in which each object represents a field displayed in the subheader of the tile for this activity record. Data type: Array of Objects |
| result.activities.subheader_fields.deeplink_to_subobject | Flag indicating whether or not the subheader field displays as a hyperlink to the record for the object on which this activity was performed. Valid values:
Data type: String |
| result.activities.subheader_fields.display_as_timeago | Flag indicating whether or not the subheader field displays in time ago format. Valid values:
Data type: String |
| result.activities.subheader_fields.label | Label for the subheader field. Data type: String |
| result.activities.subheader_fields.show_label | Flag indicating whether or not the subheader field label displays for subheader field values in the tile for this activity record. Valid values:
Data type: String |
| result.activities.subheader_fields.type | Type of the subheader field. Data type: String |
| result.activities.subheader_fields.value | Value of the subheader field. Data type: String |
| result.activities.subobject_sys_id | Sys_id of the record for the object on which this activity was performed.
Located in the table specified in the subobject_table_name
parameter value. Data type: String |
| result.activities.subobject_table_name | Name of the table containing the record for the object on which this activity was performed. Determined by the Table Name defined in the Activity Group [sn_actsub_subscribable_object] table for the group containing the activity type associated with this activity record. Data type: String |
| result.activities.sys_id | Sys_id of this activity record. Located in the table specified as the
source_table_name response body parameter value. Data type: String |
| result.activities.title | Title that displays on the tile for this activity record. Data type: String |
| result.hasMoreRecords | Flag indicating whether or not the list of activities in the response body is truncated by the last query parameter value. Valid values:
Data type: String |
| result.message | Error message describing the problem encountered during request
processing. Data type: String |
| result.status | HTTP status code returned for request. Valid values: Refer to Status Codes. Data type: Number |
| result.stream | Sys_id specified in request context query parameter. Data type: String Table: Activity Context [sn_actsub_activity_context] |
| result.user | Sys_id specified in request context_instance query
parameter. Located in the appropriate table for the activity context. Data type: String |
cURL request
Request the second and third activity records for a specific Contact, limiting to data from 2020:
curl "https://instance.servicenow.com/api/now/actsub/activities\
?context=4a6a035a73d30010e37d71ef64f6a714\
&context_instance=ddce70866f9331003b3c498f5d3ee417\
&stFrom=1&last=3\
&start_date=2020-01-01%2000:00:00&end_date=2020-12-31%2023:59:59" \
--request GET \
--header "Accept: application/json" \
--user "username:password"
The response body includes the two requested activity records for the specified Contact:
{
"result": {
"hasMoreRecords": true,
"activities": [
{
"subobject_table_name": "sn_customerservice_case",
"source_table_name": "sn_customerservice_case",
"content_fields": [
{
"value": "Test",
"show_label": "false",
"type": "string",
"label": "Short description",
"display_as_timeago": "false",
"deeplink_to_subobject": "false"
}
],
"created": "2020-05-29 18:42:16",
"activity_type_id": "baf0aace73530010e37d71ef64f6a748",
"title": "Lamar Wilson created case",
"subobject_sys_id": "1687360e8d819010f87705a074e52ac9",
"icon": "clipboard_outline",
"sys_id": "1687360e8d819010f87705a074e52ac9",
"subheader_fields": [
{
"value": "CS0001007",
"show_label": "false",
"type": "string",
"label": "Number",
"display_as_timeago": "false",
"deeplink_to_subobject": "true"
},
{
"value": "2020-05-29 18:42:16",
"show_label": "false",
"type": "glide_date_time",
"label": "Created",
"display_as_timeago": "true",
"deeplink_to_subobject": "false"
},
{
"value": "",
"show_label": "false",
"type": "reference",
"label": "Assigned to",
"display_as_timeago": "false",
"deeplink_to_subobject": "false"
},
{
"value": "Lamar Wilson",
"show_label": "false",
"type": "reference",
"label": "Contact",
"display_as_timeago": "false",
"deeplink_to_subobject": "false"
}
]
},
{
"subobject_table_name": "kb_knowledge",
"source_table_name": "kb_use",
"content_fields": [
{
"value": "How to Set Up a Broadband Router",
"show_label": "false",
"type": "string",
"label": "Short description",
"display_as_timeago": "false",
"deeplink_to_subobject": "false"
}
],
"created": "2020-05-26 10:00:00",
"activity_type_id": "4a8c329273d30010e37d71ef64f6a7c1",
"title": "Lamar Wilson viewed knowledge article",
"subobject_sys_id": "f855a0a89f011200550bf7b6077fcf4f",
"icon": "document_outline",
"sys_id": "b929dd5873941010e37d71ef64f6a719",
"subheader_fields": [
{
"value": "KB0000110",
"show_label": "false",
"type": "string",
"label": "Number",
"display_as_timeago": "false",
"deeplink_to_subobject": "true"
},
{
"value": "2020-05-26 10:00:00",
"show_label": "false",
"type": "glide_date_time",
"label": "Created",
"display_as_timeago": "true",
"deeplink_to_subobject": "false"
}
]
}
]
}
}
ActivitySubscriptions - GET /now/actsub/facets/{activity_context}/{context_instance}
Retrieves facets configured for an activity context from the Subscriptions and Activity Feed Framework. Displays activity counts and data for each facet as determined by activity type, group, and context settings.
Users must have the actsub_user or admin role to access this endpoint. Data returned is limited by user access settings.
For more details on activity context facets, see Create facets for activity contexts.
URL format
Versioned URL: /api/now/{api_version}/actsub/facets/{activity_context}/{context_instance}
Default URL: /api/now/actsub/facets/{activity_context}/{context_instance}
Supported request parameters
| Name | Description |
|---|---|
| activity_context | Sys_id of an activity context. Predefined activity contexts include Consumer and Contact. Navigate to to view the full list of activity contexts defined for your instance. Data type: String Table: Activity Contexts [sn_actsub_activity_context] |
| api_version | Optional. Version of the endpoint to access. For example, v1 or v2. Only specify this value to use an endpoint version other than the
latest.
Data type: String |
| context_instance | Sys_id of an instance of the specified activity context, representing the initiator of the activities you want to retrieve facets for. As an example, if you set activity_context to the sys_id of the Contact activity context, you should set this parameter to the sys_id of the Contact [customer_contact] record for the contact whose activity facets you want to retrieve. Data type: String Table: In the context table specified for the activity context record in the Activity Contexts [sn_actsub_activity_context] table. |
| Name | Description |
|---|---|
| end_date | Date/time value. The request returns only records created during the time
period defined by start_date and this parameter. Must be set
along with start_date. Data type: String Format: YYYY-MM-DD hh:mm:ss or YYYY-MM-DD |
| facets | Comma-separated list of sys_ids of activity facets to retrieve for the specified activity context. To see the activity facet types defined for an activity context, navigate to and examine the Facets related list. Data type: String Default: Return all activity facets configured for the activity context. |
| get_activity_count | Flag indicating whether or not to include activity counts for each facet in the response body. Valid values:
Data type: Boolean Default: false |
| lazy_load | Flag indicating whether or not to improve performance by omitting facet activity data and activity counts from the response body. This parameter takes precedence over
get_activity_count. Valid values:
Data type: Boolean Default: false |
| start_date | Date/time value. The request returns only records created during the time
period defined by this parameter and end_date. Must be set
along with end_date. Data type: String Format: YYYY-MM-DD hh:mm:ss or YYYY-MM-DD |
| Name | Description |
|---|---|
| None |
Headers
The following request and response headers apply to this HTTP action only, or apply to this action in a distinct way. For a list of general headers used in the REST API, see Supported REST API headers.
| Header | Description |
|---|---|
| Accept | Data format of the response
body. Supported types: application/json or
application/xml.
Default: application/json |
| Header | Description |
|---|---|
| None |
Status codes
The following status codes apply to this HTTP action. For a list of possible status codes used in the REST API, see REST API HTTP response codes.
| Status code | Description |
|---|---|
| 200 | Successful. The request was successfully processed. |
| 400 | Bad Request. A bad request type or malformed request
was detected. The response body result.message parameter
describes the nature of the error. Example error messages:
|
| 401 | Unauthorized. The user credentials are incorrect or have not been passed. |
| 500 | Internal server error. An unexpected error occurred while processing the request. The response contains additional information about the error. |
Response body parameters (JSON or XML)
| Name | Description |
|---|---|
| result | List of activity facets. Data type: Array of Objects |
| result.activity_count | Number of activity records included in this facet (and its children, if any.
Only displayed when lazy_load query parameter is false and
get_activity_count query parameter is true. Data type: Number |
| result.children | Array of objects in which each object represents an activity record (if this is a dynamic facet) or a child facet (if this is a static facet). Data type: Array of Objects |
| result.children.activity_count | Number of activity records included in this child facet (and its children, if
any). Only displayed when the lazy_load query parameter is
false and the get_activity_count query parameter is
true. Data type: Number |
| result.children.created | Creation date/time for this activity record. Data type: String Format: YYYY-MM-DD hh:mm:ss |
| result.children.facet | Sys_id of this child facet record. Data type: String Table: Activity Facet [sn_actsub_facet] |
| result.children.icon | Name of the icon associated with this child facet. Data type: String |
| result.children.sys_id | Sys_id of this activity record. Located in the appropriate table for the parent facet type. As an example, an activity record included in the Cases facet has a sys_id located in the Case [sn_customerservice_case] table. Data type: String |
| result.children.metadata | Array of objects in which each object includes activity record data for a facet field configured in the Activity Facet [sn_actsub_facet] table record for this facet type. Data type: Array of Objects |
| result.children.metadata.key | Name of this facet field. Data type: String |
| result.children.metadata.label | Label of this facet field. Data type: String |
| result.children.metadata.type | Type of this facet field. Data type: String |
| result.children.metadata.value | Value of this facet field. Data type: String |
| result.children.title | Name of this activity record or child facet. Data type: String |
| result.facets | List of sys_ids associated with this facet record. For a dynamic facet, this array contains the sys_id of the facet itself. For a static facet, it instead contains the sys_ids of all facets which are children of
the facet. Data type: Array Table: Activity Facet [sn_actsub_facet] |
| result.icon | Name of the icon associated with this facet. Data type: String |
| result.is_dynamic | Flag indicating whether or not this facet is a dynamic facet. This value determines the type of information included in the children response body parameter. Possible values:
Data type: Boolean |
| result.message | Error message describing problem encountered during request processing. Data type: String |
| result.name | Name of the facet or facet group. Data type: String |
| result.status | HTTP status code returned for request. Possible values: See the Status Code table. Data type: Number |
cURL request
Retrieve Chat, Phone, and Knowledge articles facets and activity counts for a Contact:
curl "https://instance.servicenow.com/api/now/actsub/facets/4a6a035a73d30010e37d71ef64f6a714/ddce70866f9331003b3c498f5d3ee417\
?get_activity_count=true\
&facets=510d7e2e73570010e37d71ef64f6a70d,bc9bfaaa73570010e37d71ef64f6a771,c72d7e2e73570010e37d71ef64f6a7b8" \
--request GET \
--header "Accept: application/json" \
--user "username:password"
The response body includes the three requested facets as children of their facet groups, with activity counts displayed:
{
"result": [
{
"is_dynamic": false,
"name": "Interactions",
"activity_count": 4.0,
"facets": [
"510d7e2e73570010e37d71ef64f6a70d",
"bc9bfaaa73570010e37d71ef64f6a771"
],
"children": [
{
"facet": "510d7e2e73570010e37d71ef64f6a70d",
"icon": "chat_outline",
"activity_count": 2.0,
"title": "Chat"
},
{
"facet": "bc9bfaaa73570010e37d71ef64f6a771",
"icon": "phone_outline",
"activity_count": 2.0,
"title": "Phone"
}
]
},
{
"is_dynamic": false,
"name": "Portal Activity",
"activity_count": 5.0,
"facets": [
"c72d7e2e73570010e37d71ef64f6a7b8"
],
"children": [
{
"facet": "c72d7e2e73570010e37d71ef64f6a7b8",
"icon": "document_outline",
"activity_count": 5.0,
"title": "Knowledge articles"
}
]
}
]
}