<?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: variable not taking value inside rest api in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/234002#M67456</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/19322/mishraanurag643.html" nodeid="19322" target="_blank"&gt;@Anurag Mishra&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You should use extra single quotes as&lt;STRONG&gt; &lt;/STRONG&gt;"&lt;STRONG&gt;'${password}'&lt;/STRONG&gt;"&lt;STRONG&gt; &lt;/STRONG&gt; and &lt;STRONG&gt; &lt;/STRONG&gt;"&lt;STRONG&gt;'${username}'&lt;/STRONG&gt;"&lt;/P&gt;&lt;P&gt;Notice:&lt;/P&gt;&lt;PRE&gt;"'${password}'"&lt;/PRE&gt;&lt;P&gt;And&lt;/P&gt;&lt;PRE&gt;"'${username}'"&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;# export username=test112233
# export password=test112233_password
# export Ambariuser=admin
# export ambaripass=admin

# curl -iv -u $Ambariuser:$ambaripass -H "X-Requested-By: ambari" -X POST  -d '{"Users/user_name":"'${username}'","Users/password":"'${password}'","Users/active":"true","Users/admin":"false"}' &lt;A href="http://localhost:8080/api/v1/users" target="_blank" rel="nofollow noopener noreferrer"&gt;http://localhost:8080/api/v1/users&lt;/A&gt;&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Output:&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="38467-curl-user-creation.png" style="width: 1298px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/14685i2D7B05B43B46C78D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="38467-curl-user-creation.png" alt="38467-curl-user-creation.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 18 Aug 2019 00:07:44 GMT</pubDate>
    <dc:creator>jsensharma</dc:creator>
    <dc:date>2019-08-18T00:07:44Z</dc:date>
    <item>
      <title>variable not taking value inside rest api</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/233995#M67449</link>
      <description>&lt;P&gt;curl -iv -u $Ambariuser:$ambaripass -H "X-Requested-By: ambari" -X POST -d '{"Users/user_name":"$username","Users/password":"$password","Users/active":"true","Users/admin":"false"}' &lt;A href="http://$localhost:8080/api/v1/users" target="_blank"&gt;http://$localhost:8080/api/v1/users&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I am executing this curl command to create user, but $username does not replace what I am passing instead it is passing as $username only, and user been created as $username&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 15:40:55 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/233995#M67449</guid>
      <dc:creator>amol_08</dc:creator>
      <dc:date>2017-08-30T15:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: variable not taking value inside rest api</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/233996#M67450</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/3418/jsensharma.html" nodeid="3418"&gt;@Jay SenSharma&lt;/A&gt;  pls have a look &lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 15:41:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/233996#M67450</guid>
      <dc:creator>amol_08</dc:creator>
      <dc:date>2017-08-30T15:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: variable not taking value inside rest api</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/233997#M67451</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/19322/mishraanurag643.html" nodeid="19322"&gt;@Anurag Mishra&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Before running the actual Curl command please first check if the values are being substituted properly or not?  &lt;/P&gt;&lt;P&gt;You can do so by just putting an "echo" before the curl command as following:&lt;/P&gt;&lt;PRE&gt;# echo "curl -iv -u $Ambariuser:$ambaripass -H "X-Requested-By: ambari" -X POST -d '{"Users/user_name":"$username","Users/password":"$password","Users/active":"true","Users/admin":"false"}' http://$localhost:8080/api/v1/users"&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 18:25:39 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/233997#M67451</guid>
      <dc:creator>jsensharma</dc:creator>
      <dc:date>2017-08-30T18:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: variable not taking value inside rest api</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/233998#M67452</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/19322/mishraanurag643.html" nodeid="19322"&gt;@Anurag Mishra&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Please export the variables properly as following, I see that it is working fine at my end as following:&lt;/P&gt;&lt;PRE&gt;[root@sandbox ~]# export username=test112233
[root@sandbox ~]# export password=test112233_password
[root@sandbox ~]# export Ambariuser=admin
[root@sandbox ~]# export ambaripass=admin
[root@sandbox ~]# 
[root@sandbox ~]# echo "curl -iv -u $Ambariuser:$ambaripass -H "X-Requested-By: ambari" -X POST -d '{"Users/user_name":"$username","Users/password":"$password","Users/active":"true","Users/admin":"false"}' http://localhost:8080/api/v1/users"
&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Example Output:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;[root@sandbox ~]# curl -iv -u $Ambariuser:$ambaripass -H "X-Requested-By: ambari" -X POST -d '{"Users/user_name":"$username","Users/password":"$password","Users/active":"true","Users/admin":"false"}' &lt;A href="http://localhost:8080/api/v1/users" target="_blank"&gt;http://localhost:8080/api/v1/users&lt;/A&gt;
* About to connect() to localhost port 8080 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'admin'
&amp;gt; POST /api/v1/users HTTP/1.1
&amp;gt; Authorization: Basic YWRtaW46YWRtaW4=
&amp;gt; User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
&amp;gt; Host: localhost:8080
&amp;gt; Accept: */*
&amp;gt; X-Requested-By: ambari
&amp;gt; Content-Length: 104
&amp;gt; Content-Type: application/x-www-form-urlencoded
&amp;gt; 
&amp;lt; HTTP/1.1 201 Created
HTTP/1.1 201 Created
&amp;lt; X-Frame-Options: DENY
X-Frame-Options: DENY
&amp;lt; X-XSS-Protection: 1; mode=block
X-XSS-Protection: 1; mode=block
&amp;lt; X-Content-Type-Options: nosniff
X-Content-Type-Options: nosniff
&amp;lt; Cache-Control: no-store
Cache-Control: no-store
&amp;lt; Pragma: no-cache
Pragma: no-cache
&amp;lt; Set-Cookie: AMBARISESSIONID=prd2vhf93mq517gq7ashfb9zw;Path=/;HttpOnly
Set-Cookie: AMBARISESSIONID=prd2vhf93mq517gq7ashfb9zw;Path=/;HttpOnly
&amp;lt; Expires: Thu, 01 Jan 1970 00:00:00 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
&amp;lt; User: admin
User: admin
&amp;lt; Content-Type: text/plain
Content-Type: text/plain
&amp;lt; Content-Length: 0
Content-Length: 0
&amp;lt; Server: Jetty(8.1.19.v20160209)
Server: Jetty(8.1.19.v20160209)

&amp;lt; 
* Connection #0 to host localhost left intact
* Closing connection #0

&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 18:28:34 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/233998#M67452</guid>
      <dc:creator>jsensharma</dc:creator>
      <dc:date>2017-08-30T18:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: variable not taking value inside rest api</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/233999#M67453</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/19322/mishraanurag643.html" nodeid="19322" target="_blank"&gt;@Anurag Mishra&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Now i see what do you mean by "$username" is not being replaced.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="34596-username-issue.png" style="width: 2782px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/14686i7FF49B72CD8D8EF4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="34596-username-issue.png" alt="34596-username-issue.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;This is happening because the Environment variable properties substitution does not happen inside  RAW string that is palced inside single quotes like as this is part of the Data String.&lt;/P&gt;&lt;PRE&gt;-d '{"Users/user_name":"$username","Users/password":"$password","Users/active":"true","Users/admin":"false"}'&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;Please see the difference:  (removed the single quote here)
&lt;/P&gt;&lt;PRE&gt;[root@sandbox ~]# echo '{"Users/user_name":"$username","Users/password":"$password","Users/active":"true","Users/admin":"false"}'
{"Users/user_name":"$username","Users/password":"$password","Users/active":"true","Users/admin":"false"}


[root@sandbox ~]# echo {"Users/user_name":"$username","Users/password":"$password","Users/active":"true","Users/admin":"false"}
Users/user_name:test112233 Users/password:test112233_password Users/active:true Users/admin:false&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2019 00:07:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/233999#M67453</guid>
      <dc:creator>jsensharma</dc:creator>
      <dc:date>2019-08-18T00:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: variable not taking value inside rest api</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/234000#M67454</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/3418/jsensharma.html" nodeid="3418"&gt;@Jay SenSharma&lt;/A&gt;but if i am removing single quote curl command is not working, not able to create user then&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 18:38:43 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/234000#M67454</guid>
      <dc:creator>amol_08</dc:creator>
      <dc:date>2017-08-30T18:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: variable not taking value inside rest api</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/234001#M67455</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/3418/jsensharma.html" nodeid="3418"&gt;@Jay SenSharma&lt;/A&gt;what i can do then, since I have to pass username dynamically, is there other way to achieve this ?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 18:40:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/234001#M67455</guid>
      <dc:creator>amol_08</dc:creator>
      <dc:date>2017-08-30T18:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: variable not taking value inside rest api</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/234002#M67456</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/19322/mishraanurag643.html" nodeid="19322" target="_blank"&gt;@Anurag Mishra&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You should use extra single quotes as&lt;STRONG&gt; &lt;/STRONG&gt;"&lt;STRONG&gt;'${password}'&lt;/STRONG&gt;"&lt;STRONG&gt; &lt;/STRONG&gt; and &lt;STRONG&gt; &lt;/STRONG&gt;"&lt;STRONG&gt;'${username}'&lt;/STRONG&gt;"&lt;/P&gt;&lt;P&gt;Notice:&lt;/P&gt;&lt;PRE&gt;"'${password}'"&lt;/PRE&gt;&lt;P&gt;And&lt;/P&gt;&lt;PRE&gt;"'${username}'"&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;# export username=test112233
# export password=test112233_password
# export Ambariuser=admin
# export ambaripass=admin

# curl -iv -u $Ambariuser:$ambaripass -H "X-Requested-By: ambari" -X POST  -d '{"Users/user_name":"'${username}'","Users/password":"'${password}'","Users/active":"true","Users/admin":"false"}' &lt;A href="http://localhost:8080/api/v1/users" target="_blank" rel="nofollow noopener noreferrer"&gt;http://localhost:8080/api/v1/users&lt;/A&gt;&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Output:&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="38467-curl-user-creation.png" style="width: 1298px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/14685i2D7B05B43B46C78D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="38467-curl-user-creation.png" alt="38467-curl-user-creation.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2019 00:07:44 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/variable-not-taking-value-inside-rest-api/m-p/234002#M67456</guid>
      <dc:creator>jsensharma</dc:creator>
      <dc:date>2019-08-18T00:07:44Z</dc:date>
    </item>
  </channel>
</rss>

