POST /user/ - Login of a user

Create a user, or get the User Project ID (UPID) if it already exists in the system.
A user is linked to a Facebook ID and a specific project.

Once a user is created, you will get the User Project ID (UPID) that can be used on further calls to get user favorites, or add/remove a favorite.

Endpoint URL

https://api3.greencopper.com/account/<project-tag>/user/

Request information

Request type

POST

Request parameters

ParameterMandatoryDescription
auth_typeXSee authentication mechanism
for more information
auth_tokenX
gc_user_id
Required for projects using version > 6.16
share_favorites
0 or 1, defaults to 0. Set if the user's favorites will be shared with his Facebook friends

Response information

The User Project ID (UPID) in a JSON dict.

Response format

JSON

Response sample

{ upid: "215" }



Web sample - JavaScript implementation

Sample code based on jQuery and the Facebook JavaScript SDK callback, after registering to "auth.authResponseChange" and "auth.login" FB.event.
You can get more information on the Facebook JavaScript SDK, and on the FB.login method.

For more information about "getFacebookSignedRequest" method, read the authentication mechanism

/*
 * Internal login after the user is Facebook authenticated.
 * Try to log into the Greencopper system, and store the user ID to cookies if succeeded.
 */
internalLogin: function(){

    var signedRequest = this.getFacebookSignedRequest();
    if (signedRequest == null) {
        // Can not login without a valid Facebook signed request
        // Remove cookie if any
        return;
    }

    // Ensure we are not already trying to login
    if (!this.loginInProgress) {
        // Save that we are trying to login
        this.loginInProgress = true;
		var self = this;

        // Call the API
        jQuery.ajax({
            type: 'POST',
            url: 'http://api3.greencopper.com/account/<project-tag>/user/',
            data: { auth_type: "facebook", auth_token: signedRequest },
            success: function( data ) {
                var result = jQuery.parseJSON(data);
                self.loginInProgress = false;
				// Store in a cookie the user project ID
				// User is now connected, you can call API list to get favorites
            },
            error: function(jqXHR, textStatus, errorThrown) {
				self.loginInProgress = false;
 				// Error state management
				// Display and error to your user if you want
				// Remove cookie with user project ID if needed
            }
        });
    }
}