Friend connections

The Friends component allow your members to make connections with other members. The BuddyPress Friendship is a mutually agreed relationship between 2 members.

Note: The Friends component is an optional one. This means the following endpoints will only be available if the component is active on the community site

Schema Schema

The schema defines all the fields that exist for a friendship object.

id

integer
A unique numeric ID for the friendship.
Read only
Context: viewedit
initiator_id

integer
The ID of the user who is requesting the Friendship.
Context: viewedit
friend_id

integer
The ID of the user who is invited to agree to the Friendship request.
Context: viewedit
is_confirmed

boolean
Whether the friendship has been confirmed. true if it is the case, false otherwise.
Read only
Context: viewedit
date_created

string,
date-time
The date the friendship was created, in the site’s timezone.
Read only
Context: viewedit

Top ↑

List a Member’s Friendship requests List a Member’s Friendship requests

Arguments Arguments

NameTypeDescription
contextstringScope under which the request is made; determines fields present in response.
Default: view
One of : view, edit
pageintegerCurrent page of the collection.
Default: 1
per_pageintegerMaximum number of friendships to be returned in result set.
Default: 10
user_idintegerID of the member whose friendships are being retrieved.
Required
Default: the logged in user ID
is_confirmedintegerWhether the friendship has been confirmed. 1 if it is the case, 0 otherwise.
Default: 0
idintegerUnique numeric identifier of the friendship.
Default: 0
initiator_idintegerThe ID of the user who is requesting the Friendship.
Default: 0
friend_idintegerThe ID of the user who is invited to agree to the Friendship request.
Default: 0
orderbystringOrder Groups by which attribute.
Default: date_created
One of : 'date_created', 'initiator_user_id', 'friend_user_id', 'id'
orderstringOrder sort attribute ascending or descending.
Default: desc
One of : asc, desc

Top ↑

Definition Definition

GET /buddypress/v1/friends

Top ↑

Example of use Example of use

Alert: To use the bp.apiRequest function, you need to enqueue the bp-api-request JavaScript or use it as a dependency of your script. Refer to this page to know more about loading JavaScript files in WordPress.

bp.apiRequest( {
  path: 'buddypress/v1/friends',
  type: 'GET',
  data: {
    context: 'view',
    'user_id': 47,
    'is_confirmed': 1
  }
} ).done( function( data ) {
  return data;
} ).fail( function( error ) {
  return error;
} );

Top ↑

Request a new Friendship Request a new Friendship

Top ↑

Arguments Arguments

NameTypeDescription
contextstringScope under which the request is made; determines fields present in response.
Default: edit
One of : view, edit
initiator_idintegerThe ID of the user who is requesting the Friendship.
Required
friend_idintegerThe ID of the user who is invited to agree to the Friendship request.
Required
forcebooleanWhether to force the friendship agreement.
NB: Only Administrators can force a friendship.
Default: false

Top ↑

Definition Definition

POST /buddypress/v1/friends

Top ↑

Example of use Example of use

Alert: To use the bp.apiRequest function, you need to enqueue the bp-api-request JavaScript or use it as a dependency of your script. Refer to this page to know more about loading JavaScript files in WordPress.

bp.apiRequest( {
  path: 'buddypress/v1/friends',
  type: 'POST',
  data: {
    context: 'edit',
    'initiator_id': 4, // Required.
    'friend_id': 5     // Required.
  }
} ).done( function( data ) {
  return data;
} ).fail( function( error ) {
  return error;
} );

Top ↑

Retrieve the Friendship between the logged in Member & another Member Retrieve the Friendship between the logged in Member & another Member

Top ↑

Arguments Arguments

NameTypeDescription
idintegerNumeric identifier for a possible Friendship initiator or for the user who is invited to agree to a Friendship request.
Required
contextstringScope under which the request is made; determines fields present in response.
Default: view
One of : view, edit

Top ↑

Definition Definition

GET /buddypress/v1/friends/<id>

Top ↑

Example of use Example of use

Alert: To use the bp.apiRequest function, you need to enqueue the bp-api-request JavaScript or use it as a dependency of your script. Refer to this page to know more about loading JavaScript files in WordPress.

bp.apiRequest( {
  path: 'buddypress/v1/friends/51',
  type: 'GET',
  data: {
    context: 'view'
  }
} ).done( function( data ) {
  return data;
} ).fail( function( error ) {
  return error;
} );

Top ↑

Let the logged in Member accept a Friendship Let the logged in Member accept a Friendship

Top ↑

Arguments Arguments

NameTypeDescription
idintegerNumeric identifier of the friendship initiator.
Required
contextstringScope under which the request is made; determines fields present in response.
Default: edit
One of : view, edit

Top ↑

Definition Definition

PUT /buddypress/v1/friends/<id>

Top ↑

Example of use Example of use

Alert: To use the bp.apiRequest function, you need to enqueue the bp-api-request JavaScript or use it as a dependency of your script. Refer to this page to know more about loading JavaScript files in WordPress.

bp.apiRequest( {
  path: 'buddypress/v1/friends/131',
  type: 'PUT',
  data: {
    context: 'edit'
  }
} ).done( function( data ) {
  return data;
} ).fail( function( error ) {
  return error;
} );

Top ↑

Let the logged in Member reject, withdraw or remove a Friendship. Let the logged in Member reject, withdraw or remove a Friendship.

  • The logged in Member is withdrawing a Friendship request when he is the initiator.
  • The logged in Member is rejecting a Friendship request when he is the user who is invited to agree to a Friendship request.
  • The logged in Member is removing an existing Friendship when the force argument is used.

Top ↑

Arguments Arguments

NameTypeDescription
idintegerA unique numeric ID for the user who requested a Friendship or who is invited to agree to a Friendship request.
Required
forcebooleanWhether to force the removal of an existing Friendship. true to remove, false otherwise.
Default: false
contextstringScope under which the request is made; determines fields present in response.
Default: edit
One of : view, edit

Top ↑

Definition Definition

DELETE /buddypress/v1/friends/<id>

Top ↑

Example of use Example of use

Alert: To use the bp.apiRequest function, you need to enqueue the bp-api-request JavaScript or use it as a dependency of your script. Refer to this page to know more about loading JavaScript files in WordPress.

bp.apiRequest( {
  path: 'buddypress/v1/friends/131',
  type: 'DELETE',
  data: {
    context: 'edit',
    force: true
  }
} ).done( function( data ) {
  return data;
} ).fail( function( error ) {
  return error;
} );