I'm writing CURL COMMAND
HTTP_Method : POST
API : api/databricks/query
Request body {"query":" GRANT SELECT,READ_METADATA,USAGE on DATABASE `DB` to `userID` " }
The query,I have execute using POSTMAN it's working
curl --location --request POST 'https://<databick_workspace-url>/api/sql/databricks/query' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"GRANT SELECT,READ_METADATA,USAGE on DATABASE `DB-NAME` to `userID` " }
# Working, And user can access DB
I believe the problem is with backticks,
// Function
function grantReadAccess() {
local path="/api/sql/databricks/query"
local url="https://<databricks-workspace-url>/${path}"
printf 'curl %q' "${url}"
local DATABASENAME="DB-NAME"
local userID="userID"
local content="GRANT SELECT,READ_METADATA,USAGE on DATABASE \`${DATABASENAME}\` to \`${userID}\` "
echo "------------$content"
// OUTPUT Here : GRANT SELECT,READ_METADATA,USAGE on DATABASE `DB-NAME` to `userID`
// Same I have to pass in request body
local permissionToGroup=$(
curl -X POST "${url}" -H "Authorization: Bearer ${authtoken}" -H "Content-Type: application/json" -d '{ "query": \"'"${content}"'\" } ')
//Required in this {"query":"GRANT SELECT,READ_METADATA,USAGE on DATABASE `DB` to `userID` " }
echo "${permissionToGroup}"
}
// Tried In Postman insted of using backtick
1. Single Quote "'" {"query":"GRANT SELECT,READ_METADATA,USAGE on DATABASE 'DB' to 'userID' "
2. Blacket "(" {"query":"GRANT SELECT,READ_METADATA,USAGE on DATABASE (DB) to (userID) "
Error
{
"query": "grant SELECT, READ_METADATA, USAGE on DATABASE 'DB' to 'useID' ",
"data": null,
"error": " org.apache.spark.sql.catalyst.parser.ParseException: \nOperation not allowed: grant(line 1, pos 0)\n\n== SQL ==\ngrant SELECT, READ_METADATA, USAGE on DATABASE 'DB"
}
The above function is not working,
Always use a tool that understands JSON when you need to build JSON. In this context, the widely-accepted tool is for the job is jq.
curl -X POST "${url}" \
-H "Authorization: Bearer ${authtoken}" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg content "$content" '{"query": $content}')"
Your question is not very clear, but I'll guess you're having problems in this part:
-d '{ "query": \"'"${content}"'\" } '
That will get you literal backslashes before the double quotes around your content, since backslashes inside single quotes are inserted literally. You could swap that for -d '{ "query": "'"${content}"'" }' or -d "{ \"query\": \"${content}\" }"
Related
How to pass a string with whitespaces characters to a variable to curl command in windows cmd?
I have to pass a string variable that has white space characters to curl requests in windows cmd.
Below is the command.
set emailID="xxxx#gmail.com"
set openAPISpec="http://petstore/v2/swagger.json"
set licenseKey="ccc0e4-b000-491f-9d7b-7e59f9768"
set projectName="Online Banking REST API OmPf"
set MyDefault="dXNlcjFAbmV0YmFua2luZy5pbzphZG1pbjEyMyDefault"
set MyRoleAdmin="dXNlcjFAbmV0YmFua2luZy5pbzphZG1pbjEyMyRoleAdmin"
set MyRoleUser="dXNlcjFAbmV0YmFua2luZy5pbzphZG1pbjEyMyRoleUser"
curl -s --location --request POST "https://dev.ethicalcheck.qtech.ai/api/v1/scan" -H "Content-Type: application/json" -d "{ \"openAPISpec\": \"%openAPISpec%\", \"email\": \"%emailID%\", \"licenseKey\": \"%licenseKey%\", \"projectName\": \"%projectName%\", \"headers\":[\"Authorization: Bearer %MyDefault%\", \"Authorization: Bearer %MyRoleAdmin%\", \"Authorization: Bearer %MyRoleUser%\"] }"
When I run the above command in windows cmd below is the response
curl -s --location --request POST "https://dev.ethicalcheck.qtech.ai/api/v1/scan" -H "Content-Type: application/json" -d "{ \"openAPISpec\": \"%openAPISpec%\", \"email\": \"%emailID%\", \"licenseKey\": \"%licenseKey%\", \"projectName\": \"%projectName%\", \"headers\":[\"Authorization: Bearer %MyDefault%\", \"Authorization: Bearer %MyRoleAdmin%\", \"Authorization: Bearer %MyRoleUser%\"] }"
{"timestamp":"2022-10-19T03:03:39.094+00:00","status":400,"error":"Bad Request","path":"/api/v1/scan"}
The above command in windows CMD is working perfectly if the variable doesn't have whitespaces characters.
The same was the error I was getting in Linux bash, so I modified the above command accordingly to the Linux environment and it's working perfectly even for whitespaces characters in the variable.
Below is the working command in Linux if a variable has whitespaces characters in it.
export emailID="xxxx#gmail.com"
export openAPISpec="http://petstore/v2/swagger.json"
export licenseKey="ccc0e4-b000-491f-9d7b-7e59f9768"
export projectName="Online Banking REST API OmPf"
export MyDefault="dXNlcjFAbmV0YmFua2luZy5pbzphZG1pbjEyMyDefault"
export MyRoleAdmin="dXNlcjFAbmV0YmFua2luZy5pbzphZG1pbjEyMyRoleAdmin"
export MyRoleUser="dXNlcjFAbmV0YmFua2luZy5pbzphZG1pbjEyMyRoleUser"
curl -s --location --request POST "https://dev.ethicalcheck.qtech.ai/api/v1/scan" -H "Content-Type: application/json" --data-raw '{ "openAPISpec": "'${openAPISpec}'", "email": "'${emailID}'", "licenseKey": "'${licenseKey}'", "projectName": "'"${projectName}"'", "headers":["Authorization: Bearer '${MyDefault}'","Authorization: Bearer '${MyRoleAdmin}'","Authorization: Bearer '${MyRoleUser}'"] }'
Below is the actual thing that is working in Linux bash, I have added extra double quotations to handle whitespaces characters with the projectName variable, and with the email variable it's normal.
"projectName": "'"${projectName}"'"
"email": "'${emailID}'"
The same modification is not working in windows CMD or currently, I'm not able to figure out
#1 Tried to pass this way
\"projectName\": \"\'\"%projectName%\"\'\"
# Command
curl -s --location --request POST "https://api.ethicalcheck.apisec.ai/api/v1/scan" -H "Content-Type: application/json" -d "{ \"openAPISpec\": \"%openAPISpec%\", \"email\": \"%emailID%\", \"licenseKey\": \"%licenseKey%\", \"projectName\": \"\'\"%projectName%\"\'\", \"headers\":[\"Authorization: Bearer %MyDefault%\", \"Authorization: Bearer %MyRoleAdmin%\", \"Authorization: Bearer %MyRoleUser%\"] }"
# Response
{"timestamp":"2022-10-19T03:03:39.094+00:00","status":400,"error":"Bad Request","path":"/api/v1/scan"}
#2 Tried to pass this way
\"projectName\": \"\"%projectName%\"\"
# Command
curl -s --location --request POST "https://api.ethicalcheck.apisec.ai/api/v1/scan" -H "Content-Type: application/json" -d "{ \"openAPISpec\": \"%openAPISpec%\", \"email\": \"%emailID%\", \"licenseKey\": \"%licenseKey%\", \"projectName\": \"\"%projectName%\"\", \"headers\":[\"Authorization: Bearer %MyDefault%\", \"Authorization: Bearer %MyRoleAdmin%\", \"Authorization: Bearer %MyRoleUser%\"] }"
# Response
{"timestamp":"2022-10-19T03:03:39.094+00:00","status":400,"error":"Bad Request","path":"/api/v1/scan"}
So how do I pass a string with whitespaces characters as a variable to curl command in windows CMD?
This link why-is-no-string-output-with-echo-var-after-using-set-var-text-command-line helped in resolving the issue.
Thanks #Mofi
The below syntax worked for me.
set "emailID=xxxx#gmail.com"
set "openAPISpec=http://petstore/v2/swagger.json"
set "licenseKey=ccc0e4-b000-491f-9d7b-7e59f9768"
set "projectName=Online Banking REST API OmPf"
set "MyDefault=dXNlcjFAbmV0YmFua2luZy5pbzphZG1pbjEyMyDefault"
set "MyRoleAdmin=dXNlcjFAbmV0YmFua2luZy5pbzphZG1pbjEyMyRoleAdmin"
set "MyRoleUser=dXNlcjFAbmV0YmFua2luZy5pbzphZG1pbjEyMyRoleUser"
curl -s --location --request POST "https://dev.ethicalcheck.qtech.ai/api/v1/scan" -H "Content-Type: application/json" -d "{ \"openAPISpec\": \"%openAPISpec%\", \"email\": \"%emailID%\", \"licenseKey\": \"%licenseKey%\", \"projectName\": \"%projectName%\", \"headers\":[\"Authorization: Bearer %MyDefault%\", \"Authorization: Bearer %MyRoleAdmin%\", \"Authorization: Bearer %MyRoleUser%\"] }"
The first part of the script looks like:
curl -k -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "Cache-Control: no-cache" -d 'username=username&password=password "https://get_token" >> token.txt
token=$(<'token.txt'$'\r')
echo "$token"
The output from echo $token looks fine(417 characters):
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyTVd0bGo4Y1VPYW8xNmdZTlV4QWlFS3RLcTc1b2JsSEN0c3hKWnlxeExCTkRKb1wvKzNSK1l5XC9YUFhoWExLaytJRVdKSE5CTE9MZmxPNksxemFjYXVlM0t1NnFIQjNRXC9QeUxzUTdVSmVOYk9pS3FDeHhcLzk1dz09IiwibmJmIjoxNDgzOTg5NjgwLCJpc3MiOiJwaHgtcmVtc3QtMDAzIiwiX2NhY2hlSWQiOjE0MzA0OCwiZXhwIjoxNDgzOTkzNDAwLCJpYXQiOjE0ODM5ODk4MDAsImp0aSI6IklER0FBNVYwR1pNU0pBTzk5QlVXTzhOMDY5VlRGTiJ9.H3vD-WfZBFXOII4k-cy7Ey2QM9YXytp31m9-Huj9vKw
Let's see what happens when I try to insert the token into the next part of the script.
echo curl -k -X POST -H "Content-Type: application/json" -H "Authorization: AR-JWT "$token"" -H "Cache-Control: no-cache" -d '{
"values":{
"First_Name": "John",
"Last_Name": "Doe",
}
} ' "https://randomurl.com"
Here is the output:
curl -k -X POST -H Content-Type: application/json -H Authorization: AR-JWT eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyTVd0bGo4Y1VPYW8xNmdZTlV4QWlFS3RLcTc1b2JsSEN0c3hKWnlxeExCTkRKb1wvKzNSK1l5XC9YUFhoWExLaytJRVdKSE5CTE9MZmxPNksxemFjYXVlM0t1NnFIQjNRXC9QeUxzUTdVSmVOYk9pS3FDeHhcLzk1dz0 -H Cache-Control: no-cache -d { OiJwaHgtcmVtc3QtMDAzIiwiX2NhY2hlSWQiOjE0MzA0OCwiZXhwIjoxNDgzOTkzNDAwLCJpYXQiOjE0ODM5ODk4MDAsImp0aSI6IklER0FBNVYwR1pNU0pBTzk5QlVXTzhOMDY5VlRGTiJ9.H3vD-WfZBFXOII4k-cy7Ey2QM9YXytp31m9-Huj9vKw
"values":{
"First_Name": "John",
"Last_Name": "Doe",
}
} https://randomurl.com
2 Things happen when the token is passed in
"9IiwibmJmIjoxNDgzOTg5NjgwLCJpc3Mi" within the token gets deleted
The 2nd half of the token(After the deleted part) gets inserted into the body
What I've tried:
Using a different token
Use token without passing it into a file first
Moving the Authorization header before the URL
All of these results in the same behavior.
I'm using cygwin64 on Windows 7
When the second cURL command is typed with full token in the correct space into cygwin, it works no problem
Output when set-x is added to the script:
$ ./variable_testing.sh
+ ./variable_testing.sh
+ token=$'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyTVd0bGo4Y1VPYW8xNmdZTlV4QWlFS3RLcTc1b2JsSEN0c3hKWnlxeExCTkRKb1wvKzNSK1l5XC9YUFhoWExLaytJRVdKSE5CTE9MZmxPNksxemFjYXVlM0t1NnFIQjNRXC9QeUxzUTdVSmVOYk9pS3FDeHhcLzk1dz09IiwibmJmIjoxNDgzOTg5NjgwLCJpc3MiOiJwaHgtcmVtc3QtMDAzIiwiX2NhY2hlSWQiOjE0MzA0OCwiZXhwIjoxNDgzOTkzNDAwLCJpYXQiOjE0ODM5ODk4MDAsImp0aSI6IklER0FBNVYwR1pNU0pBTzk5QlVXTzhOMDY5VlRGTiJ9.H3vD-WfZBFXOII4k-cy7Ey2QM9YXytp31m9-Huj9vKw\r'
+ echo $'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyTVd0bGo4Y1VPYW8xNmdZTlV4QWlFS3RLcTc1b2JsSEN0c3hKWnlxeExCTkRKb1wvKzNSK1l5XC9YUFhoWExLaytJRVdKSE5CTE9MZmxPNksxemFjYXVlM0t1NnFIQjNRXC9QeUxzUTdVSmVOYk9pS3FDeHhcLzk1dz09IiwibmJmIjoxNDgzOTg5NjgwLCJpc3MiOiJwaHgtcmVtc3QtMDAzIiwiX2NhY2hlSWQiOjE0MzA0OCwiZXhwIjoxNDgzOTkzNDAwLCJpYXQiOjE0ODM5ODk4MDAsImp0aSI6IklER0FBNVYwR1pNU0pBTzk5QlVXTzhOMDY5VlRGTiJ9.H3vD-WfZBFXOII4k-cy7Ey2QM9YXytp31m9-Huj9vKw\r\r'
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyTVd0bGo4Y1VPYW8xNmdZTlV4QWlFS3RLcTc1b2JsSEN0c3hKWnlxeExCTkRKb1wvKzNSK1l5XC9YUFhoWExLaytJRVdKSE5CTE9MZmxPNksxemFjYXVlM0t1NnFIQjNRXC9QeUxzUTdVSmVOYk9pS3FDeHhcLzk1dz09IiwibmJmIjoxNDgzOTg5NjgwLCJpc3MiOiJwaHgtcmVtc3QtMDAzIiwiX2NhY2hlSWQiOjE0MzA0OCwiZXhwIjoxNDgzOTkzNDAwLCJpYXQiOjE0ODM5ODk4MDAsImp0aSI6IklER0FBNVYwR1pNU0pBTzk5QlVXTzhOMDY5VlRGTiJ9.H3vD-WfZBFXOII4k-cy7Ey2QM9YXytp31m9-Huj9vKw
+ echo curl -k -X POST -H '"Content-Type:' 'application/json"' -H '"Authorization:' AR-JWT 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyTVd0bGo4Y1VPYW8xNmdZTlV4QWlFS3RLcTc1b2JsSEN0c3hKWnlxeExCTkRKb1wvKzNSK1l5XC9YUFhoWExLaytJRVdKSE5CTE9MZmxPNksxemFjYXVlM0t1NnFIQjNRXC9QeUxzUTdVSmVOYk"' -H '"Cache-Control:' 'no-cache"' -d '{ LCJpc3MiOiJwaHgtcmVtc3QtMDAzIiwiX2NhY2hlSWQiOjE0MzA0OCwiZXhwIjoxNDgzOTkzNDAwLCJpYXQiOjE0ODM5ODk4MDAsImp0aSI6IklER0FBNVYwR1pNU0pBTzk5QlVXTzhOMDY5VlRGTiJ9.H3vD-WfZBFXOII4k-cy7Ey2QM9YXytp31m9-Huj9vKw
"values":{
"First_Name": "John",
"Last_Name": "Doe",
}
} ' $'https://randomurl.com\r'
curl -k -X POST -H "Content-Type: application/json" -H "Authorization: AR-JWT eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyTVd0bGo4Y1VPYW8xNmdZTlV4QWlFS3RLcTc1b2JsSEN0c3hKWnlxeExCTkRKb1wvKzNSK1l5XC9YUFhoWExLaytJRVdKSE5CTE9MZmxPNksxemFjYXVlM0t1NnFIQjNRXC9QeUxzUTdVSmVOYk9pS3FDeHhcLzk1" -H "Cache-Control: no-cache" -d { OiJwaHgtcmVtc3QtMDAzIiwiX2NhY2hlSWQiOjE0MzA0OCwiZXhwIjoxNDgzOTkzNDAwLCJpYXQiOjE0ODM5ODk4MDAsImp0aSI6IklER0FBNVYwR1pNU0pBTzk5QlVXTzhOMDY5VlRGTiJ9.H3vD-WfZBFXOII4k-cy7Ey2QM9YXytp31m9-Huj9vKw
"values":{
"First_Name": "John",
"Last_Name": "Doe",
}
} https://randomurl.com
Full, simplified script that that displays output above
#!/bin/bash
set -x logs
token="eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyTVd0bGo4Y1VPYW8xNmdZTlV4QWlFS3RLcTc1b2JsSEN0c3hKWnlxeExCTkRKb1wvKzNSK1l5XC9YUFhoWExLaytJRVdKSE5CTE9MZmxPNksxemFjYXVlM0t1NnFIQjNRXC9QeUxzUTdVSmVOYk9pS3FDeHhcLzk1dz09IiwibmJmIjoxNDgzOTg5NjgwLCJpc3MiOiJwaHgtcmVtc3QtMDAzIiwiX2NhY2hlSWQiOjE0MzA0OCwiZXhwIjoxNDgzOTkzNDAwLCJpYXQiOjE0ODM5ODk4MDAsImp0aSI6IklER0FBNVYwR1pNU0pBTzk5QlVXTzhOMDY5VlRGTiJ9.H3vD-WfZBFXOII4k-cy7Ey2QM9YXytp31m9-Huj9vKw"
echo "$token"
echo curl -k -X POST -H \"Content-Type: application/json\" -H \"Authorization: AR-JWT $token\" -H \"Cache-Control: no-cache\" -d '{
"values":{
"First_Name": "John",
"Last_Name": "Doe",
}
} ' "https://randomurl.com"
First: Your token currently has literal CRs in it -- the apparent butchering is caused by those CRs being printed in your echo output, moving the cursor back to the beginning of the line so parts of your token get overwritten with later content. To eliminate them, you can either convert the file into UNIX text format (and ensure that there aren't CRs in any of the commands generating that file), or you can use:
token=$(<token.txt) # read token.txt into "token" variable
token=${token//$'\r'/} # strip CRs from token variable
If you want to pass the Authorization header to curl as a single word, don't end and reinitialize your quotes; keep that single argument inside one set of syntactic quotes.
-H "Authorization: AR-JWT $token"
Finally, make sure your script itself is in UNIX format -- that your editor isn't saving it with DOS newlines.
I'm currently trying to make a DDNS script that interacts with the Cloudflare API to catch changes in my ip address and automatically fix the ip address change for my web server. Everything is working correctly so far except I can't get $IP to be put properly in the curl statement. I first run a python script from within the bash script to get the ip address, then run the curl statement in the bash script. Here's what the python script looks like (it returns an ip address like "1.1.1.1" with quotations included because the curl command requires the quotations)
#!/usr/bin/python3
import subprocess as sp
def main():
command = "dig +short myip.opendns.com #resolver1.opendns.com";
ip = sp.check_output(command, shell=True).decode('utf-8').strip('\n');
ip_tmp = ip;
ip_tmp = '"' + ip + '"';
ip = ip_tmp;
print(ip);
if __name__ == "__main__":
main();
And the bash script looks like this:
#!/bin/bash
IP=$("./getIP.py")
curl -X PUT "https://api.cloudflare.com/client/v4/zones/zone_id/dns_records/dns_id" \
-H "X-Auth-Email: example.com" \
-H "X-Auth-Key: authkey" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":"example.com","content":$IP,"ttl":120,"proxied":true}'
I've tried to have the python script only return numbers and then added the quotations in the bash script and now vice versa and I can't seem to get it to work. The last line should end up looking like this once the variable replaces with quotations around the ip address:
'{"type":"A","name":"example.com","content":"127.0.0.1","ttl":120,"proxied":true}'
The single quotes around your json structure prevent the variable from expanding.
You have a few options that are readily available.
Ugly quote escaping inside/around your json.
"{\"type\":\"A\",\"name\":\"example.com\",\"content\":$IP,\"ttl\":120,\"proxied\":true}"
Having the python write this data to a file and telling curl to use that file for the source of the post data.
curl -X PUT "https://api.cloudflare.com/client/v4/zones/zone_id/dns_records/dns_id" \
-H "X-Auth-Email: example.com" \
-H "X-Auth-Key: authkey" \
-H "Content-Type: application/json" \
--data #file_you_wrote_your_json_to.json
Using the python requests or urllib modules to issue the request to cloud flare.
Update your main() function to return the IP instead of print it.
my_ip = main()
url = "https://api.cloudflare.com/client/v4/zones/zone_id/dns_records/dns_id"
myheaders = {
"X-Auth-Email": "example.com",
"X-Auth-Key": "authkey",
"Content-Type": "application/json"
}
myjson = {
"type":"A",
"name":"example.com",
"content":my_ip,
"ttl":120,
"proxied":true
}
requests.put(url, headers=myheaders, data=myjson)
Better yet, just do it in bash. Cloudflare DDNS on github.
One shot to fetch the dynamic A-record ID:
curl -X GET "https://api.cloudflare.com/client/v4/zones/**Zone ID** \
/dns_records?type=A&name=dynamic" \
-H "Host: api.cloudflare.com" \
-H "User-Agent: ddclient/3.9.0" \
-H "Connection: close" \
-H "X-Auth-Email: example#example.com" \
-H "X-Auth-Key: "**Authorization key**" \
-H "Content-Type: application/json"
Cron job (* * * * *) to set the dynamic A-record:
#/usr/bin/env sh
AUTH_EMAIL=example#example.com
AUTH_KEY=** CF Authorization key **
ZONE_ID=** CF Zone ID **
A_RECORD_NAME="dynamic"
A_RECORD_ID=** CF A-record ID from cloudflare-dns-id.sh **
IP_RECORD="/tmp/ip-record"
RECORDED_IP=`cat $IP_RECORD`
PUBLIC_IP=$(curl --silent https://api.ipify.org) || exit 1
if [ "$PUBLIC_IP" = "$RECORDED_IP" ]; then
exit 0
fi
echo $PUBLIC_IP > $IP_RECORD
RECORD=$(cat <<EOF
{ "type": "A",
"name": "$A_RECORD_NAME",
"content": "$PUBLIC_IP",
"ttl": 180,
"proxied": false }
EOF
)
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID \
/dns_records/$A_RECORD_ID" \
-X PUT \
-H "Content-Type: application/json" \
-H "X-Auth-Email: $AUTH_EMAIL" \
-H "X-Auth-Key: $AUTH_KEY" \
-d "$RECORD"
I know how to store a string as a variable, for example: API="http://localhost:4741"
However, for the sake of a CURL request I would like to be able to store on object as a variable that I can access values on, something like OBJ="{name : Joe}". Is this possible?
Right now my CURL request looks like this:
curl --include --request POST localhost:3000/scrape \
--header "Content-Type: application/json" \
--data '{
"url": "http://www.oddsshark.com/stats/gamelog/basketball/nba/20736",
"team": "LA Clippers"
}'
I would like to be able to do something like this, using a dictionary or an object:
TEAM=( ["Clippers"]="http://www.oddsshark.com/stats/gamelog/basketball/nba/20736" )
curl --include --request POST localhost:3000/scrape \
--header "Content-Type: application/json" \
--data '{
"url": "http://www.oddsshark.com/stats/gamelog/basketball/nba/20736",
"team": "${TEAM[Clippers]}"
}'
hello I have this script in bash:
first part : authentication against server - works fine.
second part: adds user - and this works fine when I define user directly in curl code - but when I want to add user from parameters.. then I got a message error:
"{"code":400,"reason":"Bad Request","message":"The request could not
be processed because the provided content is not valid
JSON","detail":"Unexpected character ('$' (code 36)): expected a valid
value (number, String, array, object, 'true', 'false' or 'null')\n at
[Source: org.apache.catalina.connector.CoyoteInputStream#3a248e6a;
line: 2, column: 18]"}"
Any ideas how can I pass values to this script ? :)
Regards
#!/bin/bash
adm_user="admin"
adm_pass="secret"
user_name=""
user_pass=""
auth_url="http://url/OpenAM-11.0.0/json/authenticate"
add_user_url="http://url/OpenAM-11.0.0/json/users/?_action=create"
session_id=$(curl \
--request POST --header "X-OpenAM-Username: $adm_user " \
--header "X-OpenAM-Password: $adm_pass" \
--header "Content-Type: application/json" \
--data "{}" $auth_url | cut -d"\"" -f4 )
sleep 1
curl \
--request POST \
--header "iplanetDirectoryPro: $session_id" \
--header "Content-Type: application/json" \
--data \
'{
"username": "$1",
"userpassword": "secret12",
"mail": "bjensen#example.com"
}' \
$add_user_url
OK, mates I got the answer:
'{
"username": "'"$1"'",
"userpassword": "'"$2"'" ,
"mail": "bjensen#example.com"
}' \