<?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: Automate token retrieval from Rest API for sales force in Connectivity &amp; Data Prep</title>
    <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Automate-token-retrieval-from-Rest-API-for-sales-force/m-p/1920890#M10596</link>
    <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The process that you need to follow here is to do a POST to the first API end point that will give you the token. You then need to &lt;A href="https://help.qlik.com/en-US/sense/February2022/Subsystems/Hub/Content/Sense_Hub/Scripting/InterRecordFunctions/Peek.htm" target="_self"&gt;PEEK&lt;/A&gt; that into a variable, which you can then inject into the second API request, by using &lt;A href="https://help.qlik.com/en-US/connectors/Subsystems/REST_connector_help/Content/Connectors_REST/Load-REST-data/Load-data.htm#WITH-CONNECTION-keyword" target="_self"&gt;WITH CONNECTION&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;I've not got code for SalesForce, but this code for connecting to the Twitter API should give you an idea of the workflow.&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;if vBearerKey = '' or IsNull(vBearerKey) or vBearerLastGot &amp;lt; (vNow - vBearerRefreshDays) then
	TRACE Getting New Bearer Key;
    
    LIB CONNECT TO '$(v_POST_Connector)';
    
    tmpBearerKey:
    SQL SELECT
	"tokem_type",
        "access_token"
    FROM JSON (wrap on) "root" PK "__KEY_root"
	WITH CONNECTION (  
      URL "https://api.twitter.com/oauth2/token",
      HTTPHEADER "content-type" "application/x-www-form-urlencoded",
      HTTPHEADER "Authorization" "Basic $(vBASE64Key)",
      QUERY "grant_type" "client_credentials"
    )
	;

	let vBearerKey = peek('access_token', -1, 'tmpBearerKey');

	DROP TABLE tmpBearerKey;

	let vBearerLastGot = now();
	let vLastBearerKey = vBearerKey;
end if


let vMaxTweetURL = if(vMinTweet = 0, '', '&amp;amp;max_id=$(vMinTweet)');

RestConnectorMasterTable:
SQL SELECT 
	[... removed for brevity ...]
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION (  
      URL "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=$(vTwitterName)&amp;amp;trim_user=true&amp;amp;count=200$(vMaxTweetURL)",    
      HTTPHEADER "Authorization" "Bearer $(vBearerKey)"
    )
;
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck!&lt;/P&gt;
&lt;P&gt;Steve&lt;/P&gt;</description>
    <pubDate>Thu, 21 Apr 2022 11:29:07 GMT</pubDate>
    <dc:creator>stevedark</dc:creator>
    <dc:date>2022-04-21T11:29:07Z</dc:date>
    <item>
      <title>Automate token retrieval from Rest API for sales force</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Automate-token-retrieval-from-Rest-API-for-sales-force/m-p/1920699#M10593</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In order to access data from Sales force, I do the following steps:&lt;/P&gt;
&lt;P&gt;1) I use postman to get access token using post method&lt;/P&gt;
&lt;P&gt;2) After getting the token, I enter the token data in the res connector api to extract data from sales force.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem with the above approach is, the token is only valid for 30 mins. So every time I need to access data, I have to again repeat the above steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to automate this process.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Please advice&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 00:12:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Automate-token-retrieval-from-Rest-API-for-sales-force/m-p/1920699#M10593</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-04-21T00:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Automate token retrieval from Rest API for sales force</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Automate-token-retrieval-from-Rest-API-for-sales-force/m-p/1920890#M10596</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The process that you need to follow here is to do a POST to the first API end point that will give you the token. You then need to &lt;A href="https://help.qlik.com/en-US/sense/February2022/Subsystems/Hub/Content/Sense_Hub/Scripting/InterRecordFunctions/Peek.htm" target="_self"&gt;PEEK&lt;/A&gt; that into a variable, which you can then inject into the second API request, by using &lt;A href="https://help.qlik.com/en-US/connectors/Subsystems/REST_connector_help/Content/Connectors_REST/Load-REST-data/Load-data.htm#WITH-CONNECTION-keyword" target="_self"&gt;WITH CONNECTION&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;I've not got code for SalesForce, but this code for connecting to the Twitter API should give you an idea of the workflow.&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;if vBearerKey = '' or IsNull(vBearerKey) or vBearerLastGot &amp;lt; (vNow - vBearerRefreshDays) then
	TRACE Getting New Bearer Key;
    
    LIB CONNECT TO '$(v_POST_Connector)';
    
    tmpBearerKey:
    SQL SELECT
	"tokem_type",
        "access_token"
    FROM JSON (wrap on) "root" PK "__KEY_root"
	WITH CONNECTION (  
      URL "https://api.twitter.com/oauth2/token",
      HTTPHEADER "content-type" "application/x-www-form-urlencoded",
      HTTPHEADER "Authorization" "Basic $(vBASE64Key)",
      QUERY "grant_type" "client_credentials"
    )
	;

	let vBearerKey = peek('access_token', -1, 'tmpBearerKey');

	DROP TABLE tmpBearerKey;

	let vBearerLastGot = now();
	let vLastBearerKey = vBearerKey;
end if


let vMaxTweetURL = if(vMinTweet = 0, '', '&amp;amp;max_id=$(vMinTweet)');

RestConnectorMasterTable:
SQL SELECT 
	[... removed for brevity ...]
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION (  
      URL "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=$(vTwitterName)&amp;amp;trim_user=true&amp;amp;count=200$(vMaxTweetURL)",    
      HTTPHEADER "Authorization" "Bearer $(vBearerKey)"
    )
;
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck!&lt;/P&gt;
&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 11:29:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Automate-token-retrieval-from-Rest-API-for-sales-force/m-p/1920890#M10596</guid>
      <dc:creator>stevedark</dc:creator>
      <dc:date>2022-04-21T11:29:07Z</dc:date>
    </item>
  </channel>
</rss>

