0

I am executing the below command inside the shell script:

CURL_RESPONSE=`curl --request POST "$1" --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'grant_type="$4"' --data-urlencode 'scope=operator test' --data-urlencode 'client_id=$2' --data-urlencode 'client_secret=$3' -s

But when i am running the script, getting below error:

`curl Response is {"code":"400","description":"Invalid grant_type. Only client_testcred is accepted"}
`

I am passing client_testcred in $4 actually.

CURL_RESPONSE=`curl --request POST "$1" --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'grant_type="$4"' --data-urlencode 'scope=operator test' --data-urlencode 'client_id=$2' --data-urlencode 'client_secret=$3' -s

Even i tried below command using args, but doesn't work:

args=(--request POST "$1" --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'grant_type=client_credentials' --data-urlencode 'scope=operator supervisor' --data-urlencode 'client_id=$2' --data-urlencode 'client_secret=$3' -s) CURL_RESPONSE=curl "${args[@]}"``

I am expecting a token as output in CURL_RESPONSE.

  • 1
    Put a valid [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) and paste your script at https://shellcheck.net for validation/recommendation. – Jetchisel Apr 17 '23 at 09:28
  • 1
    `'client_id=$2'` does not expand the value of `$2`. It needs double quotes instead `"client_id=$2"`. Same problem with `'client_secret=$3'` should be `"client_secret=$3"` – Léa Gris Apr 17 '23 at 09:30
  • Parameters inside backquotes **are** expanded. However, your `$4` for instance lives between single quotes, and single quotes inside backquotes do keep their meaning. Aside of this, please don't use backquotes anymore; they are an obsolete feature. – user1934428 Apr 17 '23 at 12:44

1 Answers1

0

You are not passing $4 correctly.

Try this:

CURL_RESPONSE=$(curl --request POST "$1" --header "Content-Type: application/x-www-form-urlencoded" --data-urlencode "grant_type=$4" --data-urlencode "scope=operator test" --data-urlencode "client_id=$2" --data-urlencode "client_secret=$3" -s)
AVTUNEY
  • 923
  • 6
  • 11