Discussions

Expand all | Collapse all

Building URL to download CSV

  • 1.  Building URL to download CSV

    Posted 08-12-2021 16:01
    Edited by Edwin Reik 08-12-2021 16:12

    I'm building some automations outside of Quickbase and have found the best way to pull data has been to build a URL using a usertoken that pulls data into a CSV that I process externally with python. 

    For previous tables I've used this basic format:
    qb URL: https://company.quickbase.com/db/dbID?a=q&qid=34

    url = 'https://company.quickbase.com/db/dbID(from original URL)?a=api_genresultstable&qid=34(from original URL)&options=csv&usertoken=private_token'


    However, when i build a URL call based on the URL below it pulls data from the wrong table... WHY.

    https://company.quickbase.com/db/dbID?a=q&qid=31

    ​Would love some insight on how to adjust my URL call to have it pull the correct data. 

    p.s. this works as long as I'm already signed in, but I need to do this when I'm not necessarily signed in:

    https://company.quickbase.com/db/dbID&opts=csv

    Thanks, 
    Ed

    ------------------------------
    Edwin Reik
    ------------------------------



  • 2.  RE: Building URL to download CSV

    Posted 08-12-2021 20:10
    I think the better option might be for you to look into using the API. The URLs that you're using are meant for access via the UI, so probably not the best way for you to grab information via an automated method.

    QuickBase API

    ------------------------------
    Blake Harrison
    bharrison@datablender.io
    DataBlender - Quickbase Solution Provider
    Atlanta GA
    404.800.1702 / http://datablender.io/
    ------------------------------



  • 3.  RE: Building URL to download CSV

    Posted 08-13-2021 08:59
    Edited by Edwin Reik 08-13-2021 10:38
    Thanks for the response Blake. 

    The URL calls work fine with my python automation but I'm open to a more robust option. I just need to automate pulling the table and saving it so I can manipulate the data. 

    I've been looking here: https://help.quickbase.com/api-guide/gen_results_table.html#URL_Alternative

    What would the API call look like? 

    ------------------------------
    Edwin Reik
    ------------------------------



  • 4.  RE: Building URL to download CSV

    Posted 08-13-2021 10:55
    I'd suggest you look into querying your Quickbase data directly utilizing the API. If you're working with Python, you can use the REST API here: https://developer.quickbase.com/operation/runQuery 

    Select the Code Samples tab and select Python from the drop-down and you'll get this code as an example query:

    import json
    import requests
    
    headers = {
      	'QB-Realm-Hostname': '{QB-Realm-Hostname}',
    	'User-Agent': '{User-Agent}',
    	'Authorization': '{Authorization}'
    }
    body = {}
    r = requests.post(
    'https://api.quickbase.com/v1/records/query', 
    headers = headers, 
    json = body
    )
    
    print(json.dumps(r.json(),indent=4))
    ​


    ------------------------------
    Blake Harrison
    bharrison@datablender.io
    DataBlender - Quickbase Solution Provider
    Atlanta GA
    404.800.1702 / http://datablender.io/
    ------------------------------



  • 5.  RE: Building URL to download CSV

    Posted 08-13-2021 12:59
    Edited by Edwin Reik 08-13-2021 12:59

    When I try this and print(r.url) I get the signin page. This is what happened when i tried to write my API request which i believe means I'm not getting in. 


    If you're able to support with building a URL that works I'd be satisfied. 

    'https://eagleview.quickbase.com/db/bpw3pr8nu?a=q&qid=31' + '&opts=csv' works when I'm signed in.

    'https://eagleview.quickbase.com/db/bpw3pr8nu?' + 'a=api_genresultstable&qid=31&options=csv&usertoken=SECRET' works when I'm not signed in, but downloads the wrong table! 

    'https://eagleview.quickbase.com/db/bpw3pr8nu?a=api_genresultstable&qid=31&usertoken=*secret*' (no mention of options csv) opens a page with the correct table present, but doesn't download the csv. This works when I'm not signed in.

    when I do the same as above but add '&options=csv' it downloads a CSV, but not the one that is being shown (same wrong one as mentioned above)... 

    What am I missing that can specify what the url is grabbing



    ------------------------------
    Edwin Reik
    ------------------------------



  • 6.  RE: Building URL to download CSV

    Posted 08-13-2021 13:43
    If you use the last URL you mention and include the CSV option and it's downloading the wrong fields, I'm going to guess it's downloading the default fields for that table. Most likely, you'll need to include the 'clist' parameter to identify the fields you want to download.

    ------------------------------
    Blake Harrison
    bharrison@datablender.io
    DataBlender - Quickbase Solution Provider
    Atlanta GA
    404.800.1702 / http://datablender.io/
    ------------------------------



  • 7.  RE: Building URL to download CSV

    Posted 08-13-2021 14:18
    I think that we're getting close but not 100% that this is the right solution. 

    When I use this method:
    'https://eagleview.quickbase.com/db/bpw3pr8nu?a=q&qid=31' + '&opts=csv' works when I'm signed in.​

    the csv that comes out is named X.

    But when I use the final method mentioned above:

    'https://eagleview.quickbase.com/db/bpw3pr8nu?a=api_genresultstable&qid=31&usertoken=*secret*' (no mention of options csv) opens a page with the correct table present, but doesn't download the csv. This works when I'm not signed in.
    
    when I do the same as above but add '&options=csv' it downloads a CSV, but not the one that is being shown (same wrong one as mentioned above)... 

    the csv comes out named Y. 

    I don't believe it's a matter of adjusting clist but I really have no idea. I think it's actually pointing in the wrong place



    ------------------------------
    Edwin Reik
    ------------------------------



  • 8.  RE: Building URL to download CSV

    Posted 08-14-2021 10:38
    "bpw3pr8nu" is the table DBID in your URL. Is this the correct DBID for the table where you want to pull information from? If so, then it's not possible that your URL is pulling information from a different source. According to the API documentation, if you utilize "API_GenResultsTable" and do not include the 'clist' parameter, it will return the fields that are included in the default report for that table. If those are not the fields that you are expecting / needing, you will need to include the 'clist' parameter.

    If the DBID is correct, I would compare a sample of the data you're downloading to the data as it appears in Quickbase. If, after doing that comparison, your download data does not appear in the records in Quickbase, I would suggest you submit a support ticket.

    ------------------------------
    Blake Harrison
    bharrison@datablender.io
    DataBlender - Quickbase Solution Provider
    Atlanta GA
    404.800.1702 / http://datablender.io/
    ------------------------------