ad3
ad3

Reputation: 11

"TypeError: Client is not a constructor" on Node.js using Square API

Based on the Square Developer site, it says to initialise a customer like this:

require('dotenv').config();
const { Client, Environment } = require('square');


const client = new Client({
    bearerAuthCredentials: {
        accessToken: process.env.SQUARE_ACCESS_TOKEN
    },
    environment: Environment.Sandbox
});

I am doing exactly that, but with process.env.SQUARE_ENVIRONMENT and process.env.SQUARE_ACCESS_TOKEN. I keep getting "TypeError: Client is not a constructor". Not sure what the issue is.

I expected it to create a customer.

Upvotes: 1

Views: 43

Answers (1)

Mureinik
Mureinik

Reputation: 312086

You're using the legacy API, that has been moved to square/legacy. I.e., you could do:

const { Client, Environment } = require('square/legacy');

But at this point, it's probably a better idea to use the new API:

const { SquareClient, SquareEnvironment } = require('square');

const client = new SquareClient({
    token: process.env.SQUARE_ACCESS_TOKEN,
    environment: SquareEnvironment.Sandbox
});

Upvotes: 0

Related Questions