<?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 Proc HTTP and sending URLEncoded Javascript file... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-HTTP-and-sending-URLEncoded-Javascript-file/m-p/506061#M135588</link>
    <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp; I am really struggling with converting what I am able to get to run in Postman, into a valid Proc HTTP statement...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I usually am able translate the cURL code snippets from Postman into SAS using Proc HTTP quite easily, but this one is stumping me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the cURL code that works(removed my secret code and Postman token)...&lt;/P&gt;&lt;P&gt;curl -X GET \&lt;BR /&gt;&amp;nbsp; '&lt;A href="https://mixpanel.com/api/2.0/jql?script={{encoded_script" target="_blank"&gt;https://mixpanel.com/api/2.0/jql?script={{encoded_script&lt;/A&gt;}}' \&lt;BR /&gt;&amp;nbsp; -H 'Authorization: Basic &amp;lt;my Secret Code&amp;gt;' \&lt;BR /&gt;&amp;nbsp; -H 'Postman-Token: My Token' \&lt;BR /&gt;&amp;nbsp; -H 'cache-control: no-cache'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The {{encoded_script}} is a prerequest script that URLEncodes the actual script...&lt;/P&gt;&lt;P&gt;var encoded = encodeURIComponent(function main() {return Events({from_date: "2018-10-17", to_date: "2018-10-19"})});&lt;BR /&gt;postman.setEnvironmentVariable("encoded_script", encoded);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In reading the 3rd party vendors API documentation(JQL is what they use), here is a cURL example they give...&lt;/P&gt;&lt;PRE&gt;curl https://mixpanel.com/api/2.0/jql &lt;SPAN class="se"&gt;\&lt;/SPAN&gt;
    -u Secret_Code &lt;SPAN class="se"&gt;\&lt;/SPAN&gt;
    --data-urlencode &lt;SPAN class="nv"&gt;params&lt;/SPAN&gt;&lt;SPAN class="o"&gt;=&lt;/SPAN&gt;&lt;SPAN class="s1"&gt;'{"from_date":"2016-01-01", "to_date": "2016-01-07"}'&lt;/SPAN&gt; &lt;SPAN class="se"&gt;\&lt;/SPAN&gt;
    --data-urlencode &lt;SPAN class="nv"&gt;script&lt;/SPAN&gt;&lt;SPAN class="o"&gt;=&lt;/SPAN&gt;&lt;SPAN class="s1"&gt;'function main(){ return Events(params).groupBy(["name"], mixpanel.reducer.count()) }'&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Proc HTTP statement looks like this, where the script= part has been run through the URLEncode function(I tried it not running it through that as well)...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc http&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; method="GET"&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;url="&lt;A href="https://mixpanel.com/api/2.0/jql?script='%27function%20main()%20%7Breturn%20Events(%7Bfrom_date%3A%20%222018-10-17%22,%20to_date%3A%20%222018-10-19%22%7D)%7D%27" target="_blank"&gt;https://mixpanel.com/api/2.0/jql?script='%27function%20main()%20%7Breturn%20Events(%7Bfrom_date%3A%20%222018-10-17%22,%20to_date%3A%20%222018-10-19%22%7D)%7D%27&lt;/A&gt;'"&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ct="application/json"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; headerout=hresult&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; out=json;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;headers "Authorization" = "Basic &amp;amp;api_secret.";&lt;BR /&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It authenticates fine but I always get a Bad Request with a message similar to ...&lt;/P&gt;&lt;P&gt;{"request": "/api/2.0/jql?script=%27function%20main()%20%7Breturn%20Events(%7Bfrom_date%3A%20%222018-10-17%22%2C%20to_date%3A%20%222018-10-19%22%7D)%7D%27", "error": "[Validate failed]the query must define the main() function\n"}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried putting the script= into the IN= statement but the API always tells me I am missing the Script= statment(which is required).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems to have something to do with URL Encoding the script, but it still doesn't seem like it likes my URL Encoded text.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
    <pubDate>Fri, 19 Oct 2018 17:15:58 GMT</pubDate>
    <dc:creator>Chuck_IV4</dc:creator>
    <dc:date>2018-10-19T17:15:58Z</dc:date>
    <item>
      <title>Proc HTTP and sending URLEncoded Javascript file...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-HTTP-and-sending-URLEncoded-Javascript-file/m-p/506061#M135588</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp; I am really struggling with converting what I am able to get to run in Postman, into a valid Proc HTTP statement...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I usually am able translate the cURL code snippets from Postman into SAS using Proc HTTP quite easily, but this one is stumping me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the cURL code that works(removed my secret code and Postman token)...&lt;/P&gt;&lt;P&gt;curl -X GET \&lt;BR /&gt;&amp;nbsp; '&lt;A href="https://mixpanel.com/api/2.0/jql?script={{encoded_script" target="_blank"&gt;https://mixpanel.com/api/2.0/jql?script={{encoded_script&lt;/A&gt;}}' \&lt;BR /&gt;&amp;nbsp; -H 'Authorization: Basic &amp;lt;my Secret Code&amp;gt;' \&lt;BR /&gt;&amp;nbsp; -H 'Postman-Token: My Token' \&lt;BR /&gt;&amp;nbsp; -H 'cache-control: no-cache'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The {{encoded_script}} is a prerequest script that URLEncodes the actual script...&lt;/P&gt;&lt;P&gt;var encoded = encodeURIComponent(function main() {return Events({from_date: "2018-10-17", to_date: "2018-10-19"})});&lt;BR /&gt;postman.setEnvironmentVariable("encoded_script", encoded);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In reading the 3rd party vendors API documentation(JQL is what they use), here is a cURL example they give...&lt;/P&gt;&lt;PRE&gt;curl https://mixpanel.com/api/2.0/jql &lt;SPAN class="se"&gt;\&lt;/SPAN&gt;
    -u Secret_Code &lt;SPAN class="se"&gt;\&lt;/SPAN&gt;
    --data-urlencode &lt;SPAN class="nv"&gt;params&lt;/SPAN&gt;&lt;SPAN class="o"&gt;=&lt;/SPAN&gt;&lt;SPAN class="s1"&gt;'{"from_date":"2016-01-01", "to_date": "2016-01-07"}'&lt;/SPAN&gt; &lt;SPAN class="se"&gt;\&lt;/SPAN&gt;
    --data-urlencode &lt;SPAN class="nv"&gt;script&lt;/SPAN&gt;&lt;SPAN class="o"&gt;=&lt;/SPAN&gt;&lt;SPAN class="s1"&gt;'function main(){ return Events(params).groupBy(["name"], mixpanel.reducer.count()) }'&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Proc HTTP statement looks like this, where the script= part has been run through the URLEncode function(I tried it not running it through that as well)...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc http&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; method="GET"&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;url="&lt;A href="https://mixpanel.com/api/2.0/jql?script='%27function%20main()%20%7Breturn%20Events(%7Bfrom_date%3A%20%222018-10-17%22,%20to_date%3A%20%222018-10-19%22%7D)%7D%27" target="_blank"&gt;https://mixpanel.com/api/2.0/jql?script='%27function%20main()%20%7Breturn%20Events(%7Bfrom_date%3A%20%222018-10-17%22,%20to_date%3A%20%222018-10-19%22%7D)%7D%27&lt;/A&gt;'"&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ct="application/json"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; headerout=hresult&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; out=json;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;headers "Authorization" = "Basic &amp;amp;api_secret.";&lt;BR /&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It authenticates fine but I always get a Bad Request with a message similar to ...&lt;/P&gt;&lt;P&gt;{"request": "/api/2.0/jql?script=%27function%20main()%20%7Breturn%20Events(%7Bfrom_date%3A%20%222018-10-17%22%2C%20to_date%3A%20%222018-10-19%22%7D)%7D%27", "error": "[Validate failed]the query must define the main() function\n"}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried putting the script= into the IN= statement but the API always tells me I am missing the Script= statment(which is required).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems to have something to do with URL Encoding the script, but it still doesn't seem like it likes my URL Encoded text.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 17:15:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-HTTP-and-sending-URLEncoded-Javascript-file/m-p/506061#M135588</guid>
      <dc:creator>Chuck_IV4</dc:creator>
      <dc:date>2018-10-19T17:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Proc HTTP and sending URLEncoded Javascript file...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-HTTP-and-sending-URLEncoded-Javascript-file/m-p/506095#M135600</link>
      <description>&lt;P&gt;Ok, I am very close to getting this working. If I remove the single quotes around the URL Encoded script= code, it WORKS(See below)!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc http&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; method="GET"&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;url="&lt;A href="https://mixpanel.com/api/2.0/jql?script=function%20main()%20%7Breturn%20Events(%7Bfrom_date%3A%20%222018-10-17%22,%20to_date%3A%20%222018-10-19%22%7D)%7D" target="_blank"&gt;https://mixpanel.com/api/2.0/jql?script=function%20main()%20%7Breturn%20Events(%7Bfrom_date%3A%20%222018-10-17%22,%20to_date%3A%20%222018-10-19%22%7D)%7D&lt;/A&gt;"&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ct="application/json"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; headerout=hresult&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; out=json;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;headers "Authorization" = "Basic &amp;amp;api_secret.";&lt;BR /&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue was the script = code does NOT need the single quotes(even though the cURL statement shows them).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, this now presents another problem. I need to put the script code into its own file and then call the file. The problem is, when I put the file name as the script= statement(something like script=jscript.js), JQL thinks the jscript.js the actual script code and not a file name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess I can set a macro variable to the entire file and then just drop the macro variable in place of the jscript.js filename but that seems a little odd to have to do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any thoughts on this one?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 18:14:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-HTTP-and-sending-URLEncoded-Javascript-file/m-p/506095#M135600</guid>
      <dc:creator>Chuck_IV4</dc:creator>
      <dc:date>2018-10-19T18:14:43Z</dc:date>
    </item>
  </channel>
</rss>

