POST /user-<upid>/favorites/list/ - List of favorites of a user
Returns the favorites in the favorites list 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.
Even if there is yet no favorites, the API can be called, and will return and empty dictionary result.
Endpoint URL
https://api3.greencopper.com/account/<project-tag>/user-<upid>/favorites/list/
Request information
Request type
POST
Request parameters
Parameter | Mandatory | Description |
---|---|---|
auth_type | X | See authentication mechanism |
auth_token | X |
Response information
The list of favorites on a JSON array. Each favorite is a dict containing all favorites parameters except "is favorite" one.
Only the favorites with the property "is_favorite" with "TRUE" value are returned.
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
[ { "timestamp": 1368023501, "object_type": 2, "object_id": 40 }, { "timestamp": 1362672972, "object_type": 1, "object_id": 50 }, ... { "timestamp": 1368025820, "object_type": 2, "object_id": 6 } ]
Web sample - JavaScript implementation
Sample code based on jQuery to get the list of favorites. After that call, you can update your UI to display a list of favorites, or update your buttons with a broadcast event or list of listeners.
For more information about "getFacebookSignedRequest" method, read the authentication mechanism.
/* * Get the user favorites list, store them, and update UI accordingly. * The user must be logged before calling this method. We need a UPID. */ getFavorites: function() { var self = this; if (self.isLogged()) { // Compute the URL based on user UPID urlToList = 'https://api3.greencopper.com/account/<project-tag>/user-<upid>/favorites/list/'); // Calling goevent account favorites list webservice with user credentials jQuery.ajax({ type: 'POST', url: urlToList, data: { auth_type: "facebook", auth_token: self.getFacebookSignedRequest() }, success: function( data ) { // Store favorites locally // Display them on a list, or update UI var favorites = jQuery.parseJSON(data); // Store that now we get the favorites loaded self.favoritesLoaded = true; }, error: function(jqXHR, textStatus, errorThrown) { // Error while getting favorites, display error message if needed self.favoritesLoaded = false; } }); } else { // Login required before getting favorites } }