Forum Discussion

WalkerMarema's avatar
WalkerMarema
Qrew Member
5 years ago

API_ImportFromCSV Question

Hi guys, 

I've just started a new job as a Quickbase developer and I'm attempting to get familiar with the API doing my own personal projects with my builder account. 

I've noticed something that I simply cannot wrap my head around and I suppose it's just some little trick that I'm not seeing. 

I'm using the API_ImportFromCSV

I'm typing up the raw XML text using a python script and posting it to my table with a user token like so: 

payload='''payload='''<qdbapi> <usertoken>VALID TOKEN INSERTED HERE</usertoken>
<records_csv>
<![CDATA[Date, Test Field, 12-10-2019,Hello1, 12-11-2019,Hello2, 12-12-2019,Hello3]]>
</records_csv>
<clist>8.16</clist>
<clist_output>8.16</clist_output>
<skipfirst>1</skipfirst>
</qdbapi>'''

I then post the payload and a funny thing seems to happen. The response indicates that 4 records have been added to the table in question (not 3 as you might think would occur based on my CSV above). 
On the clist output, it consistently adds a blank record to my table. (A blank record meaning that both of the fields are blank). Here is a sample response: 
<?xml version="1.0" ?>
<qdbapi>
<action>API_ImportFromCSV</action>
<errcode>0</errcode>
<errtext>No error</errtext>
<num_recs_input>4</num_recs_input>
<num_recs_added>4</num_recs_added>
<rids>
  <rid update_id="1576035474677">54</rid>   
<fields rid="54" update_id="1576035474677">     
<field id="8">1575936000000</field>      <field id="16">Hello1</field>   </fields>  
<rid update_id="1576035474677">55</rid>   
<fields rid="55" update_id="1576035474677">      <field id="8">1576022400000</field>      <field id="16">Hello2</field>   </fields>  
<rid update_id="1576035474677">56</rid>   
<fields rid="56" update_id="1576035474677">      <field id="8">1576108800000</field>      <field id="16">Hello3</field>   </fields>  
<rid update_id="1576035474677">57</rid>   <fields rid="57" update_id="1576035474677">      <field id="8"></field>      <field id="16"></field>   </fields>
</rids>
</qdbapi>

Note the red text here. Why on Earth would it be adding blank values to a new record before ending the list? Do I have a fundamental understanding here of CSV's? 

Let me know. I'm very intrigued.

------------------------------
Walker Marema
------------------------------

2 Replies

  • Usually in my API CSV Import calls I include Repeat On and Repeat off, like below. Perhaps you need to tell the call to stop with this info. I'm not a pro at these but maybe this will help!

    <records_csv>
    <![CDATA[
    %RepeatOn%
    [Forecast Record List for Webhook]
    %Repeatoff%
    ]]>
    </records_csv>
    <clist>6</clist>
    </qdbapi>

    ------------------------------
    Leanne Snoeck
    ------------------------------
  • Welcome to the Quick Base family Walker!

    In my experience, validating what data is sent can be tricky. I assume within your Python script you can write to a console log or inspect the message that's sent. 

    If that's not available, the tool I use to troubleshoot my webhook payloads could be useful here. Requestbin (link) allows you to setup a temporary URL to point a message at, then see what data comes through the call. With this, you can determine the formatting of your data body and hopefully see where the extra line is coming from.

    Outside of the details above, I suspect that since a CSV file typically denotes separate records via a carriage return that the API is reading all four of your entries which includes the column header information. With that you could either remove that portion of your API call, or insert carriage returns for each line and the "skipfirst" parameter would then apply. For an example, see the details at the bottom of the API_ImportFromCSV documentation: https://help.quickbase.com/api-guide/importfromcsv.html

    ------------------------------
    Eric Mohlman
    ------------------------------