API_AddRecord works, API_GenAddRecordForm doesn't.

  • 0
  • 1
  • Question
  • Updated 7 months ago
  • Answered
API_GenAddRecordForm works fine for me when calling it from a webpage, but from my javascript page I only seem able to get API_AddRecord to work, but it doesn't take me to the record after generating it.  And, when I try API_GenAddRecordForm from Postman, instead of a qdbapi error report I get thousands of lines of html code.  My goal is to generate a new record and then view it in Edit mode from my javascript page.  What would be the correct syntax for that API call?  Thank you!
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb

Posted 7 months ago

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

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,262 Points 20k badge 2x thumb
Everything is working properly - there is just some confusion over how to use the API calls.

The vast majority of the API methods return a single XML document as a response. The method API_GenAddRecordForm is an exception as it returns a HTML document as a response and included in this response are links and references to other resources such as JavaScript files, CSS files, font files etc.

When  API_GenAddRecordForm is loaded from a hyperlink or entered into the address bar of a Browser, the Browser will make additional calls to the other resources and assembles everything into a visible page. However, when Postman loads API_GenAddRecordForm it only grabs the raw HTML response and does not request the other resources nor does Postman render the page (it isn't a browser and doesn't even have a rendering engine).

This explains everything your report.

The area where you are probably going astray is that in your JavaScfipt you are probably calling API_GenAddRecordForm using:
$.get("...?act=API_GenAddRecordForm...") 
when you should be using:
document.location.href = "...?act=API_GenAddRecordForm..."
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb
Aha - that explains a lot.  Thank you!
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb
But actually, I'm using :

var url = "https://xxxx.quickbase.com";  
  url    += "/db/";
  url    += "abcdefghi";
  url    += "?a=API_AddRecord";

and then the url gets called from $.ajax

so now I'll try rewriting the javascript without the .ajax 
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,262 Points 20k badge 2x thumb
That API call returns XML which is not human readable. The XML response to API_AddRecord needs to be parsed with JavaScript to determine if the record was actually added without error (it normally is so you often just skip this step and proceed to the next step in the workflow).
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb
Honestly, I'm not sure what that means (as previously mentioned, I'm a self-taught hack), BUT - your answer worked!  I got it to do what I wanted it to do.  Thank you thank you!