How to edit multiple records through API. API_EditRecord

  • 2
  • 2
  • Question
  • Updated 4 years ago
  • Answered

I am trying to update multiple project records with one API call using a loop. This this possible? How?


HttpRequest req2 = new HttpRequest();

HttpResponse res2 = new HttpResponse();

Http http2 = new Http();

string body2 = '';

for(String projectId : projectMap.keyset()){

body2 = body2 = '<qdbapi><udata>UpdateQBProject</udata><ticket>'+id+'</ticket><apptoken>XXXXXXXXXXXX</apptoken>';

body2 = body2 + '<rid>'+projectId+'</rid>';

req2.setheader('QUICKBASE-ACTION','API_EditRecord');

body2 = body2 + '<field fid="1688">'+projectMap.get(projectId)+'</field>';

body2 = body2 + '</qdbapi>';

}

system.debug(body2);

req2.setEndpoint('https://XXXXXXXXXXXXXXXXXXXXX?');

req2.setheader('content-Length','');

req2.setHeader('Content-Type', 'application/xml');

req2.setMethod('POST');

req2.setBody(body2);

Photo of Bryan

Bryan

  • 10 Points

Posted 4 years ago

  • 2
  • 2
Photo of Jack

Jack, Champion

  • 50 Points
Here is a URL example of editing a record and then adding a record in another app:

In the case below the key thing to do is utilise the redirect to then redirect to the next api call.

URLRoot() & "db/" & Dbid ()
& "?act=API_EditRecord&rid=" & [Record ID#]
& "&apptoken=d44v7587hfhf84j4mk4fffght"
& "&_fid_36="&URLEncode(true)
& "&_fid_37="&URLEncode(false)
& "&_fid_39="&URLEncode(true)
& "&_fid_45="&URLEncode(false)
& "&rdr=" & URLEncode(URLRoot() & "db/buyjnbbgf?a=API_AddRecord&apptoken=bx245675843gbjfubxt7m4zv6r&_fid_49="&URLEncode([Link ID])
& "&_fid_36="&URLEncode([Price])
& "&_fid_38="&URLEncode([Net])
& "&_fid_39="&URLEncode([Tax])
& "&_fid_35="&URLEncode([Product])
& "&_fid_52="&URLEncode([Vendor])
& "&_fid_32="&URLEncode([Purchase method])
& "&_fid_37="&URLEncode([Price Line])
& "&_fid_53="&URLEncode([Supplier name])
& "&_fid_40="&URLEncode([Foreign Currency Unit])
& "&_fid_41="&URLEncode([Foreign Currency Amount])
& "&_fid_54="&URLEncode([Link ID])
& "&_fid_58="&URLEncode([Record ID#])
& "&_fid_69="&URLEncode([Reverse Lookup ID])
& "&rdr="& URLEncode(URLRoot() & "db/bihnh5j854"))

This was written some time ago. Hopefully this may help you decipher what you need.
Photo of QB_Support_Brian

QB_Support_Brian

  • 40 Points
Hi Bryan,

If every time your API call(s) are invoked you need to edit the same number of records you can use a formula as Jack described. However, if the number of records to be edited varies, you would need to write a custom script for that. This is because the QuickBase formula language does not include control structures such as loops. Something like Javascript could call API_EditRecord the proper number of times depending on the context in which your script was triggered.

In case you've not already started working with them, you can find a list of our QuickBase SDKs here:

https://github.com/QuickbaseAdmirer?tab=repositories


Unfortunately we're not able to support writing custom code via one of the SDKs, but perhaps some of the developers on this forum have coded something similar and can give you insight on how it works.



Thanks,

Brian