Forum Discussion

Sunny's avatar
12 years ago

Add Friend using Rest api ???

Hi,

 

Does anyone have an idea over how to add a friend using rest api?

 

Suppose I am on a user profile page and I have added a custom button to add the user as friend.

So what rest call should I make to complete this action?

  • Hi Sunny,

     

    If you have the JavaDocs handy, check out the "friends/add" method in the Contacts class. Here's a sample call:

    /restapi/vc/users/id/5/addressbook/contacts/friends/add

     The method is expecting a "contacts.user" parameter:

    contacts.user (required) : User - the user to add to the friends list. The user can be specified as a relative REST API path, such as id/43 to specify the user by id or login/username to specify the user by username, or by an absolute path beginning with a forward slash, like /users/id/43.

     

  • /restapi/vc/users/id/5/addressbook/contacts/friends/add?contacts.user=id/43

     

    should work, where "43" is the id of the user being added.

  • I think this may be more helpful as we need to do a post call.

     

    $.ajax({
    type: "POST",
    dataType: "xml",
    url: "/restapi/vc/users/id/${user_id}/addressbook/contacts/ignores/add?contacts.user=id/${friend_user_id}",
    success: function(data){ }
    });

  • AdamN's avatar
    AdamN
    Khoros Oracle

    Hi Sunny,

     

    If you have the JavaDocs handy, check out the "friends/add" method in the Contacts class. Here's a sample call:

    /restapi/vc/users/id/5/addressbook/contacts/friends/add

     The method is expecting a "contacts.user" parameter:

    contacts.user (required) : User - the user to add to the friends list. The user can be specified as a relative REST API path, such as id/43 to specify the user by id or login/username to specify the user by username, or by an absolute path beginning with a forward slash, like /users/id/43.

     

    • Sunny's avatar
      Sunny
      Ace
      Hi Adam,

      So I am using this rest call but not getting clearly where should I pass the "contacts.user" parameter,
      How should my call be?
      • VenkS's avatar
        VenkS
        Lithium Alumni (Retired)
        /restapi/vc/users/id/5/addressbook/contacts/friends/add?contacts.user=id/43

         

        should work, where "43" is the id of the user being added.