How Can I Resolve Unexpected Token Syntax Errors in My Code?

This topic was automatically generated from Slack. You can find the original thread here.

I am having trouble tracking down these code errors : Code Error
Unexpected token (3:0)
DETAILS

SyntaxError: Unexpected token (3:0)
    at pp$4.raise (/var/task/node_modules/@lambda-v2/builder-helpers/node_modules/acorn/dist/acorn.js:2927:15)
    at pp.unexpected (/var/task/node_modules/@lambda-v2/builder-helpers/node_modules/acorn/dist/acorn.js:698:10)
    at pp$3.parseExprAtom (/var/task/node_modules/@lambda-v2/builder-helpers/node_modules/acorn/dist/acorn.js:2326:12)
    at anonymous.parseExprAtom (/var/task/node_modules/@lambda-v2/builder-helpers/node_modules/acorn-node/lib/import-meta/index.js:27:102)
    at pp$3.parseExprSubscripts (/var/task/node_modules/@lambda-v2/builder-helpers/node_modules/acorn/dist/acorn.js:2129:21)
    at pp$3.parseMaybeUnary (/var/task/node_modules/@lambda-v2/builder-helpers/node_modules/acorn/dist/acorn.js:2106:19)
    at anonymous.parseMaybeUnary (/var/task/node_modules/@lambda-v2/builder-helpers/node_modules/acorn-node/lib/private-class-elements/index.js:151:54)
    at pp$3.parseExprOps (/var/task/node_modules/@lambda-v2/builder-helpers/node_modules/acorn/dist/acorn.js:2041:21)
    at pp$3.parseMaybeConditional (/var/task/node_modules/@lambda-v2/builder-helpers/node_modules/acorn/dist/acorn.js:2024:21)
    at pp$3.parseMaybeAssign (/var/task/node_modules/@lambda-v2/builder-helpers/node_modules/acorn/dist/acorn.js:1997:21)

RESULTS

Hi RoBey, could you share your code as well?

#!/bin/bash

# PipeDream environment variables
# Remember to replace these with the actual names in your workflow
ALERT_NAME="${_PIPEDREAM_WORKFLOW_NAME}_$(_PIPEDREAM_EVENT_NAME)"
ALERT_DESCRIPTION="${_PIPEDREAM_STEP_INPUT_ALERT_DESCRIPTION}"
ENTITY_KEY="${_PIPEDREAM_STEP_INPUT_ENTITY_KEY}"
OPSGENIE_API_KEY="${_PIPEDREAM_STEP_INPUT_OPSGENIE_API_KEY}" # Securely store API key as an environment variable

# OpsGenie API details
OPSGENIE_HOST="https://api.opsgenie.com"
OPSGENIE_PATH="/v2/alerts"

# Validate required inputs
if [[ -z "$ALERT_DESCRIPTION" || -z "$OPSGENIE_API_KEY" ]]; then
echo "Error: Missing required inputs. Please provide ALERT_DESCRIPTION and OPSGENIE_API_KEY in PipeDream workflow inputs."
exit 1
fi

# Construct alert payload with dynamic tags (optional)
tags=(pipedream) # Add other relevant tags as needed
if [[ -n "${_PIPEDREAM_STEP_INPUT_ADDITIONAL_TAGS}" ]]; then
additional_tags=( $(echo "${_PIPEDREAM_STEP_INPUT_ADDITIONAL_TAGS}" | tr ',' ' ') )
tags=("${tags[@]}" "${additional_tags[@]}")
fi
alert_payload="{
\"request\": \"createAlert\",
\"data\": {
\"userKey\": \"${OPSGENIE_API_KEY}\",
\"alert\": {
\"message\": \"${ALERT_NAME}\",
\"description\": \"${ALERT_DESCRIPTION}\",
\"priority\": \"P3\",
\"tags\": \"${tags[@]}\",
\"entity\": {
\"key\": \"${ENTITY_KEY}\"
}
}
}
}"

# Send alert to OpsGenie using curl
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${OPSGENIE_API_KEY}" \
-d "$alert_payload" "$OPSGENIE_HOST$OPSGENIE_PATH"

# Check for successful response
if [[ $? -eq 0 ]]; then
echo "P3 alert \"${ALERT_NAME}\" successfully created in OpsGenie."
else
echo "Error: Failed to create P3 alert in OpsGenie."
exit 1
fi

Got it, thanks.

Have you tried this bash script locally? Is it possible there’s a syntax error somewhere in there?

I have not tried locally but I can do that now.

Hopefully that helps, maybe it’ll give a more specific line if there is one.

There’s also Node.js & Python support too if you’d like to send payloads dynamically in a step.

I’m not seeing any syntax errors but the token message seems to imply the format of hte post is missing or incorrect at the “# send alert to opsgenie using curl " line. I did have issues forming the curl statement for Jira with “-d” instead of “–data” AND quotes within the data statement, I had to triple up on them. so instead of "request" i would have to use "”“request"”" so that may have something to do with it