API_UploadFile with JSON data

  • 0
  • 1
  • Question
  • Updated 2 years ago
  • Answered
  • (Edited)
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
Photo of Adrien Gregorj

Adrien Gregorj

  • 140 Points 100 badge 2x thumb

Posted 2 years ago

  • 0
  • 1
Photo of iris panabaker

iris panabaker

  • 80 Points 75 badge 2x thumb
Please first validate your JSON data using these tools.

Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
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. 
Photo of Adrien Gregorj

Adrien Gregorj

  • 140 Points 100 badge 2x thumb
Thanks for that instructive answer.  I definitely need to dive into the Fetch API...
Like your eclipse btw,
Cheers