Users & relations

Learn how to retrieve Facebook profiles and manage friends and follows with Unipile API.

Retrieve a profile

To get a profile, use Get a User Profile. Set me as user_id to get the profile of the account owner.

const { data } = await usersApi.getUserProfile({
  path: {
    account_id: "acc_123456789",
    user_id: "user_id",
  },
});
profile = users_api.get_user_profile("user_id", "acc_123456789")
curl --request GET \
     --url https://api.unipile.com/v2/acc_123456789/users/user_id \
     --header 'X-API-KEY: api-key' \
     --header 'accept: application/json'

A profile picture URL expires within days. To get the current picture, use Get a User Picture.


Edit your profile

To edit the profile of the account owner, use Update a User Profile with me as user_id. Facebook only supports updating the bio and the picture. Any other field returns 400 api/invalid_parameters.

const { data } = await usersApi.updateUserProfile({
  path: {
    account_id: "acc_123456789",
    user_id: "me",
  },
  body: {
    bio: "Master of Unipile APIs",
  },
});
profile = users_api.update_user_profile(
    "me",
    "acc_123456789",
    {"bio": "Master of Unipile APIs"},
)
curl --request PATCH \
     --url https://api.unipile.com/v2/acc_123456789/users/me \
     --header 'X-API-KEY: api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "bio": "Master of Unipile APIs"
}
'

Manage friends

Facebook relations are friends.

List friends

To list friends, use List all User's Relations. Facebook only lists the friends of the account owner, so set me as user_id. Pagination works with cursor, with up to 50 friends per page.

const { data } = await usersApi.getUserRelations({
  path: {
    account_id: "acc_123456789",
    user_id: "me",
  },
});
relations = users_api.get_user_relations("me", "acc_123456789")
curl --request GET \
     --url https://api.unipile.com/v2/acc_123456789/users/me/relations \
     --header 'X-API-KEY: api-key' \
     --header 'accept: application/json'

To remove a friend, use Delete a Relation.

Send a friend request

To send a friend request, use Send a Relation request. Facebook friend requests carry no message: setting message returns 400 api/invalid_parameters.

const { data } = await usersApi.createRelationRequest({
  path: {
    account_id: "acc_123456789",
  },
  body: {
    user_id: "user_id",
  },
});
request = users_api.create_relation_request(
    "acc_123456789",
    {"user_id": "user_id"},
)
curl --request POST \
     --url https://api.unipile.com/v2/acc_123456789/users/me/relation-requests \
     --header 'X-API-KEY: api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "user_id": "user_id"
}
'

To manage pending requests, use List all pending Relation / Follow requests with sent or received as type, then Accept a Relation request or Cancel or Refuse a Relation / Follow request.

🚧

No realtime event

The relation.new event is not available on Facebook. To detect new friends, poll List all User's Relations.


Manage follows

To follow a profile, people and Pages alike, use Follow a User. To stop, use Unfollow a User.

const { data } = await usersApi.followUser({
  path: {
    account_id: "acc_123456789",
    user_id: "user_id",
  },
});
data = users_api.follow_user("user_id", "acc_123456789")
curl --request POST \
     --url https://api.unipile.com/v2/acc_123456789/users/me/follow/user_id \
     --header 'X-API-KEY: api-key' \
     --header 'accept: application/json'

To list the followers or followings of a profile, use List all User Followers and List all User Followings. The follower.new event is not available on Facebook.


Did this page help you?