<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question how to set variable in API in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-set-variable-in-API/m-p/222587#M74854</link>
    <description>&lt;P&gt;how to use API with variable inside the API&lt;/P&gt;&lt;P&gt;example , we replace the INSTALLED with &lt;STRONG&gt;ACTION=&lt;/STRONG&gt;&lt;STRONG&gt;INSTALLED&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;and then we run the follwing&lt;/P&gt;&lt;PRE&gt;curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop AMBARI_METRICS via REST"}, "Body": {"ServiceIfo": {"state": "$ACTION"}}}' &lt;A href="http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS" target="_blank"&gt;http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS&lt;/A&gt;&lt;/PRE&gt;&lt;P&gt;but the API not accepted the variable - &lt;STRONG&gt;$&lt;/STRONG&gt;&lt;STRONG&gt;ACTION&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;please advice how to set the variable ACTION in the API so API will read this variable &lt;/P&gt;&lt;P&gt;example of API output when using the variable&lt;/P&gt;&lt;PRE&gt;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 &lt;/PRE&gt;</description>
    <pubDate>Thu, 22 Feb 2018 18:30:17 GMT</pubDate>
    <dc:creator>mike_bronson7</dc:creator>
    <dc:date>2018-02-22T18:30:17Z</dc:date>
    <item>
      <title>how to set variable in API</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-set-variable-in-API/m-p/222587#M74854</link>
      <description>&lt;P&gt;how to use API with variable inside the API&lt;/P&gt;&lt;P&gt;example , we replace the INSTALLED with &lt;STRONG&gt;ACTION=&lt;/STRONG&gt;&lt;STRONG&gt;INSTALLED&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;and then we run the follwing&lt;/P&gt;&lt;PRE&gt;curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop AMBARI_METRICS via REST"}, "Body": {"ServiceIfo": {"state": "$ACTION"}}}' &lt;A href="http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS" target="_blank"&gt;http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS&lt;/A&gt;&lt;/PRE&gt;&lt;P&gt;but the API not accepted the variable - &lt;STRONG&gt;$&lt;/STRONG&gt;&lt;STRONG&gt;ACTION&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;please advice how to set the variable ACTION in the API so API will read this variable &lt;/P&gt;&lt;P&gt;example of API output when using the variable&lt;/P&gt;&lt;PRE&gt;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 &lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Feb 2018 18:30:17 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-set-variable-in-API/m-p/222587#M74854</guid>
      <dc:creator>mike_bronson7</dc:creator>
      <dc:date>2018-02-22T18:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to set variable in API</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-set-variable-in-API/m-p/222588#M74855</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/26229/uribarih.html" nodeid="26229"&gt;@Michael Bronson&lt;/A&gt;&lt;/P&gt;&lt;P&gt;One solution can be as following:&lt;/P&gt;&lt;PRE&gt;# 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\"}}}" &amp;gt; /tmp/postData.txt
# curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d@/tmp/postData.txt &lt;A href="http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS" target="_blank"&gt;http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS&lt;/A&gt;&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;So basically we are doing the following thing differently:&lt;/P&gt;&lt;PRE&gt;# echo {"\"RequestInfo\": {\"context\" :\"Stop AMBARI_METRICS via REST\"}, \"Body\": {\"ServiceInfo\": {\"state\": \"$ACTION\"}}}" &amp;gt; /tmp/postData.txt

# curl -u $USER:$PASSWD -i -H 'X-Requested-By: ambari' -X PUT -d@/tmp/postData.txt &lt;A href="http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS" target="_blank"&gt;http://$HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/AMBARI_METRICS&lt;/A&gt;&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 19:04:04 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-set-variable-in-API/m-p/222588#M74855</guid>
      <dc:creator>jsensharma</dc:creator>
      <dc:date>2018-02-22T19:04:04Z</dc:date>
    </item>
  </channel>
</rss>

