Form Post API_ImportFromCSV Via PHP

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • Answered
Does anyone have an example of submitting a form post API_ImportFromCSV via PHP? 

We developed a scheduling form that successfully posts into QuickBase via Javascript, however, if you inspect the element, the user_token is available, which is a major security issue. We’ve solve this by creating a 2nd action page (ex. success.php), where we have this info in variables and handle the post from this page, however, we’re stuck with posting API_ImportFromCSV on this method.

To add context around the issue, we added a feature that allows us to schedule recurring appointments. The form looks like this:

On the form page, we have our submit function:
  $('#live_form').attr('action', "/success.php).submit();

On our success.php page, we have:

$qb_base_url = "";
$qb_stage_table2 = ‘abcdefghij’;
$user_token = “***********”; 
$url = $qb_base_url . $qb_stage_table2 . "?act=API_AddRecord&usertoken=" . $user_token;

$data = array(
    '_fid_7' => $_POST['_fid_7'], // DATEPICKER
    '_fid_8' => $_POST['_fid_8'], // DATE FROM
    '_fid_9' => $_POST['_fid_9'], // DATE TO

$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'Content-Type' => 'application/xml',
        'clist' => '7.8.9', // NOT SURE IF THIS IS CORRECT
        'content' => http_build_query($data)
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);

This method will only submit 1 record, since we're not including the csvdata that successfully posts via JS. Is there a way to include this into the array to post as API_AdddRecord, or a better way to post API_ImportCSV? The javascript method w/out PHP is the only way we have successfully looped through and submitted multiple records. 


Photo of Quincy Adam

Quincy Adam

  • 268 Points 250 badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of GH


  • 616 Points 500 badge 2x thumb
have you tried using the QB PHP  API Wrapper?  Really nice to work with and it has a function for import CSV

import_from_csv ($records_csv, $clist, $skip_first = 0) 
Photo of Quincy Adam

Quincy Adam

  • 268 Points 250 badge 2x thumb
Thanks GH. I'm not clear on how we utilize this function with the code defined above. How do we define $records_csv?

The code from my description works with posting a single record; we're just unsure how to use your function with the code from the description. Thanks!
Photo of Rob White IV

Rob White IV

  • 1,070 Points 1k badge 2x thumb
You could also go get the amazing 'Postman' tool -->

Develop your API in there and then generate the code for many languages.