Discussions

Expand all | Collapse all

Form Post API_ImportFromCSV Via PHP

  • 1.  Form Post API_ImportFromCSV Via PHP

    Posted 06-15-2018 15:47
    Hello:
    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 = "https://company.quickbase.com/db/";
    $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',
            'QUICKBASE-ACTION' => 'API_ImportFromCSV', // NOT SURE IF THIS IS CORRECT
            '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. 

    Thoughts?

    Thanks


  • 2.  RE: Form Post API_ImportFromCSV Via PHP

     
    Posted 06-15-2018 18:41
    have you tried using the QB PHP  API Wrapper?  Really nice to work with and it has a function for import CSV

    '''php
    import_from_csv ($records_csv, $clist, $skip_first = 0) 
    '''

    https://github.com/QuickbaseAdmirer/QuickBase-PHP-SDK


  • 3.  RE: Form Post API_ImportFromCSV Via PHP

    Posted 06-20-2018 15:37
    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!


  • 4.  RE: Form Post API_ImportFromCSV Via PHP

     
    Posted 06-16-2018 20:44
    You could also go get the amazing 'Postman' tool --> https://www.getpostman.com/

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



    ~Rob