Forum Discussion

jross's avatar
jross
Qrew Cadet
2 months ago

Nesting URL API Calls in one Button

So, for years now this is one feature that has always eluded me due to the fact that I've never been able to get it to work.

How does one nest multiple API calls in a single button?  I've read the old article that talks about "rdr" and such, but the example only shows a single API call which doesn't help.  Right now I need this single button to ADD a new record in a specific table, which it does, but then EDIT the parent and then RETURN to the parent in edit mode.  This is what I have currently:

var text URLTwo =
                    URLRoot() & "db/" & [_DBID_TABLENAME] & "?a=API_EditRecord=" & "&apptoken=APPTROKEN"
                        & (If([THING1]=false, "&_fid_312=false" & "&_fid_304=false",""))
                        & (If([THING2]=false, "&_fid_36=false" & "&_fid_305=false",""))
                        & (If([THING3]=false, "&_fid_37=false" & "&_fid_306=false",""));

var text URLOne =
                    URLRoot() & "db/" &[_DBID_TABLENAME]& "?a=API_AddRecord" & "&apptoken=APPTROKEN"
                                & "&_fid_6=" & [Record ID#]
                                & "&_fid_7=" & URLEncode(User())
                                & "&_fid_8=" & Now()
                                & "&_fid_9=" & "Returned"
                                & "&_fid_23=" & $VARIABLE1
                                & "&_fid_24=" & $VARIABLE2
                                & "&_fid_25=" & $VARIABLE3 ;

//Return Button
var text ReturnButtonURL =
                            $URLOne
                            & URLEncode("&rdr=" & ($URLTwo))
                            & "&rdr=" & $ReturnURL ;

I've tried every variation I can think of with URLEncode(), but the only thing it does is run the FIRST API call which is API_AddRecord.  It runs that, then dumps me at the app's homepage.  Not once has it ran the second API_EditRecord call.  Again, it ALWAYS creates the required record, but the next steps do nothing.

Any insight on this would be ultra-appreciated.

  • Yep, been there,  done it,  bought the T-Shirt.

    It's unpublished and I really struggled with that too, a decade or two ago.

    Here is the generic syntax.  Just slice off as must of the salami as you need, keeping in mind that the last URL call needs to land the user on a record or a report or a Dashboard page or just refresh the page, or else it will spew the last XML success message back at the user.

    $URLONE 
    & "&rdr=" & URLEncode($URLTWO)
    & URLEncode("&rdr=" & URLEncode($URLTHREE))
    & URLEncode(URLEncode("&rdr=" & URLEncode($URLFOUR)))
    & URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLFIVE))))
    & URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLSIX)))))
    & URLEncode(URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLSEVEN))))))

     

    If you copy paste to a Quickbase record or Word doc it won't wrap and it will be easier to see the pattern.

    I have longer versions too.  At some point the URL gets too long for some browsers to handle.

    If you want to just refresh the page you are on, you can end with this step as $RefreshPage

    var text RefreshPage =  URLRoot() & "db/" & Dbid() & "?a=doredirect&z=" & Rurl();

     

     

     

  • Yep, been there,  done it,  bought the T-Shirt.

    It's unpublished and I really struggled with that too, a decade or two ago.

    Here is the generic syntax.  Just slice off as must of the salami as you need, keeping in mind that the last URL call needs to land the user on a record or a report or a Dashboard page or just refresh the page, or else it will spew the last XML success message back at the user.

    $URLONE 
    & "&rdr=" & URLEncode($URLTWO)
    & URLEncode("&rdr=" & URLEncode($URLTHREE))
    & URLEncode(URLEncode("&rdr=" & URLEncode($URLFOUR)))
    & URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLFIVE))))
    & URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLSIX)))))
    & URLEncode(URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLSEVEN))))))

     

    If you copy paste to a Quickbase record or Word doc it won't wrap and it will be easier to see the pattern.

    I have longer versions too.  At some point the URL gets too long for some browsers to handle.

    If you want to just refresh the page you are on, you can end with this step as $RefreshPage

    var text RefreshPage =  URLRoot() & "db/" & Dbid() & "?a=doredirect&z=" & Rurl();

     

     

     

  • Yep, been there,  done it,  bought the T-Shirt.

    It's unpublished and I really struggled with that too, a decade or two ago.

    Here is the generic syntax.  Just slice off as must of the salami as you need, keeping in mind that the last URL call needs to land the user on a record or a report or a Dashboard page or just refresh the page, or else it will spew the last XML success message back at the user.

    $URLONE 
    & "&rdr=" & URLEncode($URLTWO)
    & URLEncode("&rdr=" & URLEncode($URLTHREE))
    & URLEncode(URLEncode("&rdr=" & URLEncode($URLFOUR)))
    & URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLFIVE))))
    & URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLSIX)))))
    & URLEncode(URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLSEVEN))))))

     

    If you copy paste to a Quickbase record or Word doc it won't wrap and it will be easier to see the pattern.

    I have longer versions too.  At some point the URL gets too long for some browsers to handle.

    If you want to just refresh the page you are on, you can end with this step as $RefreshPage

    var text RefreshPage =  URLRoot() & "db/" & Dbid() & "?a=doredirect&z=" & Rurl();

     

     

     

  • Hey Mark, thanks for the reply.  I've restructured my nested URL variables as you showed above, but as far as I can tell the system is still only running the first API call; i.e. it isn't editing the parent and then still dumps me back at the app homepage.

    Is it not possible to go from an API_AddRecord run to an API_EditRecord run in the same button?

    • MarkShnier__You's avatar
      MarkShnier__You
      Icon for Qrew Legend rankQrew Legend

      Can you post your code?  It must have an error in the syntax.  You can chain together any APIs which don't need user input  (basically any API except API_GenAddRecordForm (although that one could be last)

  • Ah, disregard... In my hours of work on the URL chaining syntax, I missed a single "&rid=" in one of the URL's.  So after fixing that... IT WORKS!!!

    You have my thanks Mark!

    • MarkShnier__You's avatar
      MarkShnier__You
      Icon for Qrew Legend rankQrew Legend

      Ya, so the best idea is to copy paste in that standard nesting code,  and then just substitute in your URL formula variables in place of $URLONE  and $URLTWO etc.  I never try to just wing it.  I have an app with tips and tricks like that and I just go back there to grab that code each time.

      • jross's avatar
        jross
        Qrew Cadet

        Oh yes, this is absolutely going into my NotePad++ QB Tricks folder... haha!