Discussions

Expand all | Collapse all

API_UploadFile with JSON data

  • 1.  API_UploadFile with JSON data

    Posted 08-15-2017 22:11
    Hey!
    Probably a stupid question but I can figure out is there is a way to provide JSON data to an API_UploadFile call. At the moment I use xml data like this:
    var req = "";
    req += "<qdbapi>";
    req += "<apptoken>" + QBU_apptoken + "</apptoken>";
    req += "<rid>1</rid>";
    req += "<field fid='6' filename='" + fineName" + "'>";
    req += fileContent;
    req += "</field>";
    req += "</qdbapi>";
    $.ajax({
        url: QBU_tabledbid + "app?act=API_UploadFile",
        type: 'POST',
        data: req,
        contentType: "text/xml",
        dataType: "xml",
        processData: false
    });
    But I would prefer something like 
    $.post(QBU_tabledbid, {
        act: "API_UploadFile",
        rid: 1,
        field: {
            fid: 6,
            filename: fileName,
            value: fileContent
        }
    }) 
    but I am struggling to find the correct syntax...
    Thank you!
    Adrien


  • 2.  RE: API_UploadFile with JSON data

    Posted 08-16-2017 03:31
    Please first validate your JSON data using these tools.



  • 3.  RE: API_UploadFile with JSON data

    Top
    Contributor
    Posted 08-16-2017 16:41
    QuickBase's API are skewed towards using XML for both the request and response. There is no JSON supported in the API. You could write a wrapper around their API that consumed JSON but it would be a very thin wrapper and probably would not be worth the effort in just this one instance of preferring JSON over XML.

    That said you can upload files using Fetch and the FormData API as demonstrated here for copying file attachments between files.

    https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=574

    This script does not even use the QuickBase API and it demonstrates that advances in the browser and web technologies are making old ways of doing things obsolete. You will not take advantage of the bounty of new features and technologies that are in your browser unless you stop relying on old ways of doing things. 


  • 4.  RE: API_UploadFile with JSON data

    Posted 08-16-2017 20:32
    Thanks for that instructive answer.  I definitely need to dive into the Fetch API...
    Like your eclipse btw,
    Cheers


  • 5.  RE: API_UploadFile with JSON data

    Bronze
    Contributor
    Posted 08-08-2019 17:54
    Dan, you did it again... This was exactly the situation I was looking for.

    Your notation for the URLs, you're using the URL notations of just queries/edit records like the native QB UI does... so you're not even using the actual API right?