Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

how to set variable in API

avatar

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 
Michael-Bronson
1 ACCEPTED SOLUTION

avatar
Master Mentor

@Michael Bronson

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

.

View solution in original post

1 REPLY 1

avatar
Master Mentor

@Michael Bronson

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

.