Discussions

Expand all | Collapse all

Get an XML result from an API call into a field as a value

  • 1.  Get an XML result from an API call into a field as a value

    Posted 05-21-2019 01:13
    I have a formula button that returns the User ID of a user based on their email address.  I'm getting the result in an XML page and want to pass it to a field called User ID.

    Here's the formula that gets me the User ID.

    Here's the result it returns.

    How can I edit the formula to make the API call and pass the <user id="xxxxxx"> result to a field in one swoop?  I need this result in order to complete a button I'm using to send an invitation to the app.  The user ID is my missing link, which will pull this all together.

    Thanks for any help you can offer.

    Dana


  • 2.  RE: Get an XML result from an API call into a field as a value

    Posted 05-21-2019 01:19
    You have to reconfigure the way you're making the call to use Javascript instead of just a formula url. Basically you have to make the call, interpret the raw XML and then make a secondary API call to do an EditRecord or API_SendInvitation. 

    If you're using a standard URL button - you can inject Javascript like so:

    javascript: {
    $.get( api call to get user id , function(data,success) {
    var userid = parse xml response;
    $.get( make your editRecord call with the userid var );
    }) 
    }

    the first $.get request makes the initial API call. Then, once that returns successfully, you parse the response, then make a second API call using that response data, and then you have the desired effect.

    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 3.  RE: Get an XML result from an API call into a field as a value

    Posted 05-21-2019 01:57
    Thank you Chayce!  I figured it might be something along those lines.  I'll give it a try and see what I can come up with..

    Dana


  • 4.  RE: Get an XML result from an API call into a field as a value

    Posted 05-21-2019 02:04
    Hey Dana - feel free to reach out via email or this thread if you need any assistance. The syntax with single quotes versus double quotes for Quick Base gets tricky, more annoying than anything. So keep that in mind when working within your JS - everything should be kept within single quotes if possible


    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 5.  RE: Get an XML result from an API call into a field as a value

    Posted 05-21-2019 18:17
    Thanks Chayce, I certainly will.  I really appreciate your help.

    Dana


  • 6.  RE: Get an XML result from an API call into a field as a value

    Posted 05-21-2019 20:45
    Chayce,

    I'm stuck on the parsing the xml return of the User ID.  Can you elaborate on that further?

    Thanks,

    Dana


  • 7.  RE: Get an XML result from an API call into a field as a value

    Posted 05-21-2019 20:56
    Dana - see the below as one way to get the User Id

    "javascript: {" & 
      "$.get('" & $urlU & "',function(data,success) {" & 
            "console.log(data);" &
            "var user = data.getElementsByTagName('user')[0].getAttribute('id');" & 
            "console.log(user);" & 
            //"$.get('" & $urlE & "' + user);" & 
      "});" &   
    "}"

    In this case - I've declared urlU as the getUserInfo API call - then the User Id gets stored in a variable 'user' in the actual JS line. I've commented it out - but the second $.get is where you can set up your Edit Record call and include the user variable as part of the call

    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 8.  RE: Get an XML result from an API call into a field as a value

    Posted 05-21-2019 21:20
    Chayce,

    Am I on the right track here?

    var text urlU= "https://xxx.quickbase.com/db/main?a=API_GetUserInfo&email="; & [Email]; "javascript: {" &    "$.get('" & $urlU & "',function(data,success) {" &          "console.log(data);" &         "var user = data.getElementsByTagName('user')[0].getAttribute('id');" &          "console.log(user);" &  var text urlE= URLRoot() & "db/" & Dbid() & "?act=API_EditRecord" & "&rid=" & [Record ID#] &  "&apptoken=xxxxxx"  & "&_fid_435=";          "$.get('" & $urlE & "' + user);" &   "});" &    "}" 

    Thanks,

    Dana


  • 9.  RE: Get an XML result from an API call into a field as a value

    Posted 05-21-2019 21:27
    Wow!  I just realized it was working, I had to refresh the page in order to see it.  

    I'll have to tweak it a little, but this is exactly what I was trying to do.

    Thanks so much for your help Chayce, this is great.


  • 10.  RE: Get an XML result from an API call into a field as a value

    Posted 05-21-2019 21:28
    Ah - Great!

    If you want to force a refresh - after you make your editRecord call - you can do a window.location.reload() to force the page to refresh too. 

    so
    $.get();
    window.location.reload();


    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 11.  RE: Get an XML result from an API call into a field as a value

    Posted 05-21-2019 21:34
    Nice!  That is in place and does the trick.


  • 12.  RE: Get an XML result from an API call into a field as a value

    Posted 05-21-2019 21:27
    Dana - that looks spot on. I copied it over to QB just to check syntax - but it all looks right on point. Have you tested yet? 

    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 13.  RE: Get an XML result from an API call into a field as a value

    Posted 05-21-2019 21:30
    Our posts crossed there Chayce.  Yes, it's working great.  Now I just have to implement the User ID into my Invite button, which has to have the User ID.