Space in name fields returns 'invalid token'

Bugs Reports and Useful Links

Space in name fields returns 'invalid token'

Postby skippybosco » Fri Sep 19, 2008 3:41 am

When creating or updating a user via API, if you have a space in the first name or last name the API returns "invalid token".

The UI allows names with spaces in it (example: first: Mary Jo last: Smith), so it seems reasonable that the API should allow this as well.

For the moment I am wrapping the plugin name fields with $surname = str_replace( ' ', '', $surname ); .
User avatar
skippybosco
 
Posts: 2150
Joined: Fri Aug 22, 2008 7:58 am

Re: Space in name fields returns 'invalid token'

Postby trentv » Tue Jan 06, 2015 3:06 pm

Has there been a resolution to this bug? It appears to produce an error for spaces that exist in the first name, surname or username. The problem is that there are a lot of people that have spaces for their surname, such as "del Rio". How can we fix this?
trentv
 
Posts: 10
Joined: Tue Jan 06, 2015 3:03 pm

Re: Space in name fields returns 'invalid token'

Postby vprountzos » Thu Jan 08, 2015 2:19 pm

Hello,

Please receive attached the file

www/api2.php

Replace the one you have with the one i am sending you.

After this change you should urlencode the users first and last name. A username can not have any spaces so this change does not apply to usernames.

Kind regards

V. Prountzos
Attachments
api2.zip
(13.22 KiB) Downloaded 71 times
vprountzos
 
Posts: 589
Joined: Tue Feb 19, 2013 11:06 am

Re: Space in name fields returns 'invalid token'

Postby trentv » Tue Jan 13, 2015 2:37 am

Hi vprountzos,

Thanks for the reply. Do you know if there are any specific requirements for the API? Every once in a while, I have a user come through that registers with my e-commerce software that doesn't create a user account using the API. I try and set up an account for them on eFront manually but the Update API code doesn't work for them either.

There doesn't seem to be anything weird with their firstname, surname, username or e-mail address that I can see. No spaces, special characters and there's at least 6 alphanumeric characters there but all attempts to update the account using the API fails for that particular user.

I'm stumped. I have no idea why it's not working. Any thoughts? Maybe the new API you sent me will fix it?

Out of curiousity, is this api2.php different from the one that came with eFront 3.6.14?
trentv
 
Posts: 10
Joined: Tue Jan 06, 2015 3:03 pm

Re: Space in name fields returns 'invalid token'

Postby trentv » Tue Jan 13, 2015 4:46 am

I should mention that I've never been able to get the api2.php to work. I've been using api.php. I've used skippybosco's code and I've no idea why I can't even get the apidemo2.php to work properly. It always gives me an Invalid token error or tells me that the User already exists, even though I can't find the user I just created anywhere in the database.

Here's the code I've been using with the api.php:

$api_url = 'http://localhost/efront3.6.14/www/api.php';
$admin_id = 'admin';
$admin_pw = 'password';

if ($stream = fopen($api_url.'?action=token', 'r')) {
$token = stream_get_contents($stream);
$token = preg_replace('#</?token[^>]*>#is', '', $token);
fclose($stream);
}


if ($stream = fopen($api_url.'?action=login&username='.$admin_id.'&password='.$admin_pw.'&token='.$token, 'r')) {
$login = stream_get_contents($stream);
fclose($stream);
}


if ($stream = fopen($api_url.'?action=create_user&login=new&password='.$_POST['passwd'].'&name='.$customer->firstname.'&surname='.$customer->lastname.'&login='.$customer->username.'&email='.$customer->email.'&languages=english&token='.$token, 'r')) {
$create = stream_get_contents($stream);
fclose($stream);
}
trentv
 
Posts: 10
Joined: Tue Jan 06, 2015 3:03 pm

Re: Space in name fields returns 'invalid token'

Postby vprountzos » Tue Jan 13, 2015 10:03 am

Hello,

The file api2.php i sent in this thread is different than the on in eFront 3.6.14. You should not use the api.php, because it is obsolete, it will work in some of the cases but it does not support most of the functionality that comes with the latest eFront versions.

Regarding the user that the API fails to update, what is the response that you get? Can you give me more details?

Kind regards

V. Prountzos
vprountzos
 
Posts: 589
Joined: Tue Feb 19, 2013 11:06 am

Re: Space in name fields returns 'invalid token'

Postby trentv » Wed Jan 14, 2015 5:10 pm

Hi vprountzos,

I get the Error Invalid Token. As I said, the api2.php doesn't seem to work for me. I've used skippybosco's code to integrate into my ecommerce software but the api2.php just won't pass the token.

I can't figure out why it's not. The code I've been using seems to follow the steps required for the api2.php by calling a token, logging in with an admin username/password and then executing the command but no luck.

I can't even get the apidemo2.php to work. It keeps giving me an Error Invalid token. I've replaced the old api2.php with yours and still get an error. Any thoughts? I appreciate the help.
trentv
 
Posts: 10
Joined: Tue Jan 06, 2015 3:03 pm


Return to Bugs

Who is online

Users browsing this forum: No registered users and 2 guests