Forum Discussion

JonJon's avatar
JonJon
Qrew Trainee
12 years ago

How do you use API to add a user and then send an invitation?

I have created a form that contains 3 fields, First Name, Last Name, and email. I would like to be able to create a button with a formula URL field that takes that information and does 3 things:

1. Adds a new user
2. Sends an invitation to the new user
3. Signs out the current user

I understand that API calls can do this but I can't figure out how to use the API_ProvisionUser to feed into the API_SendInvitation

Does anyone know how to do this? Thanks!!!


  • OK Jon. Her is one solution.

    1 - Create a formula url that has the domain,app_dbid,roleid,email,fname and last name as below. Also load the QuickBaseClient,js:

    "javascript:" &"var QBU_domain='https://xxx.quickbase.com'" & ";" &"var QBU_dbid='bedmkj7zj'" & ";" &"var QBU_roleid='11'" & ";" &"var QBU_email='souheil.karam@gmail.com'" & ";" &"var QBU_fname='souheil'" & ";" &"var QBU_lname='karam'" & ";" &"var scriptElem = document.createElement('script');" &" scriptElem.setAttribute('language', 'JavaScript');" &" scriptElem.setAttribute('src', '/js/QuickBaseClient.js'); " &" document.body.appendChild(scriptElem);" &" function loadScript(scriptURL) {" &" var scriptElem = document.createElement('script');" &" scriptElem.setAttribute('language', 'JavaScript');" &" scriptElem.setAttribute('src', scriptURL); " &" document.body.appendChild(scriptElem);" &"}" &" loadScript('/db/" & Dbid() & "?act=dbpage&pagename=SendInvitationToUser.js');"

    2 - Create a user file in your quickbase call it SendInvitationToUser.js with the code below:
    function SendInvitationToUser() { var rc; var qdb = new QuickBaseClient(QBU_domain); rc = qdb.errorcode; // if success, begin process if ( rc == 0 ) { // provision the user var userid = qdb.ProvisionUser (QBU_dbid,QBU_roleid,QBU_email,QBU_fname,QBU_lname); rc = qdb.errorcode; if ( rc ==0) { // we have a userid let us invite him with the roleid var Invitation = qdb.SendInvitation(QBU_dbid,userid); } } if ( rc == 0 ) alert("success"); else alert("failure"); } // call on load
    SendInvitationToUser();
  • Hello Jon,

    You probably prefer the code. I will make time to write it if this explanation does not work for you. I will assume that the user has never been registered in your quickbase application:
    Once you have the user last name, first name, email address then you may go thru the following:

    You must have Basic Access (able to view/add/modify records, depending on permissions)
    1 - Invoke API_GetRoleInfo api to get your available roles, You will get back
    An aggregate containing one or more roles, structured as follows:
    <roles>
    <role id="11">
    <name>Participant</name>
    <access id="3">Basic Access</access>
    </role>
    </roles
    Each role returned has a role ID as an attribute and contains a role name and the application access level that is conferred by the role.



    2 - Get the role_id from the response

    3 - Get the dbid for the application that you want the user to have access to.

    4 - Provision the user by calling the API_ProvisionUser with the parameters below on the above dbid

    <qdbapi>
    <ticket>2_bdh78chd4_dpsx_b_dnbypa8d372j5rb6vt6kfdx7ty25</ticket>
    <apptoken>dtmd897bfsw85bb6bneceb6wnze3</apptoken>
    <roleid>11</roleid>
    <email>sanskor@sbcglobal.com</email>
    <fname>Margi</fname>
    <lname>Rita</lname> </qdbapi>

    if success the api will return the user_id as follows:
    <qdbapi>
    <action>api_provisionuser</action>
    <errcode>0</errcode>
    <errtext>No error</errtext>
    <userid>112248.5nzg</userid>
    </qdbapi>

    5 - Now, use API_SendInvitation using the return user_id from provision user api

    <qdbapi>
    <ticket>2_bdh78chd4_dpsx_b_dnbypa8d372j5rb6vt6kfdx7ty25</ticket>
    <apptoken>dtmd897bfsw85bb6bneceb6wnze3</apptoken>
    <userid>112249.ctdg</userid>
    <usertext>Welcome!</usertext> </qdbapi>



    6 - If success - Voila!!!
    <qdbapi>
    <action>API_SendInvitation</action>
    <errcode>0</errcode>
    <errtext>No error</errtext>
    </qdbapi>
  • JonJon's avatar
    JonJon
    Qrew Trainee
    This is very helpful in understanding how it works.  Thanks for taking the time to answer me.  I am still hazy as to how the code will know how to get the user ID from the response and use it in the send invitation.  I'm missing something.  Can you write the code as it would be typed into the Formula URL field so I can see it in action?  Thanks again!
  • sckaram,
    I know this is an old thread but fits what I am trying to solve for.  Unfortunately I am still new to QB and cannot get this to work. 
    I have added the above solution, part 1 to a code page, part 2 to a url formula field. 
    Is this method still viable?