<?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 Calling a REST API in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Calling-a-REST-API/m-p/2419935#M95573</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Very very new on Qlik, but experienced with development and APIs.&lt;/P&gt;
&lt;P&gt;I'm trying to query data from a REST API.&lt;/P&gt;
&lt;P&gt;The process is twofold, first authenticate, grab a token in the response, then query the other APIs.&lt;/P&gt;
&lt;P&gt;On postman I can authenticate fine, and grab a success json object with the session token I can use to query other APIs.&lt;/P&gt;
&lt;P&gt;On click, I get a success=false and an empty token.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Feb 2024 10:30:45 GMT</pubDate>
    <dc:creator>hafer</dc:creator>
    <dc:date>2024-02-16T10:30:45Z</dc:date>
    <item>
      <title>Calling a REST API</title>
      <link>https://community.qlik.com/t5/App-Development/Calling-a-REST-API/m-p/2419935#M95573</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Very very new on Qlik, but experienced with development and APIs.&lt;/P&gt;
&lt;P&gt;I'm trying to query data from a REST API.&lt;/P&gt;
&lt;P&gt;The process is twofold, first authenticate, grab a token in the response, then query the other APIs.&lt;/P&gt;
&lt;P&gt;On postman I can authenticate fine, and grab a success json object with the session token I can use to query other APIs.&lt;/P&gt;
&lt;P&gt;On click, I get a success=false and an empty token.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 10:30:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calling-a-REST-API/m-p/2419935#M95573</guid>
      <dc:creator>hafer</dc:creator>
      <dc:date>2024-02-16T10:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a REST API</title>
      <link>https://community.qlik.com/t5/App-Development/Calling-a-REST-API/m-p/2423218#M95885</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/288632"&gt;@hafer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously there are many REST APIs and they behave in many different ways.&lt;/P&gt;
&lt;P&gt;To give some ideas on how it might work here are some extracts from a script to get data from the Twitter API. I think the API may have changed since I wrote this (and there is a native Qlik Twitter connector now), so this might not work, but it should give you an idea:&lt;/P&gt;
&lt;LI-CODE lang="markup"&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
		"token_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

// Connect to the GET library
LIB CONNECT TO '$(v_GET_Connector)';

RestConnectorMasterTable:
SQL SELECT 
	"created_at" AS "created_at_u0",
	"id" AS "id_u4",
	"id_str" AS "id_str_u4",
	"full_text" AS "text_u3",
	"truncated" AS "truncated_u0",
	"source" AS "source_u0",
	"in_reply_to_status_id" AS "in_reply_to_status_id_u0",
	"in_reply_to_status_id_str" AS "in_reply_to_status_id_str_u0",
	"in_reply_to_user_id" AS "in_reply_to_user_id_u0",
	"in_reply_to_user_id_str" AS "in_reply_to_user_id_str_u0",
	"in_reply_to_screen_name" AS "in_reply_to_screen_name_u0",
	"geo" AS "geo_u0",
	"coordinates" AS "coordinates_u0",
	"place" AS "place_u0",
	"contributors" AS "contributors_u0",
	"is_quote_status" AS "is_quote_status_u0",
	"retweet_count" AS "retweet_count_u0",
	"favorite_count" AS "favorite_count_u0",
	"favorited" AS "favorited_u0",
	"retweeted" AS "retweeted_u0",
	"lang" AS "lang_u0",
	"possibly_sensitive",
	"__KEY_root",
	(SELECT 
		"__KEY_entities",
		"__FK_entities",
		(SELECT 
			"text",
			"__KEY_hashtags",
			"__FK_hashtags"
		FROM "hashtags" PK "__KEY_hashtags" FK "__FK_hashtags"),
		(SELECT 
			"text" AS "text_u0",
			"__KEY_symbols",
			"__FK_symbols"
		FROM "symbols" PK "__KEY_symbols" FK "__FK_symbols"),
		(SELECT 
			"screen_name",
			"name",
			"id",
			"id_str",
			"__KEY_user_mentions",
			"__FK_user_mentions"
		FROM "user_mentions" PK "__KEY_user_mentions" FK "__FK_user_mentions"),
		(SELECT 
			"url",
			"expanded_url",
			"display_url",
			"__KEY_urls",
			"__FK_urls",
			(SELECT 
				"@Value" AS "@Value_u2",
				"__FK_indices_u2"
			FROM "indices" FK "__FK_indices_u2" ArrayValueAlias "@Value_u2")
		FROM "urls" PK "__KEY_urls" FK "__FK_urls")
	FROM "entities" PK "__KEY_entities" FK "__FK_entities")
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;tweet_mode=extended&amp;amp;count=200$(vMaxTweetURL)",    
      HTTPHEADER "Authorization" "Bearer $(vBearerKey)"
    )
;
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Twitter one is a nice example, as it requires a POST request to get the bearer key (after working out the Base64 version of the basic authentication key) and then a separate GET request, with the bearer key PEEKed out of the first call passed into the second. Many REST connectors are much simpler.&lt;/P&gt;
&lt;P&gt;Note that you can create a reasonably generic REST connection in Sense and then change the parameters using WITH CONNECTION in the call to the connector, but you do need separate GET and POST connectors.&lt;/P&gt;
&lt;P&gt;Hope that helps.&lt;/P&gt;
&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Sun, 25 Feb 2024 16:36:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calling-a-REST-API/m-p/2423218#M95885</guid>
      <dc:creator>stevedark</dc:creator>
      <dc:date>2024-02-25T16:36:01Z</dc:date>
    </item>
  </channel>
</rss>

