Building QB Code Pages in Python

  • 38
  • 1
  • Question
  • Updated 6 months ago
  • In Progress
Hi, 

For building advanced API & custom codes in QB the options of code pages seems to be a great way to accomplish this. 

 In my case Python I am looking to make calls from inside QB to external systems using python as the main language. The platforms I wish to integrate with already have pre-built libraries ready, which will make the integration a lot easier.  

 -- (Oauth2 & Google API client libraries) --
 

But I am unable to find any use cases or help files that will help me learn more about the QB compatibility with Python.

So here is my questions: 

- Is it possible to create  and run a code page written in python that is using imported libraries ? 
- Can quickbase handle pip install and import commands ?


Photo of Shadi Hashem

Shadi Hashem

  • 222 Points 100 badge 2x thumb

Posted 6 months ago

  • 38
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
There is no ability to run any server-side code such as Python from a code page. If you want to capitalize on your Python skills you have to run your code from your own server or perhaps through one of the FaaS services (AWS Lambda, Google Cloud functions, Azure functions).
Photo of Shadi Hashem

Shadi Hashem

  • 222 Points 100 badge 2x thumb
Thanks for your response.. 

Python aside as I should be able to work with JSON requests through the webhook feature..
However I still have a problem with my Oauth credential. 

I have set up Oath to run in javascript in a code page, which will be executed on a formula button.
this does prompt the user with the consent screen, but when I try to run a webhook afterwards using the JSON method, I get error messages that I am not authorized / logged in.

seems that either QB dropping the token extremely fast or not able to store it at all.

Any advise on this issue ?


Thanks

Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
I would have to see the code to offer an opinion.
Photo of Shadi Hashem

Shadi Hashem

  • 222 Points 100 badge 2x thumb
Hi Dan, 

Sorry for the late reply.  

Now the actual auth is working and the google api passes back its access token to the users. But my problem is I am unable to store this access token for the user and use it in other API calls inside QB.
When trying to set up a webhook I would need to pass that access token manually in the URL to make a succesful call. 

I seem to have similar issues with other tokens which are not native QB tokens.

Is there someway to store an access token from a 3rd party either in a temporary QB record or in the local.storage of the user and then recall it from inside QB when triggering a  webhooks ?

My codepage looks like this:



/*
 * Create form to request access token from Google's OAuth 2.0 server.
 */
oauthSignIn();

function oauthSignIn() {
  // Google's OAuth 2.0 endpoint for requesting an access token
  var oauth2Endpoint = 'https://accounts.google.com/o/oauth2/v2/auth';

  // Create <form> element to submit parameters to OAuth 2.0 endpoint.
  var form = document.createElement('form');
  form.setAttribute('method', 'GET'); // Send as a GET request.
  form.setAttribute('action', oauth2Endpoint);

  // Parameters to pass to OAuth 2.0 endpoint.
  var params = {'client_id': 'xxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com', 
                'redirect_uri': 'https://domain.quickbase.com/db/bnzms2m4f',   
                'response_type': 'token',
                'scope': 'https://www.googleapis.com/auth/dfatrafficking https://www.googleapis.com/auth/dfareporting https://www.googleapis.com/auth/ddmconversions',
                'include_granted_scopes': 'true',
                'state': 'pass-through value'};

  // Add form parameters as hidden input values.
  for (var p in params) {
    var input = document.createElement('input');
    input.setAttribute('type', 'hidden');
    input.setAttribute('name', p);
    input.setAttribute('value', params[p]);
    form.appendChild(input);
  }

  // Add form to page and submit it to open the OAuth 2.0 endpoint.
  document.body.appendChild(form);
  form.submit();
  console.log(params);
}

 

Thanks 

Best regards 
Shadi