Unexpected token \ in JSON at position 1 in chapter test-the-apis

I’m on windows VS code using git bash.
npx aws-api-gateway-cli-test … --body “{“content”:“helloworld”,“attachment”:“hello.jpg”}”

This is giving me -
undefined:1
{\content:\helloworld,\attachment:\hello.jpg}
^
SyntaxError: Unexpected token \ in JSON at position 1

The same thing when I tried on cmd prompt gives the same error.

By looking at other solutions on git I tried
“{“content”:“helloworld”,“attachment”:“hello.jpg”}”

‘{“content”:“helloworld”,“attachment”:“hello.jpg”}’

are still giving me similar errors.

Try removing the JSON.parse from your function.

I notice in prod, you need JSON.parse while you don’t when you’re testing. It might be the other way around but test both cases and see.

this was a huge pain to troubleshoot but I ended up having success with the following on Windows:

npx aws-api-gateway-cli-test --username='admin@example.com' --password='Passw0rd!' --user-pool-id='...' --app-client-id='...' --cognito-region='...' --identity-pool-id='...' --invoke-url='...' --api-gateway-region='...' --path-template='/notes' --method='POST' --body='{\"content\":\"helloworld\",\"attachment\":\"hello.jpg\"}'

Leaving a plain text version below as well for posterity / certainty that the code block formatting doesn’t mess anything up:

npx aws-api-gateway-cli-test --username=‘admin@example.com’ --password=‘Passw0rd!’ --user-pool-id=’…’ --app-client-id=’…’ --cognito-region=’…’ --identity-pool-id=’…’ --invoke-url=’…’ --api-gateway-region=’…’ --path-template=’/notes’ --method=‘POST’ --body=’{“content”:“helloworld”,“attachment”:“hello.jpg”}’

Make sure to note that you will have to plug in the appropriate values for your env for the ...'s I have in the example snippet. Main issues I noticed from the content provided in the course (Secure Our Serverless APIs) were issues with aligning the quotes (i.e. opening and closing quotes potentially getting misplaced / unintentionally plugged in during copy/paste etc.) and the space in ‘hello world’ getting bungled up by the terminal upon attempting to interpret it.

Only advice would be to be careful about copying pasting anything that will affect any of the quotes throughout the snippet (i.e. plug the values directly into the quotes instead)

Hope this helps someone down the line…! ^^^