The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

weird error on API-created accounts

swensorswensor Member
in Bugs & Feature Requests edited May 2009
hey all,

i am using the api to import a membership database into foxycart, so users will have a seemless checkout their first time paying for anything. all the users i created using the api do not work, i get this error when i try to insert the password and click "continue" (default template graphic):

Error: unterminated string literal
Source File: https://cgcw.foxycart.com/v/0.5.0/checkout.php?ThisAction=customer_info&PHPSESSID=9nqbom7h4k8vc3l3igvqvqq7a2
Line: 12, Column: 18
Source Code:
"customer_phone": "860 583-6895

can anyone make sense of this? is there anything i need to do to make my api-created accounts function properly? it does not happen with accounts created via typical check out. thanks!!!
Comments
  • lukeluke FoxyCart Team
    That's no good... sounds like a bug somewhere. You're describing a JavaScript error, right? It must be that the API is not correctly saving the customer phone or something. Do you have FireBug installed? If so, could you whisper us the entire JSON response you get after attempting to login with the customer?

    Also, what's the API call you're making to create the customer?
  • swensorswensor Member
    hey luke/all,

    yes it is a javascript error, i just installed firebug (way awesome tool thanks!), and here is the response data:

    jsonp1241797796990({
    "result": "LoginCorrect",
    "id": "2b523c404a04f1cfd8e2e1a11048cd92",
    "customer_first_name": "Daniel",
    "customer_last_name": "Kucinskas",
    "customer_email": "dank16@usa.net",
    "customer_address1": "98 Main St",
    "customer_address2": "",
    "customer_city": "Terryville",
    "customer_state": "CT",
    "customer_postal_code": "6786",
    "customer_country": "",
    "customer_phone": "860 583-6895
    ",
    "shipping_first_name": "",
    "shipping_last_name": "",
    "shipping_address1": "",
    "shipping_address2": "",
    "shipping_city": "",
    "shipping_state": "",
    "shipping_postal_code": "",
    "shipping_country": "",
    "shipping_phone": "",
    "customer_company": ",",
    "shipping_company": "",
    "customer_company": ",",
    "shipping_company": "",
    "customer_country_name": "",
    "customer_state_name": "",
    "shipping_country_name": "",
    "shipping_state_name": "",
    "save_cc": false,
    "cc_number": "",
    "cc_exp_month": "",
    "cc_exp_year": "",
    "has_active_subs": false,
    addresses: [
    ]
    })

    is that what you needed? i am pretty sure its just the customer_phone having improper formatting, haha... is that the issue do you think? thats where the error i described in my initial post was generated i am fairly sure.
    thanks for the speedy response, as usual.
  • swensorswensor Member
    edited May 2009
    oh oops,

    i am using the following form values, performing the post with asp.net:

    inputs.Add("api_token","centraxxxxx345")
    inputs.Add("api_action","customer_save")
    inputs.Add("customer_email",email)
    inputs.Add("customer_password",password)
    inputs.Add("customer_company",company)
    inputs.Add("customer_first_name",fn)
    inputs.Add("customer_last_name",ln)
    inputs.Add("customer_company",company)
    inputs.Add("customer_address1",add)
    inputs.Add("customer_city",city)
    inputs.Add("customer_state",state)
    inputs.Add("customer_postal_code",zip)
    inputs.Add("customer_country",country)
    inputs.Add("customer_phone",phone)
    PostTo("https://cgcw.foxycart.com/api",inputs)

    the PostTo() method presumably posts to a url. it seems to work, it is creating the accounts, but they dont work properly. i'm wondering if maybe encoding or something is a problem here. any ideas?

    is there anything wrong w/ my data? the phone variable is completely stripped of any new lines or what have you.

    another weird detail... when i trya different method, using a simple web form i made to post data to the api... it was able to successfully reformat the phone number, and enable the account to checkout w/o JS errors. the html for that form is like this:

    <body>
    <form action="https://cgcw.foxycart.com/api"; method="post">
    <input type="text" name="api_token" value="centralpt31512345"/>
    <input type="text" name="api_action" value="customer_get"/>
    <input type="text" name="customer_email" value="bheffernan@collinsbarrow.com"/>
    <input type="text" name="customer_phone" value=""/>

    <input type="submit"/>
    </form>
    </body>


    only when i use my automated script does it behave strangely. i get the same output (xml of customer information) as the simple web form on my automated script, but for some reason it decides to format the phone number differently... i'm trying to figure if the issue is on my side or your side...
  • lukeluke FoxyCart Team
    Ah yes, that sounds familiar. If you're pulling this data from a SQL database you'll definitely need to use ASP's Trim(string) method. There is a carriage return in your phone number field there. Looking through the accounts you've set up, there's a bit of funky data in there. Quite of a few of them were created with the email address listed twice (separated by a comma) and others where the company is listed twice (or not at all, but a comma is there).

    When dealing with API's it can be a little tricky for us to determine what should be rejected from a validation standpoint and what should be allowed. We'll be thinking this through a little more and may end up adding our own trim methods, email address validation checks and such down the road. I'd recommend using the API to pull the customers you've created (by email address) and inspect the data there. If something is funky, go ahead and update that customer.

    Some of your customers, for example, have their address information wrapped in double quotes which may cause problems as well.

    Data cleanup and validation always takes WAY longer than you expect whenever you try to integrate systems.

    Have fun and let us know what else we can do to help.
  • swensorswensor Member
    Hey all,

    So i figured this one out, its possibly a bug in the api, or maybe I am just tripping. Alright so when I had "phone" as my last form variable before calling PostTo():

    ...
    inputs.Add("customer_postal_code",zip)
    inputs.Add("customer_country",country)
    inputs.Add("customer_phone",phone)
    PostTo("https://cgcw.foxycart.com/api",inputs)
    ...

    This was not working. So I set phone to a static "8888888888" and it still had new-lines and formatting in the customer_phone field and when i tried to check out, still threw that jsonp error. I then grew quite presumptuous and figured for whatever reason, the last field had a newline appended to it. Maybe its being done by my method (PostTo), I got it mostly from a code sample, but it might be something in the api.

    I tested this PostTo() script a fair amount, posting to another script on my site, and found that the way I retrieved posted data (in asp.net) affects its formatting IN AN IDENTICAL WAY. If I spit the collection out via a loop then it does not have any formatting, if I straight call for "customer_phone" from the collection, then it pads it with new lines and shiiii.

    So anyways, I added a dummy field to be "mis-handled" (either PostTo or FoxyCart's api) after customer_phone, and all of a sudden customer_phone comes through super groovy and my dummy field gets ignored by your software (getting presumptuous again [^_^] ). This works now:

    ...
    inputs.Add("customer_postal_code",zip)
    inputs.Add("customer_country",country)
    inputs.Add("customer_phone",phone)
    inputs.Add("filla","filla")
    Response.Write(PostTo("https://cgcw.foxycart.com/api",inputs) & "<br/><br/>")
    ...

    Just thought I'd share, there's still a chance my PostTo() method is sending it a bit funky to your servers (I'm on .Net+Windows, you are php and probably Unix), but it seems that I was able to post it properly, and it ended up getting handled improperly. so i'm thinking its either encoding or an api bug. as for this specific problem i have it fixed with that dummy field. thanks again and peace out!
  • lukeluke FoxyCart Team
    .net+windows = crufty. :)

    You may want to look into your PostTo a bit more since sending a dummy field doesn't seem like a very good solution to me. Is PostTo something you could post here? We might be able to diagnose something for you. At least you got it working.
Sign In or Register to comment.