POST /user-<upid>/favorites/update/ - Update a favorite of a user
Updates a favorite of a user for a project (based on UPID).
The user must be already created and be authenticated in the good way, otherwise a 401 Unauthorized will be returned.
The call can optionally returns the new list of favorites to avoid another call to list them.
Endpoint URL
https://api3.greencopper.com/account/<project-tag>/user-<upid>/favorites/update/
Request information
Request type
POST
Request parameters
Parameter | Mandatory | Description |
---|---|---|
auth_type | X | See authentication mechanism for more information |
auth_token | X | |
data | X | JSON list of favorites, structured as follow: [ { }, ... "is_favorite": Use value 0 to remove a favorite and value 1 to add as a favorite. "delta" is the duration in seconds between favorite modification on the device and sync time. |
callback | X | Indicates if the response must contains the new list of favorites. |
share_favorites | 0 or 1, defaults to 0. Set if the user's favorites will be shared with his Facebook friends |
Response information
A dict with a value "success" if "callback" parameter set to false, otherwise, the list of favorites exactly as retrieved from the /favorites/list/ API call.
Response format
JSON
Response header
- Gc-Reference-Date: Reference date used by the server. Used on mobile to synchronize timestamp with the server.
Not used on web if no local storage usage, as timestamp are not used.
Response sample
{ "success": "true" }
Web sample - JavaScript implementation
Sample code based on jQuery to add/remove a favorite from the list of favorites.
For more information about "getFacebookSignedRequest" method, read the authentication mechanism.
/* * Update a favorite by adding/removing it from the list of favorites. * The user must be logged before calling this method. We need a UPID. */ updateFavorite: function(favorite, is_favorite) { var self = this; if (self.isLogged()) { // Update UI accordingly to that new state // The best is to it before the call, so the user will have the feeling of instant operation // Compute the URL based on user UPID urlToUpdate = 'https://api3.greencopper.com/account/<project-tag>/user-<upid>/favorites/update/'); data = [ { object_id: favorite.object_id, object_type: favorite.object_type, is_favorite: is_favorite } ]; GC_jQuery.ajax({ type: 'POST', url: urlToUpdate, data: { auth_type: "facebook", auth_token: self.getFacebookSignedRequest(), callback:"false", data:JSON.stringify(data, null) }, success: function(data) { // Nothing more to do, the UI have already been updated }, error: function(jqXHR, textStatus, errorThrown) { // Error while updating favorite // Rollback behavior on the UI, and warn user if needed } }); } else { // Login required before updating favorites } }