- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
how to set variable in API
- Labels:
-
Apache Ambari
Created ‎02-22-2018 10:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
how to use API with variable inside the API
example , we replace the INSTALLED with ACTION=INSTALLED
and then we run the follwing
curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop AMBARI_METRICS via REST"}, "Body": {"ServiceIfo": {"state": "$ACTION"}}}' http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS
but the API not accepted the variable - $ACTION
please advice how to set the variable ACTION in the API so API will read this variable
example of API output when using the variable
HTTP/1.1 400 Bad Request X-Frame-Options: DENY X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff Cache-Control: no-store Pragma: no-cache Set-Cookie: AMBARISESSIONID=1t1s2senrg3mtqgzda2qp8yv6;Path=/;HttpOnly Expires: Thu, 01 Jan 1970 00:00:00 GMT User: admin Content-Type: text/plain Content-Length: 313
Created ‎02-22-2018 11:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One solution can be as following:
# export HOST=amb25101.example.com # export USER=admin # export PASSWD=admin # export ACTION=INSTALLED # export CLUSTER_NAME=plain_ambari # echo {"\"RequestInfo\": {\"context\" :\"Stop AMBARI_METRICS via REST\"}, \"Body\": {\"ServiceInfo\": {\"state\": \"$ACTION\"}}}" > /tmp/postData.txt # curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d@/tmp/postData.txt http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS
.
So basically we are doing the following thing differently:
# echo {"\"RequestInfo\": {\"context\" :\"Stop AMBARI_METRICS via REST\"}, \"Body\": {\"ServiceInfo\": {\"state\": \"$ACTION\"}}}" > /tmp/postData.txt # curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d@/tmp/postData.txt http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS
.
Created ‎02-22-2018 11:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One solution can be as following:
# export HOST=amb25101.example.com # export USER=admin # export PASSWD=admin # export ACTION=INSTALLED # export CLUSTER_NAME=plain_ambari # echo {"\"RequestInfo\": {\"context\" :\"Stop AMBARI_METRICS via REST\"}, \"Body\": {\"ServiceInfo\": {\"state\": \"$ACTION\"}}}" > /tmp/postData.txt # curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d@/tmp/postData.txt http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS
.
So basically we are doing the following thing differently:
# echo {"\"RequestInfo\": {\"context\" :\"Stop AMBARI_METRICS via REST\"}, \"Body\": {\"ServiceInfo\": {\"state\": \"$ACTION\"}}}" > /tmp/postData.txt # curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d@/tmp/postData.txt http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS
.
