CURL request fails with error msg "failed to decrypt request"

Viewed 34

I have implemented a CURL script to execute API call which requires encrypted string as data, But it gets failed with 'failed to decrypt request'. I have tried with python also (requests and Crypto modules) but failed with same error message.

#!/usr/bin/env bash
output=$(openssl enc -aes-256-cbc -pass pass:xxxxxxx -in msg.txt -base64)
curl -X POST \
    "https://api.swing.tradesmartonline.in/api/v1/login-token" \
    -H "Content-Type: application/json" \
    -d '{"data":"$output","app":"APPLICATION_ID"}'

Output is: {"status":"false","data":"","error_msg":"failed to decrypt request."}

Where as I am able to decrypt the message in local using below command

echo "$output" | openssl enc -aes-256-cbc -base64 -pass pass:xxxxxxx -d

Thanks in advance

1 Answers

The shell will not expand your variables in a single quoted string. Either:

  1. Use double quotes and escape embedded double quotes with \":
"{\"data\":\"$output\",\"app\":\"APPLICATION_ID\"}"
  1. Use single quotes for static text and double quotes for what contain variables (this means less escaping):
'{"data":"'"$output"'","app":"APPLICATION_ID"}'
Related