API_ImportFromCVS functionality is not working

  • 0
  • 1
  • Question
  • Updated 3 months ago
  • Answered
Hi,
This is my API_ImportFromCVS function


function uploadData(){
console.log("Inside upload")

  if (patternFinalSku != "") {
  var url3 = "";
           url3 += "https://apollotyres.quickbase.com/db/bm7jkg5cj?act=API_ImportFromCSV";
            var qb_request = "";
                qb_request += "<qdbapi>";
                qb_request += "<records_csv><![CDATA[";
                qb_request += patternFinalSku;
                qb_request += "]]></records_csv>";
qb_request += "<clist>6.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.88.89.90.91.92.93.94.95.96.97.98.99.100.101.102.103.104.105.106.107.108.110.111.112.113.114.115.116.117.118.119.120.121.122.123.124.125.126.127.128.129.130.131.132.133.134.135.136.137.138.139.140.141.142.143.144.145.146.147.148.149.150.151.152.153.154.155.156.157.158.159.160.161.162.163.164.165.166.167.168.169.170.171.172.173.174.175.176.177.178.179.180.181.182.183.184.185.186.187.188.189.190.191.192.193.194.195.196.197.198.199.200.201.202.203.204</clist>";  // Your destination fields.
                qb_request += "<skipfirst>0</skipfirst>";
                qb_request += "</qdbapi>";
                 
$.ajax({
                    type: "POST",
                    contentType: 'text/xml',
                    async: false,
                    url: url3,
                    dataType: "xml",
                    processData: false,
                    data: qb_request,
                    success: function (response) {

                        var num_recs_input = $("qdbapi num_recs_input ",response).text();
                       
                       var  qb_recsadded = parseInt($("qdbapi num_recs_added ", response).text());
        
                    } // End success: function
                });
 }
}

need to insert/update into table through API_ImportFromCVS but it is not working.I really need  help to resolve it.Above code column no 6 is unique key in the table
Photo of Arti Dahiya

Arti Dahiya

  • 70 Points

Posted 4 months ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 27,884 Points 20k badge 2x thumb
If you place an AJAX call within a function your function should (1) take parameters and (2) return a promise.
function uploadData(<parameters>){
  return $.ajax({...});
});
uploadData(<parameters>)
  .then(function(response) {
  //further codehere
});
Other observations about your code:

(1) You should simplify the code you post to the minimal size that demonstrates the same problem or exemplifies the same issue you are asking about. Posting a long clist only generates noise and makes it more unlikely you will get an answer.

(2) Despite the API documentation and old answers in this forum, it is better to not supply the body of a POST as XML. See this sample code which calls API_ImportFromCSV without using an XML body:
$.post(dbidTable,{
  act: "API_ImportFromCSV",
  records_csv: "foo,bar,baz\n12,3\n4,5,6\n7,8,9",
  clist: "6.7.8"
}).then(function(xml) {
  console.dirxml(xml);
});

This is a general principle for almost all QuickBase APIs (unpublished and published). If the docs or source code you are looking at suggest you should send the POST body as XML:

<qdbapi>
  <foo>bar<foo>
  <baz>quux</baz>
</qdbapi>

You can in fact just send the body as an object

$.ajax(url, {
  action: "API_DoSomething:
  foo: "bar",
  baz: "quux"
});