question

Ben Watkins avatar image
Ben Watkins asked Phong Vu answered

Potential issue with address book update favorite contacts API endpoint

Hi all,

I am currently using the RC API to create an app and I'm making a contact list component. It lists all contacts and all favorite contacts on the page, and I'm trying to add functionality where you can add/remove contacts from favorites.

I'm using the PUT method on the /restapi/v1.0/account/~/extension/~/favorite with the body:

{records : [

{

id: `${contactId}`,

contactId: contactId

}

]} i.e. using the contact id as a unique ID. however when I list the favourites, the id field resets to 1 for some reason? I'm only adding one favorite at a time, and when I try to add another one, it will replace the previous one, presumably because the ID is the same. Just wondered if there's any way around this, whether there's a better way to do this or whether there's a potential bug with the API ?

Really appreciate any feedback and if you need more detail please ask!!

Cheers,

Ben

rest apicontacts
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Phong Vu avatar image
Phong Vu answered

The id in a favorite contact record is an integer and is not the contact id. It's the ordinal number of a contact in the favorite contact list.

Remember that the update favorite contact API will override the entire favorite contact so you need to read the user favorite contact, then grab the records object from the response, and modify the record member data and use that records object to update the user favorite contact. Here is an example.

// read the user favorite contact 

// Response
response = {
  uri: 'https://platform.ringcentral.com/restapi/v1.0/account/80964xxx/extension/6228832xxx/favorite',
  records: [
    { id: 1, contactId: '18405126001' },
    { id: 2, contactId: '18405126401' },
    { id: 3, contactId: '18405126101' },
    { id: 4, extensionId: '6198663701' }
  ]
}
// Modify the records to change the second contact
var records = response.records
records[1].contactId = "5597152019"

// Then call the API to update the favorite contact using the modified records data.


1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys