Skip to main content
Announcements
Qlik Connect 2025! Join us in Orlando join us for 3 days of immersive learning: REGISTER TODAY

Connect Qlik Sense Rest API to oAuth2 APIs (e.g. CVENT Core)

100% helpful (1/1)
cancel
Showing results for 
Search instead for 
Did you mean: 
Meghann_MacDonald

Connect Qlik Sense Rest API to oAuth2 APIs (e.g. CVENT Core)

Last Update:

Aug 12, 2024 3:49:13 AM

Updated By:

Sonja_Bauernfeind

Created date:

Aug 12, 2024 3:49:13 AM

This article documents the use case scenario of using CVENT Core.

This customization is provided as is. Qlik Support cannot provide continued support of the solution. For assistance, reach out to our Professional Services or engage in our active Integrations forum.

Qlik has used CVENT Core to organize sessions for Qlik Connect, allowing Qlik to extract data hourly into a Qlik Sense app.

Cvent Core uses 2-legged oAuth2. Qlik Application Automation's oAuth2 connectors currently only support 3-legged oAuth2, so I had to work around by connecting straight to Qlik Sense REST Connector, where we could do 2-legged. Here's how we did this. 

Setup

  1. Get your credentials, which you need to make the first token call. Make sure you can login to your workspace and create application to get a client_id and client_secret. Have these open and ready to copy. Here's a walkthrough if you're having trouble finding them: Developer quickstart. And send this to your CVENT manager if you can't access: Inviting your developers.

  2. Create the token refresh connector in Qlik Sense and get your first access token. Create new connection > REST API. Use the following details:

    • URL: https://api-platform.cvent.com/ea/oauth2/token
    • Method: POST (empty body)
    • Check: Add 'Expect: 100-continue' header
    • Authentication Schema: Anonymous
    • Query Parameters:
      • grant_type: client_credentials
      • client_id: {your client id}
    • Query headers:
      • Content-Type: application/x-www-form-urlencoded
      • Authorization: Basic {your client secret}

  3. No need for WITH CONNECTION or Pagination. Test this connection and save it, with a name like CVENT_TOKENREFRESH. Then click to select data on the connector and click the root table.

    This lists your first bearer token, which will expire in 60 min, but will be valid long enough to set up your session or attendee connectors. If your token expires, simply "select data" again to regenerate another. We don't need this quite yet, so click cancel for now.

  4.  Add script to regenerate token on app reload to the beginning of your data load script. Add the following to the beginning of your load script, or just before your CVENT data. This script will use the connector you just made to generate the token and save it as a variable "vAuthToken".

    // Get access token using Basic Auth
    LIB CONNECT TO 'QlikWorld:CVENT_TOKENREFRESH';
    TokenRaw:
    SQL SELECT 
    "access_token"
    FROM JSON (wrap on) "root";
    [Token]:
    LOAD [access_token]
    RESIDENT TokenRaw;
    DROP TABLE TokenRaw;
     let vAuthToken=peek('access_token',-1);
     drop table Token;
    //Trace $(vAuthToken);
  5.  Create your CVENT session data connector (or any other connector you need from the APIs, reference here) using the original token. First, click "select data" on your TOKENREFRESH connector to pull up the screenshot above, and click the token to copy it to your clipboard. Then, click Create new connection > REST API and use the following details. For this example I'll create a connector to List Sessions. Many details like the url, method, and pagination can be found in the documentation
    • URL: https://api-platform.cvent.com/ea/sessions
    • Method: GET
    • Query parameters: N/A
    • Query headers: 
      • Authorization: Bearer {your first token, copied to clipboard}
      • Accept: application/json
    • CHECK: Allow "WITH CONNECTION"
    • Pagination
      • Pagination type: Next token
      • 'Next token' parameter name: token
      • 'Next token' path: root/paging/nextToken
      • Do NOT check "pass via header" or "look in header"

  6. Name, test, and save your connector. Then, select data from the connector and add all your tables.

  7. Adjust connector script to utilize new access token instead of original. Since the session connector was set up with the access token we generated, it will only work for 60 minutes! However, since we checked off "Allow "WITH CONNECTION", we can tell the connector to use a different value for the header / authorization token each time (aka, our vAuthToken variable). Go to your sql script and add the following bolded script, right before the final semicolon (do not add the italic script, that should already be there):

    FROM JSON (wrap on) "root" PK "__KEY_root"
    WITH CONNECTION (
    HTTPHEADER "Authorization" "Bearer $(vAuthToken)"
    );
  8. Load your app and test that this is working as designed. Use this same process of steps 4 and 5 for any other event call you need to make, such as Enrollment, Surveys, and more. 

 

Limitations

  • If you need to add new fields to the {session} connector, you will need to generate another token by "selecting data" from the token refresh connector, copy it, edit the {session} connector to add the new token, saving it, and selecting data from the {session} connector, and add the fields. This makes it challenging to collaborate. Better to just add every field at the beginning when you do setup and drop what you don't need.
  • Security issues - if you are using your credentials to generate the token, make sure the connector is in a secure shared space and not somewhere that can be accessed by anyone in your tenant, and mask the variable or do what you need to do there. 
  • Writeback: not sure how I will do this since it requires app automation which can't do 2-legged. But I'll update here if we figure it out next year. 

 

Related Content

Labels (1)