'Bash script to make curl POST request based on file txt line used in data raw

I'm getting the code below

#!/bin/bash
input="processes.txt"
while IFS= read -r line
do
curl --location --request POST 'https://api.controllegal.zymdev.com/v2/getProcessesInfo' \
--header 'Content-Type: application/json' \
--data-raw '{
    "data":{
        "process_id": "$line",
        "location_id":"11001",
        "entity":"608-True-3110-11001"
    }
}'
done < "$input"

from Postman to make a cURL POST request and using it in a bash script to loop a txt file line and send it in the data json raw, but for some reason it returns

false

each time the curl get executed

when doing

echo $line

it prints fine the line string which is a something like "11001010200020160112400"

and if I use the string directly in the data-raw it works fine.

I tried using double quotes like

""$line""

but it throws

Unexpected token $ in JSON


Solution 1:[1]

In bash, a pair of single-quotes (') prevents variable substitution inside. You would need to do something like

--data-raw "{
    \"data\":{
    \"process_id\": \"$line\",
    ...
    "

so that the value of $line gets substituted.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dg99