Hi xurei,
I'm trying to write a bash script to send a message with nimrod via cURL. It works when I hard code the API key and message into the cURL command, but I can't get it to work when I try to use them in variables. I've tried changing the quotes (') to (") so the variable is not taken literally, but it still fails. For example, this code:
API_KEY=99x9999-x9x9-9x9x-9999999999 # Changed for privacy
MSG="This is a test"
curl -X POST -H "Content-Type: application/json" -d "{
'api_key': '$API_KEY',
'message': '$MSG'
}" "https://www.nimrod-messenger.io/api/v1/message"
Gives this error:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>SyntaxError: Unexpected token ' in JSON at position 3<br> at JSON.parse (<anonymous>)<br> at parse (/var/www/nimrod/node_modules/body-parser/lib/types/json.js:88:17)<br> at /var/www/nimrod/node_modules/body-parser/lib/read.js:116:18<br> at invokeCallback (/var/www/nimrod/node_modules/raw-body/index.js:262:16)<br> at done (/var/www/nimrod/node_modules/raw-body/index.js:251:7)<br> at IncomingMessage.onEnd (/var/www/nimrod/node_modules/raw-body/index.js:307:7)<br> at IncomingMessage.emit (node:events:406:35)<br> at IncomingMessage.emit (node:domain:475:12)<br> at endReadableNT (node:internal/streams/readable:1343:12)<br> at processTicksAndRejections (node:internal/process/task_queues:83:21)</pre>
</body>
</html>
Any ideas how to resolve this?
Thanks.
Hi xurei,
I'm trying to write a bash script to send a message with nimrod via cURL. It works when I hard code the API key and message into the cURL command, but I can't get it to work when I try to use them in variables. I've tried changing the quotes (') to (") so the variable is not taken literally, but it still fails. For example, this code:
Gives this error:
Any ideas how to resolve this?
Thanks.