Drew
Drew

Reputation: 33

Use Variable in CURL GET

I feel that I am just missing something very silly and not quoting/escaping something as I should, but I've been reading and testing for a solid amount of time now, and just can't get this to work.

I have a CSV file with data like the below:

TESTING.csv

17A3120UAXF-AA002771,9911017093
S150Y52157201,9911008933
17A3120UAXF-AA004545,9911016519
S170Y13084226,9911024365
S160Y45021270,9911018486

For the first part of my script, I need to read the second variable (ie. the items starting with "99110...")

I am parsing this data into a CURL while loop to sequence through all lines in the file. My bash script is like the below at this time:

#!/bin/bash

while IFS=, read -r device account; do
echo "device : $device"
echo "account : $account"
curl -X GET --header "Content-Type: application/json" --user username:password --verbose 'https://www.website.com:8444/api/subscriber?account=$account'
done < TESTING.csv

The issue that I'm running into is that while the "echo" statements are able to correctly pull/show the variable that I'm wanting to pass, this same information is not being passed into my CURL commands. When I run my script, the output is like the below:

device : 17A3120UAXF-AA002771
account : 9911017093
* About to connect() to www.website.com port 8444 (#0)
*   Trying 8.8.8.8...
* Connected to www.website.com (8.8.8.8) port 8444 (#0)
* Server auth using Basic with user 'username'
> GET /api/subscriber?account=$account HTTP/1.1
> Authorization: Basic madeUpJunkAndNumbers12345==
> User-Agent: curl/7.29.0
> Host: www.website.com:8444
> Accept: */*
> Content-Type: application/json
>
< HTTP/1.1 404 Not Found
< Content-Type: application/json
< Content-Length: 0
<
* Connection #0 to host www.website.com left intact
^C

Upvotes: 1

Views: 2024

Answers (1)

Poshi
Poshi

Reputation: 5762

You are using single quotes int the URL, so the variables don't get expanded. Use double quotes:

curl -X GET --header "Content-Type: application/json" --user username:password --verbose "https://www.website.com:8444/api/subscriber?account=$account"

Upvotes: 2

Related Questions