<?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>topic Re: Help converting a CURL command into PROC HTTP in Developers</title>
    <link>https://communities.sas.com/t5/Developers/Help-converting-a-CURL-command-into-PROC-HTTP/m-p/712585#M1085</link>
    <description>&lt;P&gt;Thank you so much for your help. I'm going to blame baldness on pulling my hair out trying to get the syntax right.&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jan 2021 04:19:58 GMT</pubDate>
    <dc:creator>Croftie</dc:creator>
    <dc:date>2021-01-20T04:19:58Z</dc:date>
    <item>
      <title>Help converting a CURL command into PROC HTTP</title>
      <link>https://communities.sas.com/t5/Developers/Help-converting-a-CURL-command-into-PROC-HTTP/m-p/712514#M1083</link>
      <description>&lt;P&gt;I have been reading post on conversion of CURL syntax to PROC HTTP for&amp;nbsp; a while now and cannot crack this one.&lt;/P&gt;&lt;P&gt;I am using Base SAS 9.4 TS Level 1M7 on the X64_10PRO platform. (latest version).&lt;/P&gt;&lt;P&gt;The follow curl statement works fine:&lt;/P&gt;&lt;P&gt;x(curl -i -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "X-Accellion-Version: 16" --header "Authorization: Bearer &amp;amp;token." -d&lt;BR /&gt;"{\"notify\": true,\"emails\": [\"croftie@tpg.com.au\"],\"roleId\": 7,\"notifyFileAdded\": false}" "&lt;A href="https://pluto.acara.edu.au/rest/folders/100/members" target="_blank"&gt;https://pluto.acara.edu.au/rest/folders/100/members&lt;/A&gt;");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried mimicking a lot of the code snippets on this site, but as the following attempt suggest, nothing works yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Attempt 1. /&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename json_in temp;
data _null_;
file json_in;
put '{';
put '"notify": true,';
put '"emails": [';
put ' "croftie@tpg.com.au"';
put ' ],';
put ' "roleId": 7,';
put ' "notifyFileAdded": false';
put '}';
run;

proc http 
method="POST"
url="https://pluto.acara.edu.au/rest/folders/100/members"
ct="application/json"
in="S:\My School QA\2021 Data Collection\SBD_Independents\FTP_Account_Creation\Requests\test1.json"
out=resp; 
headers "Authorization"="Bearer &amp;amp;token.";
run;

/* NOTE: 400 Bad Request */&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;/* Attempt 2. /&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc http
url="https://pluto.acara.edu.au/rest/folders/100/members"
method=POST
in = FORM ("notify"="true"
"emails"="[croftie@tpg.com.au]"
"roleID"="7"
"notifyFileAdded"="false");
headers "Authorization"="Bearer &amp;amp;token.";
run;

/* NOTE: 422 Unprocessable Entity */&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;/* Attempt 3. /&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc http
url="https://pluto.acara.edu.au/rest/folders/100/members"
method=POST
in = "{'notify':'true','emails':'['croftie@tpg.com.au'],'roleId':'7','notifyFileAdded':'false'}";
headers "Authorization"="Bearer &amp;amp;token.";
run;

/* NOTE: 422 Unprocessable Entity */&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;/* Attempt 4. /&lt;/P&gt;&lt;P&gt;/* EXTERNAL JSON TEXT FILE CONTAINING:&lt;BR /&gt;{&lt;BR /&gt;"notify": true,&lt;BR /&gt;"emails": [&lt;BR /&gt;"croftie@tpg.com.au"&lt;BR /&gt;],&lt;BR /&gt;"roleId": 7,&lt;BR /&gt;"notifyFileAdded": false&lt;BR /&gt;}&lt;BR /&gt;*/&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc http
method="POST"
url="https://pluto.acara.edu.au/rest/folders/100/members"
ct="application/json"
in="S:\My School QA\2021 Data Collection\SBD_Independents\FTP_Account_Creation\Requests\test1.json"
out=resp;
headers "Authorization"="Bearer &amp;amp;token.";
run;

/* NOTE: 400 Bad Request */&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;/* Attempt 5. /&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc http
url="https://pluto.acara.edu.au/rest/folders/100/members"
method=POST
in = "notify=true,emails=[croftie@tpg.com.au],roleID=7,notifyFileAdded=false";
headers "Authorization"="Bearer &amp;amp;token.";
run;

/* NOTE: 422 Unprocessable Entity */&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any help would be very gratefully accepted at this stage.&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 21:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Help-converting-a-CURL-command-into-PROC-HTTP/m-p/712514#M1083</guid>
      <dc:creator>Croftie</dc:creator>
      <dc:date>2021-01-19T21:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Help converting a CURL command into PROC HTTP</title>
      <link>https://communities.sas.com/t5/Developers/Help-converting-a-CURL-command-into-PROC-HTTP/m-p/712541#M1084</link>
      <description>&lt;P&gt;Steve,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Stepping through your attempts, you are close each time, but have simple mistakes we can easily address:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Attempt 1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;When you use the IN= option with a quoted string, that data is posted, literally.&amp;nbsp; So instead of sending the contents of the JSON file as you probably assume you are, you are actually just sending the web service the literal string "S:\My School QA\2021 Data Collection\SBD_Independents\FTP_Account_Creation\Requests\test1.json".&amp;nbsp; The web service is expecting JSON data (because you specified the content_type), which this is not, so it responds with "Bad Request"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead you want to use the fileref you created when you wrote the json data to a file in the first data step ie:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename json_in temp;
...
proc http
...
    in=json_in /*no quotes*/
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Attempt 2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Here you have a similar issue.&amp;nbsp; You are using the FORM method on the IN= option.&amp;nbsp; This helper method serializes the data you provide as a content-type such as application/x-www-form-urlencoded which your web service doesn't appear to support.&amp;nbsp; The bad content type and data is why you receive the "Unprocessable Entity" error&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot use the FORM or MULTI helpers here in the IN= option as they are not valid for the type of data you want to POST&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Attempt 3&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This time the issue is slightly different.&amp;nbsp; You are correctly trying to use the IN= option with string data equivalent to the JSON you want to post, however, you are using single quotes inside your JSON which is invalid syntax.&amp;nbsp; You also should be including the CT= option with application/json&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, you want to use double quotes inside the JSON string as you have elsewhere in your post here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc http
...
in="{""notify"":&amp;nbsp;true,&amp;nbsp;""emails"":&amp;nbsp;[""croftie@tpg.co.au""],&amp;nbsp;""roleId"":&amp;nbsp;7,&amp;nbsp;""notifyFileAdded"":&amp;nbsp;false}"
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Attempt 4&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This is essentially the same as attempt 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Attempt 5&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This is essentially the same as attempt 3, this is invalid JSON syntax so the web service cannot handle the data it receives.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Additional Information&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Across all of your attempts you are also leaving out additional headers that could be important to your web service successfully responding to your request.&amp;nbsp; Here is the most complete translation of your curl command in the HTTP Procedure&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc http
    method="POST"
    url="https://pluto.acara.edu.au/rest/folders/100/members"
    ct="application/json"
    oauth_bearer="&amp;amp;token" /* equivalent of headers "Authorization"="Bearer &amp;amp;token" */
    in="{""notify"": true, ""emails"": [""croftie@tpg.co.au""], ""roleId"": 7, ""notifyFileAdded"": false}";
    headers 
        "Accept"="application/json"
        "X-Accellion-Version"="16";
    debug level=3 NO_REQUEST_BODY NO_REQUEST_HEADERS OUTPUT_TEXT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 22:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Help-converting-a-CURL-command-into-PROC-HTTP/m-p/712541#M1084</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2021-01-19T22:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help converting a CURL command into PROC HTTP</title>
      <link>https://communities.sas.com/t5/Developers/Help-converting-a-CURL-command-into-PROC-HTTP/m-p/712585#M1085</link>
      <description>&lt;P&gt;Thank you so much for your help. I'm going to blame baldness on pulling my hair out trying to get the syntax right.&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 04:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Help-converting-a-CURL-command-into-PROC-HTTP/m-p/712585#M1085</guid>
      <dc:creator>Croftie</dc:creator>
      <dc:date>2021-01-20T04:19:58Z</dc:date>
    </item>
  </channel>
</rss>

