Order-Ahead Sample Application

Evening,

Hoping for some guidance. I am attempting to create the Order-Ahead Sample Application

But I have already ran into a wall from step two.
Testing your credentials it states to
the following command in the root directory of the order-ahead sample application:
npm test

I now get an error that states:

echo ‘Error: no test specified’

‘Error: no test specified’

I had a different error earlier, however, after much research, I found I should instal an older version of node which I have now done. BUt I still get this error.

I have also been following Day 4 of #100DaysOfCode: Building My First Square App with Glitch - DEV Community

No avail and various other youtube videos.

Any help greatly appreciated. From a humble beginner!

Hi @michaelhilland, our Order-Ahead Sample Application does say that you will need to have the latest version of Node.js. If you follow the walkthrough are you still running into the error?

Hi Bryan,

Yep, I have the latest version.

I now have ran into the following error:

Response status code was not ok: 401.

[
{
“category”: “AUTHENTICATION_ERROR”,
“code”: “UNAUTHORIZED”,
“detail”: “The Authorization http header of your request was malformed. The header value is expected to be of the format “Bearer TOKEN” (without quotation marks), where TOKEN is to be replaced with your access token (e.g. “Bearer ABC123def456GHI789jkl0”). For more information, see https://developer.squareup.com/docs/build-basics/using-rest-api#set-the-headers. If you are seeing this error message while using one of our officially supported SDKs, please report this to [email protected].”
}
]

I copied the env example file and inputted the following which is correct:

Sandbox Credentials

SQUARE_SANDBOX_ACCESS_TOKEN={{redacted}}
SQUARE_SANDBOX_APPLICATION_ID={{sandbox-sq0idb-1jPktxdYiuG1v0UN0nF1EA}}

Production Credentials

SQUARE_PRODUCTION_ACCESS_TOKEN={{YOUR_ACCESS_TOKEN}}
SQUARE_PRODUCION_APPLICATION_ID={{YOUR_APPLICATION_ID}}

Hi @michaelhilland please do not share your access tokens ever. I strongly suggest you replace your access token in your developer dashboard, as anyone who copied that value can now make API calls on your account.

As for the error: it looks like you’re leaving the {{}}; the brackets are meant as placeholders and should be removed. Ie your application id should look like: SQUARE_SANDBOX_APPLICATION_ID=sandbox-sq0idb-1jPktxdYiuG1v0UN0nF1EA.

@sjosey
Apologies thought I had removed them.

I have now replaced as you advised. I am no longer getting an error, however, when loading localhost3000 the page loads with

This is what I am running in the command prompt shell:

Microsoft Windows [Version 10.0.18362.295]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\micha>cd OneDrive\Desktop\node_orders-payments
C:\Users\micha\OneDrive\Desktop\node_orders-payments>npm install
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“win32”,“arch”:“x64”})
audited 486 packages in 1.877s
16 packages are looking for funding
run npm fund for details

found 0 vulnerabilities

C:\Users\micha\OneDrive\Desktop\node_orders-payments>npm run seed

[email protected] seed C:\Users\micha\OneDrive\Desktop\node_orders-payments
NODE_ENV=sandbox node ./bin/script/seed-catalog.js generate

Updating catalog items failed: ApiError: Response status code was not ok: 400.
at C:\Users\micha\OneDrive\Desktop\node_orders-payments\node_modules\square\dist\square.cjs.development.js:19719:15
at _callee$ (C:\Users\micha\OneDrive\Desktop\node_orders-payments\node_modules\square\dist\square.cjs.development.js:19322:66)
at tryCatch (C:\Users\micha\OneDrive\Desktop\node_orders-payments\node_modules\square\dist\square.cjs.development.js:275:40)
at Generator.invoke [as _invoke] (C:\Users\micha\OneDrive\Desktop\node_orders-payments\node_modules\square\dist\square.cjs.development.js:505:22)
at Generator.next (C:\Users\micha\OneDrive\Desktop\node_orders-payments\node_modules\square\dist\square.cjs.development.js:330:21)
at asyncGeneratorStep (C:\Users\micha\OneDrive\Desktop\node_orders-payments\node_modules\square\dist\square.cjs.development.js:16:24)
at _next (C:\Users\micha\OneDrive\Desktop\node_orders-payments\node_modules\square\dist\square.cjs.development.js:38:9)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
request: {
method: ‘POST’,
url: ‘https://connect.squareupsandbox.com/v2/catalog/batch-upsert’,
headers: {
‘user-agent’: ‘Square-TypeScript-SDK/7.0.0’,
‘content-type’: ‘application/json’,
authorization: ‘Bearer {{access_token}}’,
accept: ‘application/json’
},
body: {
type: ‘text’,
content: {"idempotency_key":"8c33882b1ff7e786f0fe90c4332fd98b47dafb1949121f852e76449bcd5288565d08be167a2afe338b2a027a0f58986de051dfda479ec9e212c3e465afeff611","batches":[{"objects":[{"type":"TAX","id":"#Sales Tax","is_deleted":false,"present_at_all_locations":true,"tax_data":{"name":"Sales Tax","calculation_phase":"TAX_TOTAL_PHASE","inclusion_type":"ADDITIVE","percentage":"8.5","applies_to_custom_amounts":true,"enabled":true}},{"type":"CATEGORY","id":"#Breakfast Category","present_at_all_locations":true,"category_data":{"name":"Breakfast"}},{"type":"CATEGORY","id":"#Entree Category","present_at_all_locations":true,"category_data":{"name":"Entree"}},{"type":"ITEM","id":"#Bacon Cheeseburger","present_at_all_locations":true,"item_data":{"name":"Bacon Cheeseburger","description":"One mouth-watering, flame-grilled, quarter-pound angus beef burger with your choice of cheese on a sesame seed bun. Comes with a side of fries.","category_id":"#Entree Category","tax_ids":["#Sales Tax"],"variations":[{"type":"ITEM_VARIATION","id":"#Regular Bacon Cheeseburger","is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"#Bacon Cheeseburger","name":"Regular","pricing_type":"FIXED_PRICING","price_money":{"amount":995,"currency":"USD"}}}]}},{"type":"ITEM","id":"#Fried Chicken Sandwich","item_data":{"name":"Fried Chicken Sandwich","description":"A buttermilk fried chicken thigh with crispy skin on a sesame seed bun. Topped with fresh red cabbage slaw and jalapeños and our house hot sauce.","abbreviation":"FCS","category_id":"#Entree Category","tax_ids":["#Sales Tax"],"variations":[{"type":"ITEM_VARIATION","id":"#Regular Fried Chicken Sandwich","is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"#Fried Chicken Sandwich","name":"Regular","pricing_type":"FIXED_PRICING","price_money":{"amount":675,"currency":"USD"}}}]}},{"type":"ITEM","id":"#Sunny-Side Egg on Toast","item_data":{"name":"Sunny-Side Egg on Toast","description":"One farm-fresh sunny side up egg, tomato, and green peppers on a slice of our toast fresh from our bakehouse.","abbreviation":"ET","category_id":"#Breakfast Category","tax_ids":["#Sales Tax"],"variations":[{"type":"ITEM_VARIATION","id":"#Regular Sunny-Side Egg on Toast","is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"#Sunny-Side Egg on Toast","name":"Regular","pricing_type":"FIXED_PRICING","price_money":{"amount":495,"currency":"USD"}}}]}},{"type":"ITEM","id":"#Grilled Steak","item_data":{"name":"Grilled Steak","description":"Perfectly grilled flank steak that's been marinated in our award winning sauce, paired with fresh-from-the-farm veggies.","abbreviation":"BRF","category_id":"#Entree Category","tax_ids":["#Sales Tax"],"variations":[{"type":"ITEM_VARIATION","id":"#Regular Grilled Steak","is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"#Grilled Steak","name":"Regular","pricing_type":"FIXED_PRICING","price_money":{"amount":1195,"currency":"USD"}}}]}},{"type":"ITEM","id":"#Italian Sandwich","item_data":{"name":"Italian Sandwich","description":"Salami, capicolla, ham, provolone, fresh lettuce, peppers, onion, and olive oil served on our homemade sourdough. What more could you want in a sandwich?","abbreviation":"IS","category_id":"#Entree Category","tax_ids":["#Sales Tax"],"variations":[{"type":"ITEM_VARIATION","id":"#Regular Italian Sandwich","is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"#Italian Sandwich","name":"Regular","pricing_type":"FIXED_PRICING","price_money":{"amount":895,"currency":"USD"}}}]}},{"type":"ITEM","id":"#Meatballs","item_data":{"name":"Meatballs","description":"Lean grilled lamb meatballs served with fresh greens. Perfect for those on a ketogenic diet.","abbreviation":"MB","category_id":"#Entree Category","tax_ids":["#Sales Tax"],"variations":[{"type":"ITEM_VARIATION","id":"#Regular Meatballs","is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"#Meatballs","name":"Regular","pricing_type":"FIXED_PRICING","price_money":{"amount":695,"currency":"USD"}}}]}},{"type":"ITEM","id":"#Mediterranean Yogurt Bowl","item_data":{"name":"Mediterranean Yogurt Bowl","description":"Greek yogurt topped with olives, chopped peppers, cucumber, crispy chickpeas, beans, and figs. Served with our fresh homemade pita.","abbreviation":"MYB","category_id":"#Entree Category","tax_ids":["#Sales Tax"],"variations":[{"type":"ITEM_VARIATION","id":"#Regular Mediterranean Yogurt Bowl","is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"#Mediterranean Yogurt Bowl","name":"Regular","pricing_type":"FIXED_PRICING","price_money":{"amount":495,"currency":"USD"}}}]}},{"type":"ITEM","id":"#Oatmeal with Fruit","item_data":{"name":"Oatmeal with Fruit","description":"A classic hot breakfast comprised of our famous steel-cut oats topped with fruit and almond slices straight from locally owned farms.","abbreviation":"SB","category_id":"#Breakfast Category","tax_ids":["#Sales Tax"],"variations":[{"type":"ITEM_VARIATION","id":"#Regular Oatmeal with Fruit","is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"#Oatmeal with Fruit","name":"Regular","pricing_type":"FIXED_PRICING","price_money":{"amount":495,"currency":"USD"}}}]}},{"type":"ITEM","id":"#Pancakes with Fruit","item_data":{"name":"Pancakes with Fruit","description":"The fluffiest, most perfectly golden pancakes you've ever had topped with fresh fruit from local farms. Real Canadian maple syrup served on the side.","abbreviation":"PF","category_id":"#Breakfast Category","tax_ids":["#Sales Tax"],"variations":[{"type":"ITEM_VARIATION","id":"#Regular Pancakes with Fruit","is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"#Pancakes with Fruit","name":"Regular","pricing_type":"FIXED_PRICING","price_money":{"amount":995,"currency":"USD"}}}]}},{"type":"ITEM","id":"#Salmon with Zucchini","item_data":{"name":"Salmon with Zucchini","description":"Fresh caught Alaskan king salmon served on a bed of braised spinach and diced zucchini.","abbreviation":"SZ","category_id":"#Entree Category","tax_ids":["#Sales Tax"],"variations":[{"type":"ITEM_VARIATION","id":"#Regular Salmon with Zucchini","is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"#Salmon with Zucchini","name":"Regular","pricing_type":"FIXED_PRICING","price_money":{"amount":1495,"currency":"USD"}}}]}},{"type":"ITEM","id":"#Steak Tacos","item_data":{"name":"Steak Tacos","description":"Two tacos with flank steak marinated for a minimum of 24 hours in our award-winning marinade. Topped with a mix of fresh cilantro and cooling cucumber.","abbreviation":"ST","category_id":"#Entree Category","tax_ids":["#Sales Tax"],"variations":[{"type":"ITEM_VARIATION","id":"#Regular Steak Tacos","is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"#Steak Tacos","name":"Regular","pricing_type":"FIXED_PRICING","price_money":{"amount":695,"currency":"USD"}}}]}},{"type":"ITEM","id":"#Autumn Soup","item_data":{"name":"Autumn Soup","description":"The smoothest butternut squash soup you've ever had served with locally made goat cheese and toasted nuts.","abbreviation":"AS","tax_ids":["#Sales Tax"],"variations":[{"type":"ITEM_VARIATION","id":"#Regular Autumn Soup","is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"#Autumn Soup","name":"Regular","pricing_type":"FIXED_PRICING","price_money":{"amount":695,"currency":"USD"}}}]}}]}]}
}
},
statusCode: 400,
headers: {
‘content-type’: ‘application/json’,
‘square-version’: ‘2020-11-18’,
vary: ‘Origin, Accept-Encoding’,
‘x-content-type-options’: ‘nosniff’,
‘x-download-options’: ‘noopen’,
‘x-frame-options’: ‘SAMEORIGIN’,
‘x-permitted-cross-domain-policies’: ‘none’,
‘x-xss-protection’: ‘1; mode=block’,
date: ‘Sun, 06 Dec 2020 17:01:05 GMT’,
‘content-length’: ‘232’,
‘strict-transport-security’: ‘max-age=631152000; includeSubDomains; preload’,
connection: ‘close’
},
body: ‘{“errors”:[{“category”:“INVALID_REQUEST_ERROR”,“code”:“INVALID_VALUE”,“detail”:“Invalid object: Invalid Object with Id: #Regular Bacon Cheeseburger\n[merchant_token=MLKP43R9VHB7E] merchant currency GBP - currency in request USD.”}]}’,
result: { errors: [ [Object] ] },
errors: [
{
category: ‘INVALID_REQUEST_ERROR’,
code: ‘INVALID_VALUE’,
detail: ‘Invalid object: Invalid Object with Id: #Regular Bacon Cheeseburger\n’ +
‘[merchant_token=MLKP43R9VHB7E] merchant currency GBP - currency in request USD.’
}
]
}

C:\Users\micha\OneDrive\Desktop\node_orders-payments>npm test

[email protected] test C:\Users\micha\OneDrive\Desktop\node_orders-payments
NODE_ENV=sandbox nodemon -e js,pug ./bin/www

[nodemon] 1.19.4
[nodemon] to restart at any time, enter rs
[nodemon] watching dir(s): .
[nodemon] watching extensions: js,pug
[nodemon] starting node ./bin/www
Listening on http://localhost:3000
GET / 304 1357.914 ms - -
GET /stylesheets/main.css 200 5.475 ms - 4803
GET /stylesheets/products.css 200 6.819 ms - 6020
GET /js/products-page.js 200 2.880 ms - 2218
GET /stylesheets/header.css 200 2.424 ms - 736
GET / 304 1261.625 ms - -
GET /stylesheets/main.css 304 2.529 ms - -
GET /stylesheets/products.css 304 2.580 ms - -
GET /js/products-page.js 304 4.268 ms - -
GET /stylesheets/header.css 304 4.853 ms - -
GET / 304 1092.546 ms - -
GET /stylesheets/main.css 304 2.296 ms - -
GET /stylesheets/products.css 304 2.269 ms - -
GET /stylesheets/header.css 304 1.363 ms - -
GET /js/products-page.js 304 1.834 ms - -
GET / 304 1044.779 ms - -
GET /stylesheets/main.css 304 1.234 ms - -
GET /stylesheets/products.css 304 1.154 ms - -
GET /stylesheets/header.css 304 3.327 ms - -
GET /js/products-page.js 304 1.082 ms - -
GET / 304 1080.768 ms - -
GET /stylesheets/main.css 304 1.790 ms - -
GET /stylesheets/products.css 304 2.260 ms - -
GET /stylesheets/header.css 304 3.533 ms - -
GET /js/products-page.js 304 1.311 ms - -
GET / 304 1091.916 ms - -
GET /stylesheets/main.css 304 2.520 ms - -
GET /stylesheets/products.css 304 2.326 ms - -
GET /stylesheets/header.css 304 3.357 ms - -
GET /js/products-page.js 304 1.183 ms - -
GET / 304 1039.093 ms - -
GET /stylesheets/main.css 304 2.075 ms - -
GET /stylesheets/products.css 304 2.433 ms - -
GET /js/products-page.js 304 3.587 ms - -
GET /stylesheets/header.css 304 3.944 ms - -
GET / 304 1052.749 ms - -
GET /stylesheets/main.css 304 1.468 ms - -
GET /stylesheets/products.css 304 1.501 ms - -
GET /js/products-page.js 304 2.492 ms - -
GET /stylesheets/header.css 304 1.026 ms - -

I edited your request as you included your access token again, and again I will suggest that you replace it.

You can see the error in your paste above: merchant currency GBP - currency in request USD. You need to change the currency to GBP instead of USD. I believe this can be found in the the seed data: https://github.com/square/connect-api-examples/blob/master/connect-examples/v2/node_orders-payments/bin/script/sample-seed-data.json.

Sorry! Didnt see the token in the shell.

I have no replaced the USD with GBP but now I am getting back the same error as before:

Unauthorized
{
“errors”: [
{
“category”: “AUTHENTICATION_ERROR”,
“code”: “UNAUTHORIZED”,
“detail”: “Your request did not include an Authorization http header with an access token. The header value is expected to be of the format "Bearer TOKEN" (without quotation marks), where TOKEN is to be replaced with your access token (e.g. "Bearer ABC123def456GHI789jkl0"). For more information, see Using the REST API. If you are seeing this error message while using one of our officially supported client libraries, please report this to [email protected].”
}
]
}

This is the shell (I have checked for the token)

C:\Users\micha\OneDrive\Desktop\OrderAhead-master>npm run seed

[email protected] seed C:\Users\micha\OneDrive\Desktop\OrderAhead-master
NODE_ENV=sandbox node ./bin/script/seed-catalog.js generate

internal/modules/cjs/loader.js:883
throw err;
^

Error: Cannot find module ‘…/…/config.json’
Require stack:

  • C:\Users\micha\OneDrive\Desktop\OrderAhead-master\bin\script\seed-catalog.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object. (C:\Users\micha\OneDrive\Desktop\OrderAhead-master\bin\script\seed-catalog.js:20:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions…js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
    code: ‘MODULE_NOT_FOUND’,
    requireStack: [
    ‘C:\Users\micha\OneDrive\Desktop\OrderAhead-master\bin\script\seed-catalog.js’
    ]
    }
    Note: This command was run via npm module ‘win-node-env’
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! [email protected] seed: NODE_ENV=sandbox node ./bin/script/seed-catalog.js generate
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] seed script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\micha\AppData\Roaming\npm-cache_logs\2020-12-07T20_23_37_279Z-debug.log

C:\Users\micha\OneDrive\Desktop\OrderAhead-master>npm test

[email protected] test C:\Users\micha\OneDrive\Desktop\OrderAhead-master
NODE_ENV=sandbox node ./bin/www

It looks like it’s complaining about missing files; did you delete or move files around? Error: Cannot find module ‘…/…/config.json’.

The error around not passing authorization header implies the access token is not being set any longer either.

Hi, nothing has been moved / deleted / added, excluding the env file at the beginning. I downloaded all the files from GitHub