<?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 Re: REST API + HOW TO CAPTURE THE ID NUMBER FROM API in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/REST-API-HOW-TO-CAPTURE-THE-ID-NUMBER-FROM-API/m-p/220002#M74683</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;What you are seeing in the output of the API call is actually the HTTP Response which ambari has sent to the client.  &lt;/P&gt;&lt;PRE&gt;{
  "href": "http://localhost:8080/api/v1/clusters/sys15626/requests/128",
  "Requests": {
    "id": 128,
    "status": "Accepted"
   }
}&lt;/PRE&gt;&lt;P&gt;Above is a standard API response from ambari when a request is accepted. The only option to get only the ID part is to use the response parsing mechanism provided by OS like &lt;STRONG&gt;grep&lt;/STRONG&gt;. (Or using Custom parsing utility / third party APIs)&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;PRE&gt; # cat /tmp/response.txt |  grep id | awk '{print $NF}' | cut -d , -f1&lt;/PRE&gt;&lt;BR /&gt;</description>
    <pubDate>Sun, 18 Feb 2018 18:58:12 GMT</pubDate>
    <dc:creator>jsensharma</dc:creator>
    <dc:date>2018-02-18T18:58:12Z</dc:date>
    <item>
      <title>REST API + HOW TO CAPTURE THE ID NUMBER FROM API</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/REST-API-HOW-TO-CAPTURE-THE-ID-NUMBER-FROM-API/m-p/220001#M74682</link>
      <description>&lt;P&gt;how to capture the id request &lt;STRONG&gt;number&lt;/STRONG&gt; from API ?&lt;/P&gt;&lt;P&gt;for example we stop the service - AMBARI_METRICS  &lt;/P&gt;&lt;P&gt;and we get the id - &lt;STRONG&gt;128&lt;/STRONG&gt; from output , so we can use grep to capture the id  , but we prefer other elegant way , &lt;/P&gt;&lt;PRE&gt;curl -u admin:admin -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop AMBARI_METRICS via REST"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}' &lt;A href="http://localhost:8080/api/v1/clusters/sys15626/services/AMBARI_METRICS" target="_blank"&gt;http://localhost:8080/api/v1/clusters/sys15626/services/AMBARI_METRICS&lt;/A&gt;


HTTP/1.1 202 Accepted
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=19rvqn2cgzwb51sfevywdfvwm7;Path=/;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
User: admin
Content-Type: text/plain
Vary: Accept-Encoding, User-Agent
Content-Length: 137
Server: Jetty(8.1.19.v20160209)
{
  "href" : "http://localhost:8080/api/v1/clusters/sys15626/requests/128",
  "Requests" : {
    "id" : 128,
    "status" : "Accepted"
  }&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Feb 2018 18:50:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/REST-API-HOW-TO-CAPTURE-THE-ID-NUMBER-FROM-API/m-p/220001#M74682</guid>
      <dc:creator>mike_bronson7</dc:creator>
      <dc:date>2018-02-18T18:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: REST API + HOW TO CAPTURE THE ID NUMBER FROM API</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/REST-API-HOW-TO-CAPTURE-THE-ID-NUMBER-FROM-API/m-p/220002#M74683</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;What you are seeing in the output of the API call is actually the HTTP Response which ambari has sent to the client.  &lt;/P&gt;&lt;PRE&gt;{
  "href": "http://localhost:8080/api/v1/clusters/sys15626/requests/128",
  "Requests": {
    "id": 128,
    "status": "Accepted"
   }
}&lt;/PRE&gt;&lt;P&gt;Above is a standard API response from ambari when a request is accepted. The only option to get only the ID part is to use the response parsing mechanism provided by OS like &lt;STRONG&gt;grep&lt;/STRONG&gt;. (Or using Custom parsing utility / third party APIs)&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;PRE&gt; # cat /tmp/response.txt |  grep id | awk '{print $NF}' | cut -d , -f1&lt;/PRE&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 18 Feb 2018 18:58:12 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/REST-API-HOW-TO-CAPTURE-THE-ID-NUMBER-FROM-API/m-p/220002#M74683</guid>
      <dc:creator>jsensharma</dc:creator>
      <dc:date>2018-02-18T18:58:12Z</dc:date>
    </item>
  </channel>
</rss>

