[Vuejs]-CORs error when accessing Square V2 API

3πŸ‘

I don’t think the Square API supports being called from a browser. I used Postman to do an OPTIONS request on https://connect.squareup.com/v2/catalog/list and the response was a NOT_FOUND. The OPTIONS request is needed for proper CORS support.

Plus, if you did this, I would think your auth token would need to be sent to the client β€” thus exposing it to everyone. It looks like the Square API is only designed to be called from a server. But that is just based on me skimming the docs a bit. I have no experience using their API.

πŸ‘€PatrickSteele

0πŸ‘

When doing OAuth authorization request you are not supposed to do it from your application. Create and URL with the parameters and open it in a new browser window or tab, Something like:

 const grants='MERCHANT_PROFILE_READ CUSTOMERS_READ CUSTOMERS_WRITE PAYMENTS_READ PAYMENTS_WRITE PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS PAYMENTS_WRITE_IN_PERSON';
    const params = new HttpParams()
        .set('scope', grants)
        .set('client_id', <YourSquareApplicationId>)
        .set('state', '1878789');
    const requestUrl = `${<squareUrl>}/oauth2/authorize?${params.toString()}`;
    window.open(requestUrl, "_blank"); 

That new window is supposed to ask the end user to login to his account and accept or deny the request.

πŸ‘€user2555515

Leave a comment