<?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: Proc HTTP 401 Unauthorized in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785823#M81328</link>
    <description>&lt;P&gt;Hi Chris,&lt;BR /&gt;&lt;BR /&gt;Correct, the client_id &amp;amp; client_secret are not referenced. I was doing some testing with those, but they are not relevant to the code I shared.&lt;BR /&gt;&lt;BR /&gt;I ran the test program no problem.&lt;BR /&gt;&lt;BR /&gt;Python is on the same machine and running some simple code such as this gets me what I need:&lt;BR /&gt;&lt;BR /&gt;import http.client&lt;BR /&gt;conn = http.client.HTTPSConnection("api.bigcommerce.com")&lt;BR /&gt;headers = { 'x-auth-token': "XXXXXXXXXXXXXXXXXXXXXXXXXX" }&lt;BR /&gt;conn.request("GET", "/stores/XXXXXXX/v3/catalog/products", headers=headers)&lt;BR /&gt;res = conn.getresponse()&lt;BR /&gt;data = res.read()&lt;BR /&gt;print(data.decode("utf-8"))&lt;BR /&gt;&lt;BR /&gt;Here is the SAS log for reference:&lt;BR /&gt;1842 %let accesskey=XXXXXXXXXXXXXXXX;&lt;BR /&gt;1843&lt;BR /&gt;1844 %let&lt;BR /&gt;1844! fullurl=&lt;A href="https://api.bigcommerce.com/stores/XXXXXXXX/v3/c" target="_blank" rel="noopener"&gt;https://api.bigcommerce.com/stores/XXXXXXXX/v3/c&lt;/A&gt;&lt;BR /&gt;1844! atalog/products;&lt;BR /&gt;1845&lt;BR /&gt;1846 filename BC_Prod temp;&lt;BR /&gt;1847&lt;BR /&gt;1848 proc http&lt;BR /&gt;1849 url= "&amp;amp;fullurl."&lt;BR /&gt;1850 method="GET" out=BC_Prod;&lt;BR /&gt;1851 headers&lt;BR /&gt;1852 "Authorization"="Bearer &amp;amp;accesskey.";&lt;BR /&gt;1853 debug level=3;&lt;BR /&gt;1854 run;&lt;BR /&gt;&lt;BR /&gt;&amp;gt; GET /stores/XXXXXXX/v3/catalog/products HTTP/1.1&lt;BR /&gt;&amp;gt; User-Agent: SAS/9&lt;BR /&gt;&amp;gt; Host: api.bigcommerce.com&lt;BR /&gt;&amp;gt; Accept: */*&lt;BR /&gt;&amp;gt; Connection: Keep-Alive&lt;BR /&gt;&amp;gt; Authorization: ************&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;lt; HTTP/1.1 401 Unauthorized&lt;BR /&gt;&lt;BR /&gt;&amp;lt; Content-Type: text/plain; charset=UTF-8&lt;BR /&gt;&lt;BR /&gt;&amp;lt; Transfer-Encoding: chunked&lt;BR /&gt;&lt;BR /&gt;&amp;lt; Connection: keep-alive&lt;BR /&gt;&lt;BR /&gt;&amp;lt; X-Request-ID: 85aafd01402485585ccb34caf2379a4b&lt;BR /&gt;&lt;BR /&gt;&amp;lt; Strict-Transport-Security: max-age=31536000;&lt;BR /&gt;includeSubDomains&lt;BR /&gt;&lt;BR /&gt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;&amp;lt; 000001DC9E0E01CE: 58 2D 41 75 74 68 2D 54 6F 6B 65 6E 20 68&lt;BR /&gt;65 61 X-Auth-Token hea&lt;BR /&gt;&amp;lt; 000001DC9E0E01DE: 64 65 72 20 69 73 20 72 65 71 75 69 72 65&lt;BR /&gt;64 der is required&lt;BR /&gt;NOTE: 401 Unauthorized&lt;BR /&gt;NOTE: PROCEDURE HTTP used (Total process time):&lt;BR /&gt;real time 0.27 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Dec 2021 18:08:01 GMT</pubDate>
    <dc:creator>CR-Horton</dc:creator>
    <dc:date>2021-12-13T18:08:01Z</dc:date>
    <item>
      <title>Proc HTTP 401 Unauthorized</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785609#M81317</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I am having some issues with proc http. In particular I am trying to access an API endpoint, but getting a 401 unauthorized error. I have got this to work in Python, but not SAS. Is there anything in my code below that does not look correct? Do I need to somehow pass the client_id and client_secret? When I debug it I see something like " X-Auth-Token header is required"&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;%let accesskey=XXXXXXXXXXXXXXXXXXXXX;&lt;BR /&gt;%let client_id=XXXXXXXXXXXXXXXXXXXXXXXXX;&lt;BR /&gt;%let client_secret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX;&lt;/P&gt;&lt;P&gt;%let fullurl=&lt;A href="https://api.bigcommerce.com/stores/XXXXXXXX/v3/catalog/products" target="_blank"&gt;https://api.bigcommerce.com/stores/XXXXXXXX/v3/catalog/products&lt;/A&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename BC_Prod temp;&lt;/P&gt;&lt;P&gt;proc http&lt;BR /&gt;url= "&amp;amp;fullurl."&lt;BR /&gt;method="GET" out=BC_Prod;&lt;BR /&gt;headers&lt;BR /&gt;"Authorization"="Bearer &amp;amp;accesskey."&lt;BR /&gt;debug level=3;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance and apologies if I am clearly missing something!&lt;/P&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785609#M81317</guid>
      <dc:creator>CR-Horton</dc:creator>
      <dc:date>2021-12-12T01:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Proc HTTP 401 Unauthorized</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785626#M81318</link>
      <description>&lt;P&gt;Can we see the log please?&lt;/P&gt;</description>
      <pubDate>Sun, 12 Dec 2021 15:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785626#M81318</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-12-12T15:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: Proc HTTP 401 Unauthorized</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785637#M81319</link>
      <description>&lt;P&gt;Did make a version of the code with &lt;STRONG&gt;NO&lt;/STRONG&gt; macro variables before attempting the macro version?&lt;/P&gt;
&lt;P&gt;If not, that is the first thing to do.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Dec 2021 17:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785637#M81319</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-12-12T17:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc HTTP 401 Unauthorized</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785642#M81320</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/387905"&gt;@CR-Horton&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. The error code 401 means authorisation has failed / access denied.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Please make sure that the SAS code and Python code are being executed with the same userid;&lt;/P&gt;
&lt;P&gt;2.It will be good if you verify your syntax. Is the semicolon after&amp;nbsp;&lt;STRONG&gt;out=BC_Prod&lt;FONT color="#FF0000"&gt;;&amp;nbsp;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#003300"&gt;correctly placed ?&lt;BR /&gt;&amp;nbsp; Please try moving it after authorisation&amp;nbsp; as&amp;nbsp;&lt;SPAN&gt;"Authorization"="Bearer &amp;amp;accesskey."&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt; ;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;The details and examples are available here&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n0bdg5vmrpyi7jn1pbgbje2atoov.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n0bdg5vmrpyi7jn1pbgbje2atoov.htm&lt;/A&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Dec 2021 19:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785642#M81320</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-12-12T19:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc HTTP 401 Unauthorized</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785651#M81321</link>
      <description>&lt;P&gt;You seem to be missing a semi-colon.&amp;nbsp; You should have separate PROC, HEADERS and DEBUG statements.&lt;/P&gt;
&lt;P&gt;Use indentation to make this clearer to the humans reading/editing the program.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename BC_Prod temp;

proc http
  url= "&amp;amp;fullurl."
  method="GET" 
  out=BC_Prod
;
  headers "Authorization"="Bearer &amp;amp;accesskey." ;
  debug level=3;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Dec 2021 21:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785651#M81321</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-12T21:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Proc HTTP 401 Unauthorized</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785736#M81322</link>
      <description>&lt;P&gt;You show the macro variable assignments for client_id and client_secret, but these are not referenced in your PROC HTTP code so they wouldn't be passed. Now, maybe the access_token is all you need (often the case) because the other credentials have already been exchanged in order to get that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your Python environment on the same machine/network as your SAS environment? Perhaps you also need to specify a proxy host from your SAS environment to reach the internet.&amp;nbsp; &lt;A href="https://blogs.sas.com/content/sasdummy/2018/01/23/check-json-and-http/" target="_self"&gt;Try this test program&lt;/A&gt; from your SAS environment to make sure things are working.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 12:31:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785736#M81322</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2021-12-13T12:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: Proc HTTP 401 Unauthorized</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785818#M81325</link>
      <description>Yes, I did, but get the same sort of error message.</description>
      <pubDate>Mon, 13 Dec 2021 17:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785818#M81325</guid>
      <dc:creator>CR-Horton</dc:creator>
      <dc:date>2021-12-13T17:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc HTTP 401 Unauthorized</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785819#M81326</link>
      <description>Thanks for your reply. The semicolon placement if correct so that is not the issue. See: &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0az1lwh6i73b1n1bianqjpgoek0.htm#p0az1lwh6i73b1n1bianqjpgoek0" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0az1lwh6i73b1n1bianqjpgoek0.htm#p0az1lwh6i73b1n1bianqjpgoek0&lt;/A&gt;</description>
      <pubDate>Mon, 13 Dec 2021 17:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785819#M81326</guid>
      <dc:creator>CR-Horton</dc:creator>
      <dc:date>2021-12-13T17:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: Proc HTTP 401 Unauthorized</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785820#M81327</link>
      <description>Thanks, Tom.&lt;BR /&gt;&lt;BR /&gt;You are correct about the missing semicolon, but that didn't seem to address the main issue I am having.</description>
      <pubDate>Mon, 13 Dec 2021 17:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785820#M81327</guid>
      <dc:creator>CR-Horton</dc:creator>
      <dc:date>2021-12-13T17:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Proc HTTP 401 Unauthorized</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785823#M81328</link>
      <description>&lt;P&gt;Hi Chris,&lt;BR /&gt;&lt;BR /&gt;Correct, the client_id &amp;amp; client_secret are not referenced. I was doing some testing with those, but they are not relevant to the code I shared.&lt;BR /&gt;&lt;BR /&gt;I ran the test program no problem.&lt;BR /&gt;&lt;BR /&gt;Python is on the same machine and running some simple code such as this gets me what I need:&lt;BR /&gt;&lt;BR /&gt;import http.client&lt;BR /&gt;conn = http.client.HTTPSConnection("api.bigcommerce.com")&lt;BR /&gt;headers = { 'x-auth-token': "XXXXXXXXXXXXXXXXXXXXXXXXXX" }&lt;BR /&gt;conn.request("GET", "/stores/XXXXXXX/v3/catalog/products", headers=headers)&lt;BR /&gt;res = conn.getresponse()&lt;BR /&gt;data = res.read()&lt;BR /&gt;print(data.decode("utf-8"))&lt;BR /&gt;&lt;BR /&gt;Here is the SAS log for reference:&lt;BR /&gt;1842 %let accesskey=XXXXXXXXXXXXXXXX;&lt;BR /&gt;1843&lt;BR /&gt;1844 %let&lt;BR /&gt;1844! fullurl=&lt;A href="https://api.bigcommerce.com/stores/XXXXXXXX/v3/c" target="_blank" rel="noopener"&gt;https://api.bigcommerce.com/stores/XXXXXXXX/v3/c&lt;/A&gt;&lt;BR /&gt;1844! atalog/products;&lt;BR /&gt;1845&lt;BR /&gt;1846 filename BC_Prod temp;&lt;BR /&gt;1847&lt;BR /&gt;1848 proc http&lt;BR /&gt;1849 url= "&amp;amp;fullurl."&lt;BR /&gt;1850 method="GET" out=BC_Prod;&lt;BR /&gt;1851 headers&lt;BR /&gt;1852 "Authorization"="Bearer &amp;amp;accesskey.";&lt;BR /&gt;1853 debug level=3;&lt;BR /&gt;1854 run;&lt;BR /&gt;&lt;BR /&gt;&amp;gt; GET /stores/XXXXXXX/v3/catalog/products HTTP/1.1&lt;BR /&gt;&amp;gt; User-Agent: SAS/9&lt;BR /&gt;&amp;gt; Host: api.bigcommerce.com&lt;BR /&gt;&amp;gt; Accept: */*&lt;BR /&gt;&amp;gt; Connection: Keep-Alive&lt;BR /&gt;&amp;gt; Authorization: ************&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;lt; HTTP/1.1 401 Unauthorized&lt;BR /&gt;&lt;BR /&gt;&amp;lt; Content-Type: text/plain; charset=UTF-8&lt;BR /&gt;&lt;BR /&gt;&amp;lt; Transfer-Encoding: chunked&lt;BR /&gt;&lt;BR /&gt;&amp;lt; Connection: keep-alive&lt;BR /&gt;&lt;BR /&gt;&amp;lt; X-Request-ID: 85aafd01402485585ccb34caf2379a4b&lt;BR /&gt;&lt;BR /&gt;&amp;lt; Strict-Transport-Security: max-age=31536000;&lt;BR /&gt;includeSubDomains&lt;BR /&gt;&lt;BR /&gt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;&amp;lt; 000001DC9E0E01CE: 58 2D 41 75 74 68 2D 54 6F 6B 65 6E 20 68&lt;BR /&gt;65 61 X-Auth-Token hea&lt;BR /&gt;&amp;lt; 000001DC9E0E01DE: 64 65 72 20 69 73 20 72 65 71 75 69 72 65&lt;BR /&gt;64 der is required&lt;BR /&gt;NOTE: 401 Unauthorized&lt;BR /&gt;NOTE: PROCEDURE HTTP used (Total process time):&lt;BR /&gt;real time 0.27 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 18:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785823#M81328</guid>
      <dc:creator>CR-Horton</dc:creator>
      <dc:date>2021-12-13T18:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: Proc HTTP 401 Unauthorized</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785866#M81339</link>
      <description>&lt;P&gt;In Python you used x-auth-token as the header key. So why not try this HEADERS statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;headers "x-auth-token"="&amp;amp;accesskey.";&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 13 Dec 2021 20:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785866#M81339</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2021-12-13T20:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc HTTP 401 Unauthorized</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785870#M81340</link>
      <description>That did it! Appreciate the help!</description>
      <pubDate>Mon, 13 Dec 2021 20:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-HTTP-401-Unauthorized/m-p/785870#M81340</guid>
      <dc:creator>CR-Horton</dc:creator>
      <dc:date>2021-12-13T20:29:35Z</dc:date>
    </item>
  </channel>
</rss>

