<?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: Getting 401 (Unauthorized) error when calling Qlik api endpoint from javascript in Integration, Extension &amp; APIs</title>
    <link>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512586#M21998</link>
    <description>&lt;P&gt;As a sense check, do you have the right scopes applied on that token - it looks like you might be requesting a non-Qlik scope in that example?&lt;/P&gt;
&lt;P&gt;Ref:&amp;nbsp;&lt;A href="https://qlik.dev/authenticate/oauth/scopes/" target="_blank"&gt;https://qlik.dev/authenticate/oauth/scopes/&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Apr 2025 13:13:03 GMT</pubDate>
    <dc:creator>Dave_Channon</dc:creator>
    <dc:date>2025-04-01T13:13:03Z</dc:date>
    <item>
      <title>Getting 401 (Unauthorized) error when calling Qlik api endpoint from javascript</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512377#M21991</link>
      <description>&lt;P&gt;I am trying to call the endpoint 'api/v1/users/me' in my Javascript application however I get a 401 error.&lt;BR /&gt;Prior to this, I get an access token via oAuth and this is stored in session storage. I then call this endpoint and pass in the access token, however I get the 401 error. I have also tried to use the API Key in my code and it does not work. I copied the access token that that gets given to me and I try to use it to call the same endpoint in postman and I still get the 401 error.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;  const getUserData = async (token: string) =&amp;gt; {
    const accessToken = sessionStorage.getItem('qlikAccessToken');
    try {
      const userInfoUrl = 'https://my-tenant.us.qlikcloud.com/api/v1/users/me';
      const response = await fetch(userInfoUrl, {
        method: 'GET',
        headers: {
          'Authorization': `Bearer ${accessToken}`,
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        },
      });
      if (!response.ok) {
        throw new Error(`HTTP error! Status: ${response.status}`);
      }

      const userData = await response.json();
      console.log('User Data:', userData);
    } catch (error) {
      console.error('Error fetching user data:', error);
    }
  };&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 31 Mar 2025 14:44:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512377#M21991</guid>
      <dc:creator>jcampbel1</dc:creator>
      <dc:date>2025-03-31T14:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: Getting 401 (Unauthorized) error when calling Qlik api endpoint from javascript</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512405#M21992</link>
      <description>&lt;P&gt;can you show the call and body you used to generate the token?&lt;/P&gt;&lt;P&gt;-Rob&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 18:36:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512405#M21992</guid>
      <dc:creator>rwunderlich</dc:creator>
      <dc:date>2025-03-31T18:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: Getting 401 (Unauthorized) error when calling Qlik api endpoint from javascript</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512418#M21993</link>
      <description>&lt;P&gt;hello, here is how i generate the token.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;  const redirectToQlikAuth = async () =&amp;gt; {
    const clientId = 'my-client-id'; // Consider moving to environment variables
    const redirectUri = encodeURIComponent(process.env.REACT_APP_REDIRECT_URI || 'http://localhost:3000/CDO-DA/build/redirect');
    const state = crypto.randomUUID();
    const codeVerifier = generateCodeVerifier();
    const codeChallenge = await generateCodeChallenge(codeVerifier);

    sessionStorage.setItem('qlikAuthState', state);
    sessionStorage.setItem('codeVerifier', codeVerifier);

    const qlikAuthUrl = `https://my-tenant.us.qlikcloud.com/oauth/authorize?` +
      `response_type=code&amp;amp;` +
      `client_id=${clientId}&amp;amp;` +
      `redirect_uri=${redirectUri}&amp;amp;` +
      `state=${state}&amp;amp;` +
      `code_challenge=${codeChallenge}&amp;amp;` +
      `code_challenge_method=S256&amp;amp;` +
      `scope=user.profile`;

    window.location.href = qlikAuthUrl;
  };

  const generateCodeVerifier = () =&amp;gt; {
    const array = new Uint32Array(56 / 2);
    window.crypto.getRandomValues(array);
    return Array.from(array, dec =&amp;gt; ('0' + dec.toString(16)).substr(-2)).join('');
  };

  const generateCodeChallenge = async (codeVerifier: string) =&amp;gt; {
    const encoder = new TextEncoder();
    const data = encoder.encode(codeVerifier);
    const digest = await window.crypto.subtle.digest('SHA-256', data);
    return btoa(String.fromCharCode(...Array.from(new Uint8Array(digest))))
      .replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
  };&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 31 Mar 2025 20:13:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512418#M21993</guid>
      <dc:creator>jcampbel1</dc:creator>
      <dc:date>2025-03-31T20:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: Getting 401 (Unauthorized) error when calling Qlik api endpoint from javascript</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512429#M21994</link>
      <description>&lt;P&gt;I believe you need to then exchange the authorization code for a token using&amp;nbsp;&lt;A href="https://qlik.dev/apis/rest/oauth/#post-oauth-token" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;POST&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN class=""&gt;&lt;A href="https://qlik.dev/apis/rest/oauth/#post-oauth-token" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;/oauth&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;&lt;A href="https://qlik.dev/apis/rest/oauth/#post-oauth-token" target="_blank" rel="noopener"&gt;/token&lt;/A&gt;. with an&amp;nbsp;&lt;FONT face="courier new,courier"&gt;oauth-authorization-code-request&lt;/FONT&gt;. See&amp;nbsp;&lt;A href="https://www.qalyptus.com/blog/setting-up-qlik-oauth-for-authentication" target="_blank" rel="noopener"&gt;https://www.qalyptus.com/blog/setting-up-qlik-oauth-for-authentication&lt;/A&gt;&amp;nbsp;for a good overview and example.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;-Rob&lt;BR /&gt;&lt;A href="http://www.easyqlik.com" target="_blank" rel="noopener"&gt;http://www.easyqlik.com&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://masterssummit.com" target="_blank" rel="noopener"&gt;http://masterssummit.com&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://qlikviewcookbook.com" target="_blank" rel="noopener"&gt;http://qlikviewcookbook.com&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 21:17:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512429#M21994</guid>
      <dc:creator>rwunderlich</dc:creator>
      <dc:date>2025-03-31T21:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: Getting 401 (Unauthorized) error when calling Qlik api endpoint from javascript</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512498#M21997</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/6148"&gt;@rwunderlich&lt;/a&gt;&amp;nbsp;, my code does this in the callback method. I get the token from the post endpoint. I then try to call the 'api/v1/users/me' endpoint passing in the Bearer token into the authorization and I am given the following error:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;"errors":[{"code":"USERS-7","status":404,"title":"Not found"}]}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 09:24:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512498#M21997</guid>
      <dc:creator>jcampbel1</dc:creator>
      <dc:date>2025-04-01T09:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Getting 401 (Unauthorized) error when calling Qlik api endpoint from javascript</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512586#M21998</link>
      <description>&lt;P&gt;As a sense check, do you have the right scopes applied on that token - it looks like you might be requesting a non-Qlik scope in that example?&lt;/P&gt;
&lt;P&gt;Ref:&amp;nbsp;&lt;A href="https://qlik.dev/authenticate/oauth/scopes/" target="_blank"&gt;https://qlik.dev/authenticate/oauth/scopes/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 13:13:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512586#M21998</guid>
      <dc:creator>Dave_Channon</dc:creator>
      <dc:date>2025-04-01T13:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Getting 401 (Unauthorized) error when calling Qlik api endpoint from javascript</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512611#M22000</link>
      <description>&lt;P&gt;that was the issue, it works now! thanks&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 14:13:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Getting-401-Unauthorized-error-when-calling-Qlik-api-endpoint/m-p/2512611#M22000</guid>
      <dc:creator>jcampbel1</dc:creator>
      <dc:date>2025-04-01T14:13:50Z</dc:date>
    </item>
  </channel>
</rss>

