Create an HTTPS request

Hello Square support.

I am trying to retrieve the list of customers in my account through the REST API, as noted in the documentation. However, when I run the code below I am not receiving any response, and the xhttp.responseText is NULL.
Could you please provide me with any guidance on how to complete this task?
Thank you in advance.

    const endpoint = 'https://connect.squareup.com/v2/customers/search';
    var accesstoken = 'EAAAEB4lmEG*********P0gtakZYxubfGN'  //production

    const xhttp = new XMLHttpRequest();
 
    xhttp.open('POST', endpoint, true); 
    xhttp.setRequestHeader('Content-Type', 'application/json');
    xhttp.setRequestHeader('Authorization', 'Bearer ' + accesstoken);              
    const requestBody = JSON.stringify({
        'query': {
            'filter': {}
        }
    });
  
    xhttp.send(requestBody);
    const response = xhttp.responseText;

Whats your application ID? :slight_smile:

Hello Bryan

Here is my app ID sandbox-sq0idb-1IW4o2k_sK-fxFviTssK5A

I did find an error after viewing dev options regarding Access-Control-Allow-Origin

Let me know if you need anything else

Is this call happening on the client? If so it will throw this error. You’ll need to make sure that this call is a server side API call. :slight_smile:

Hello Bryan

My application is a Microsoft addin that is written in javascript. The app will do the http request so there is no server involved.

In dev mode I found this error. Any ideas?

A cross-origin resource sharing (CORS) request was blocked because of invalid or missing response headers of the request or the associated preflight request .

To fix this issue, ensure the response to the CORS request and/or the associated preflight request are not missing headers and use valid header values.

Thanks

image001.jpg