curl works, but won't execute in BASH script

Viewed 9284

The following curl command works from the command line. I get a valid response from the server.

curl -X POST https://somebaseurl/api/v1/auth/login -H "Content-Type:application/json" -d '{"email": "foo@bar,com", "password": "foo"}'

However I am trying to write a BASH script like this

baseUrl=https://somebaseurl
contentTypeJson="\"Content-Type:application/json\""
credentials="'{\"email\": \"foo@bar.com",\"password\": \"foo\"}'"
login="curl -X POST $baseUrl/api/v1/auth/login -H $contentTypeJson -d $credentials"
 echo ${login}

response=`${login}`
echo ${response}

I get a bad request response from the server. However if I copy the echoed curl command directly into my terminal it works. What am I doing wrong?

edit:

As requested I get Bad Request For request 'POST api/v1/auth/login' [Expected application/json]

2 Answers
Related