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.

API fetch customer error

dariodario Member
in Help edited October 2014

I'm trying to use the API to get the list of customers using javascript (I know that passing api_token from js is not safe but I'm just testing foxycart, no real deployment for the moment).

So, if I use CURL, it works (I get some XML 'no users found') but if I use js+ajax (with same api_token and api_action) I always get the error
<message>Required API Token Missing (api_token)</message><context>1004</context><message>Required API Action Missing (api_action)</message>

I use a common ajax Post with the following parameters:
url: 'https://[my shop]',
 method: 'POST',
data: { 
   api_token: [my api token],
    d.api_action : "customer_list"

I also tried to set different headers (content-type, accept) but no way to get some data. Am I missing something?

  • fc_adamfc_adam FoxyCart Team

    As long as you're running this on the same domain as your store, something like this should work:
      type: "POST",
      url: "",
      data: { api_token: "XXXXXXX", api_action: "category_list" }
    }).done(function(xml) {
  • dariodario Member
    edited October 2014
    I'm not in the same domain, I'm testing on localhost. When I make the call I have no cross-domain errors, I got an XML answer from the API but with issues about api_token and api_action missing. I tried your code and same issue...
  • fc_adamfc_adam FoxyCart Team

    Open up your store and give it a try in the console on your store domain - for example on the cart or checkout. The code I pasted above works for me when on page page of the same domain.
  • dariodario Member
    edited November 2014
    Hello Adam
    Is there a way to test and use foxycart from a different domain? Or how can I have some file in the same domain of Is there some folder to upload some file?

    I try to clarify: I'm testing the whole thing on my localhost, so I'm using localhost as server; there is no cross-domain issues, the requests are sent and the response is received in the right format but with the error message. Which is the best way to test the whole thing?

  • fc_adamfc_adam FoxyCart Team

    To be honest - what I'd recommend doing is actually moving to a server-side language to test this out. To do reliably with javascript though, and to get it onto the same domain as your store, you'll just need to include your scripts within one of your FoxyCart templates. You can do that from within your stores administration - and edit the cart or checkout templates to include your script.

    If you wouldn't mind - could you also whisper me your store domain? I'd like to look at the logs to see how it's handling the requests that it's returning those errors to you.
  • Hello Adam
    In the end uploading the script in the template worked
  • fc_adamfc_adam FoxyCart Team

    Awesome - thanks for posting back with an update
Sign In or Register to comment.