Activity REST API routes
BuddyPress activities inform about actions and interactions of the community site’s members. Members can share public announcements and react about these by commenting or favoriting them. Activities also log events generated by the other BuddyPress components, for instance, when two users become friends.
[!IMPORTANT] The Activity component is an optional one. This means the activity endpoints will only be available if the component is active on the community site.
Schema
The schema defines all the fields that exist for an activity object.
| Property | Description |
|---|---|
id |
Unique identifier for the activity item. JSON data type: integer. Read only. Context: embed, view, edit. |
primary_item_id |
The ID of some other object primarily associated with this activity item. JSON data type: integer. Context: embed, view, edit. |
secondary_item_id |
The ID of some other object also associated with this activity item. JSON data type: integer. Context: embed, view, edit. |
user_id |
The ID for the author of the activity item. JSON data type: integer. Read only. Context: embed, view, edit. |
link |
The permalink to this activity item on the site. JSON data type: string, format: URI. Read only. Context: embed, view, edit. |
component |
The BuddyPress component the activity item relates to. JSON data type: string. One of: the active BuddyPress component names. Context: embed, view, edit. |
type |
The type of the activity (e.g.: activity_update). JSON data type: string. One of: the registered activity types. Context: embed, view, edit. |
title |
The description of the activity item’s type (eg: Username posted an update). JSON data type: string. Read only. Context: embed, view, edit. |
content |
The raw and rendered contents of the activity item. JSON data type: object (properties: raw, rendered ). Context: embed, view, edit. |
date |
The date the activity item was published, in the site’s timezone. JSON data type: string | null, format: date-time. Read only. Context: embed, view, edit. |
date_gmt |
The date the activity item was published, as GMT. JSON data type: string | null, format: date-time. Read only. Context: embed, view, edit. |
status |
Whether the activity has been marked as spam or not. JSON data type: string. Read only. One of: published, spam. Context: embed, view, edit. |
comments |
A list of comments which are children of the activity item. JSON data type: array. Read only. Context: embed, view, edit. |
comment_count |
Total number of comments which are children of the activity item. JSON data type: integer. Read only. Context: embed, view, edit. |
hidden |
Whether the activity item should be sitewide hidden or not. JSON data type: boolean. Read only. Context: embed, edit. |
favorited |
Whether the activity item has been favorited by the current user. JSON data type: boolean. Read only. Context: embed, view, edit. |
user_avatar[^1] |
Avatar URLs for the author of the activity item (Full & Thumb sizes). JSON data type: object (properties: full, and thumb). Read only. Context: embed, view, edit. |
List Activities
Arguments
| Name | Description |
|---|---|
context |
Scope under which the request is made; determines fields present in response. JSON data type: string. Default: view. One of: view, embed, edit. |
page |
Current page of the collection. JSON data type: integer. Default: 1. |
per_page |
Maximum number of activity items to be returned in result set. JSON data type: integer. Default: 10. |
search |
Limit results to those matching a string. JSON data type: string. |
exclude |
Ensure result set excludes specific IDs. JSON data type: array. Default: []. |
include |
Ensure result set includes specific IDs. JSON data type: array. Default: []. |
order |
Order sort attribute ascending or descending. JSON data type: string. Default: desc. One of: desc, asc. |
after |
Limit result set to activity items published after a given ISO8601 compliant date. JSON data type: string | null, format: date-time. |
user_id |
Limit result set to activity items created by a specific user (ID). JSON data type: integer. Default: 0. |
status |
Limit result set to activity items with a specific status. JSON data type: string. Default: ham_only. One of: ham_only, spam_only, all. |
scope |
Limit result set to activity items with a specific scope. JSON data type: string. One of: just-me, friends, groups, favorites, mentions. |
group_id |
Limit result set to activity items created by a specific group. JSON data type: integer. Default: 0. |
site_id |
Limit result set to activity items created by a specific site. JSON data type: integer. Default: 0. |
primary_id |
Limit result set to activity items with a specific prime association ID. JSON data type: integer. Default: 0. |
secondary_id |
Limit result set to activity items with a specific secondary association ID. JSON data type: integer. Default: 0. |
component |
Limit result set to activity items with a specific BuddyPress component. JSON data type: string. One of: the active BuddyPress component names. |
type |
Limit result set to activity items with one or more specific activity type. JSON data type: array. One of: the registered activity types. |
display_comments |
No comments by default, stream for within stream display, threaded for below each activity item. JSON data type: string. Default: ''. |
Definition
GET /buddypress/v2/activity
Example of use
[!WARNING] The
requestHeadersobject needs to be set according to the WordPress REST API nonce. Read more about the REST API authentification.
fetch( '/wp-json/buddypress/v2/activity?context=view&type=activity_update', {
method: 'GET',
headers: requestHeaders,
} ).then( ( response ) => {
return response.json();
} ).then( ( data ) => {
console.table( data );
} );
JSON Response
- An array of objects representing the matching activity items on success.
- An object containg the error code, data and message on failure.
Create an activity item
Logged in users can create sitewide activity items. When the Groups component is active, only group members can create activity items within the corresponding group.
Arguments
| Name | Description |
|---|---|
primary_item_id |
The ID of some other object primarily associated with this one. JSON data type: integer. |
secondary_item_id |
The ID of some other object also associated with this one. JSON data type: integer. |
link |
The permalink to this activity item on the site. JSON data type: string, format: URI. |
component |
The active BuddyPress component the activity relates to. JSON data type: string. One of: the active BuddyPress component names. Default: activity. |
type |
The type of the activity (e.g.: activity_update). JSON data type: string. One of: the registered activity types. Default: activity_update. |
content |
Allowed HTML content for the activity. JSON data type: string. |
hidden |
Whether the activity item should be sitewide hidden or not. JSON data type: boolean. |
Definition
POST /buddypress/v2/activity
Example of use
[!WARNING] The
requestHeadersobject needs to be set according to the WordPress REST API nonce. Read more about the REST API authentification.
fetch( '/wp-json/buddypress/v2/activity', {
method: 'POST',
headers: requestHeaders,
body: JSON.stringify(
{
content: 'bapuu is the BuddyPress wapuu',
}
),
} ).then( ( response ) => {
return response.json();
} ).then( ( data ) => {
console.log( data );
} );
JSON Response
- An object representing the created activity item on success.
- An object containg the error code, data and message on failure.
Retrieve a specific activity item
Arguments
| Name | Description |
|---|---|
id |
A unique numeric ID for the activity item. Required. JSON data type: integer. |
context |
Scope under which the request is made; determines fields present in response. JSON data type: string. Default: view. One of: view, embed, edit. |
Definition
GET /buddypress/v2/activity/<id>
Example of use
[!WARNING] The
requestHeadersobject needs to be set according to the WordPress REST API nonce. Read more about the REST API authentification.
fetch( '/wp-json/buddypress/v2/activity/18', {
method: 'GET',
headers: requestHeaders,
} ).then( ( response ) => {
return response.json();
} ).then( ( data ) => {
console.log( data );
} );
JSON Response
- An object representing the activity item on success.
- An object containg the error code, data and message on failure.
Update a specific activity item
Arguments
| Name | Description |
|---|---|
id |
A unique numeric ID for the activity item. Required. JSON data type: integer. |
primary_item_id |
The ID of some other object primarily associated with this one. JSON data type: integer. |
primary_item_id |
The ID of some other object also associated with this one. JSON data type: integer. |
link |
The permalink to this activity item on the site. JSON data type: string, format: URI. |
component |
The active BuddyPress component the activity relates to. JSON data type: string. One of: the active BuddyPress component names. Default: activity. |
type |
The type of the activity (e.g.: activity_update). Required. JSON data type: string. One of: the registered activity types. Default: activity_update. |
content |
Allowed HTML content for the activity. JSON data type: string. |
hidden |
Whether the activity item should be sitewide hidden or not. JSON data type: boolean. |
Definition
PUT /buddypress/v2/activity/<id>
Example of use
[!WARNING] The
requestHeadersobject needs to be set according to the WordPress REST API nonce. Read more about the REST API authentification.
fetch( '/wp-json/buddypress/v2/activity/18', {
method: 'PUT',
headers: requestHeaders,
body: JSON.stringify(
{
content: 'bapuu, The BP wapuu.',
type: 'activity_update',
}
),
} ).then( ( response ) => {
return response.json();
} ).then( ( data ) => {
console.log( data );
} );
JSON Response
- An object representing the updated activity item on success.
- An object containg the error code, data and message on failure.
Delete a specific activity item
Arguments
| Name | Description |
|---|---|
id |
A unique numeric ID for the activity item. Required. JSON data type: integer. |
Definition
DELETE /buddypress/v2/activity/<id>
Example of use
[!WARNING] The
requestHeadersobject needs to be set according to the WordPress REST API nonce. Read more about the REST API authentification.
fetch( '/wp-json/buddypress/v2/activity/18', {
method: 'DELETE',
headers: requestHeaders,
} ).then( ( response ) => {
return response.json();
} ).then( ( data ) => {
console.log( data );
} );
JSON Response
- An object informing about the
deletedstatus and thepreviousactivity item on success. - An object containg the error code, data and message on failure.
Add or remove a specific activity item from favorited activities
NB: the same endpoint is used to favorite and unfavorite an activity item. In case the activity is already favorited, it will remove this activity item from favorite activities.
Arguments
| Name | Description |
|---|---|
id |
A unique numeric ID for the activity item. Required. JSON data type: integer. |
Definition
POST /buddypress/v2/activity/<id>/favorite
Example of use
[!WARNING] The
requestHeadersobject needs to be set according to the WordPress REST API nonce. Read more about the REST API authentification.
fetch( '/wp-json/buddypress/v2/activity/17/favorite', {
method: 'POST',
headers: requestHeaders,
} ).then( ( response ) => {
return response.json();
} ).then( ( data ) => {
console.log( data );
} );
JSON Response
- An object representing the activity item on success.
- An object containg the error code, data and message on failure.
[^1]: This property is only available if the WordPress discussion settings allow avatars.
谢谢你的反馈!