PDA

View Full Version : Volusion v1 API USER Endpoint



Marc_NY
08-21-2014, 03:13 PM
I thought I would take some time and start a thread on some of the new API endpoints. In this case the USERS endpoint, what it is, what info can be retrieved, updated or inserted with it. I am sure that others may want to chime in and offer any thoughts or even some may have questions on how to use it even though Volusion has some basic descriptions but they don't really give you any real world code on how one would use them.

Let's start with the "Check if email account is valid" which is currently active and functional on all V13 stores. Although functional I really don't see any constructive use for it and as I have stated previously not too happy they have it but I suppose they will need it to check to be sure a user was created.

For specific info on this see https://volusion-angular.github.io/theme-engine-docs/devcenter/Content/ThemeAPI/Theme_Users_GetEmail.htm

http://{domain}/api/v1/users?email=email

Basically to use this one would enter a Volusion domain in place of the {domain} and insert the email address in place of email. If your enter it in a browser it doesn't really do you much good and you cannot really do anything useful with it. In firebug however you will see that if the email address exists in the database then it will return a 200 status code (ok) if it doesn't exists a user it will return a 404 status code (not found).

Here is an example of a code snippet using jQuery that allows you to do something with it.



var email = 'johndoe@domain.com';
jQuery.ajax({
url: '/api/v1/users/current?email=' + email,
type: 'GET',
cache: false,
dataType: 'json',
success: function (data) {
DO SOMETHING IF THE EMAIL EXISTS
},
error: function () {
DO SOMETHING IF IT DOESN'T EXIST
}
});


Next we will dive into the "Get Logged In User" part of the USERS endpoint, which is probably the most useful part of this endpoint.

Please comment, correct me or ask any question you may have.

GGG
08-21-2014, 03:35 PM
Please comment, correct me or ask any question you may have.

I didn't understand a single word you typed except for the sentence I just quoted.

Could that email 'do something if the email exists' stuff be used to create some kind of 'combine' thingy for customers who already have an email on file, but want to check out as a guest? As in... let them do so, no password required, and add the order to their 'email' on file...

Quit laughing at me. I have no clue what you're talking about and there's no such thing as a stupid question. Even if it is.

sigh.

Marc_NY
08-21-2014, 03:42 PM
In itself, all this does is provide logic as to whether or not a user email exists. Any "combining" of accounts is something that would have to be done behind the scenes.

GGG
08-21-2014, 04:02 PM
Ok, I just read through the orders stuff...seems like same old with guest checkout. However, if this new API gives more control...and I found somebody who knew what they were doing... COULD it be done?

Sorry, another stupid ? about the stuff you posted. I can't be the only moron on this forum. So that 404 status code is just as a 'trigger' to collect email info for an unrecognized user? It's not an 'error' per se... simply a switch to the next defined step...as in 'please enter email'. (pardon my terminology)

GGG
08-21-2014, 04:13 PM
Wait a sec. Then please explain this. What about customers who have previously checked out as guests. Have account/customer id's...whatever...no password to retrieve. Never had one. Same email address.

758

swilliams
08-21-2014, 04:26 PM
Thanks for sharing Marc. I agree that this endpoint is a little creepy, but since it's there will be helpful for many I'm sure.

Marc_NY
08-21-2014, 04:32 PM
Anonymous or not is irrelevant, If the email is in use then it will return a 200 status code.

Again all this is really good for is to do a check to see if a email is currently in use. It could be a non customer even, like a user who registered for a newsletter.

GGG
08-21-2014, 04:41 PM
haha! Marc and Scott, I'm trying my best to understand and not get creeped out. I understand the 'get' stuff, 'post' stuff, 'delete' stuff, mostly.

However, this seems intrinsically flawed unless somewhere/somehow in the process there's some kind of function to 'recognize' existing email as 'anonymous' or something like that to allow user to continue despite email on file? My 'anonymous' accounts couldn't log in because no password on file.

Maybe I haven't read far enough ahead? I'm not trying to put the cart before the horse, but this is extremely important to me.

GGG
08-21-2014, 04:45 PM
Anonymous or not is irrelevant, If the email is in use then it will return a 200 status code.

Again all this is really good for is to do a check to see if a email is currently in use. It could be a non customer even, like a user who registered for a newsletter.

Ok, thanks, Marc. It's checked for email on file. Period.:)

Marc_NY
08-21-2014, 04:53 PM
Since they are currently saying to use the legacy login and checkout process it remains to be seen what they intend to do in that area but I cannot imagine them not doing something.

I personally would like them to do a forced https site. No more http!!!!

MelanieF
08-21-2014, 06:27 PM
I'm with you GGG and I have to start reading these threads early in the morning with coffee instead of just before bed!

Marc_NY
08-21-2014, 07:49 PM
The second parts of this endpoint is the "Get Logged In User"

This is perhaps one of the most important parts of this endpoint and the one which I personally find the most useful and is often the starting point for many script which I have written recently.

Examples of its use would be a to recongnize when a user is logged in so that you can properly show the login or logout link on your website rather than a static "login" link or what some do which is show the link like this "login/logout?". Now you can show the correct one based on actual login status.

http://{domain}/api/v1/users/current

Again replace {domain} with your domain. Provided the user is logged in, the server will respond will a status code of 200 and a JSON response with the following data. You can use any or all of the data for script or simply check the status code.

Note: I am actually not checking the status code in the script below but and if I really wanted to be anal about it I could actually check the true status code but this for all practical purposes does the same.

customer ID
first name
last name:
email address:
store credit available amount:
isAnonymous:

If the user is not currently logged in the server responds with a 404 status code

This is a script to show what is returned. You could use this data is custom script. I have used this data on several script recently.


<script>
jQuery.ajax({
url: '/api/v1/users/current',
type: 'GET',
cache: false,
dataType: 'json',
success: function (data) {
alert('CUSTOMER ID: ' + data.data.id + ' - EMAIL: ' + data.data.email + ' - NAME: ' + data.data.firstName + ' ' + data.data.lastName + ' - ANONYMOUS?: ' + data.data.isAnonymous + ' - Store Credit Available : ' + data.data.storeCreditAvailable);
},
error: function () {
alert('User not logged in');
}
});
</script>

GGG
08-22-2014, 04:53 AM
sigh. Ok, I've had my morning coffee as Melanie suggested. Unfortunately, still hung up on the 'anonymous' user.

How could a previously anonymous customer be logged in given response of the email endpoint? I can't get my brain wrapped around this. Either I still can't see the forest through the trees or this stuff has been set up incorrectly. Does it function properly for users not logged in because given explanation for the email endpoint, I don't think so?

I see isAnonymous for current user, but what about previous?

I know. I know. You're merely explaining the endpoint and doing a good job :)

Edit post: Although this appears to be written just for logged in users... so perhaps not relevant for 'anonymous' unless set up to trigger other functions?

Marc_NY
08-22-2014, 05:36 AM
Like you said I didn't design the API. The assumption is and I haven't tested it yet, perhaps it is set right after a user checks out and pays. The user is logged in kinda but doesn't have a password set. Also I beleive it is technically possible for the admin to set an account to anonomous even with a password, I would have to check that as well.

dmoore
09-10-2014, 02:56 PM
Let's start with the "Check if email account is valid" which is currently active and functional on all V13 stores. Although functional I really don't see any constructive use for it and as I have stated previously not too happy they have it but I suppose they will need it to check to be sure a user was created.

I can already see a use for this - I have a multi-page form that uses VSMTP, so if I could check to see if the user already has an email in the database, it would send the email to the CRM system but if they don't have an email, it goes over to the standard mailbox.

Marc_NY
09-10-2014, 03:19 PM
I suppose that would be one use.