How to I properly get a webhook to fire for AddRecord?

  • 2
  • 1
  • Question
  • Updated 2 years ago
  • Answered

I am just trying to figure out basic Webhooks. I want to trigger a webhook when a data record changes in Table 1 to add a record to Table #2. I set everything up with 1. When criteria are all set

2. Endpoint URL goes to the Table #2

3. XML, QuickBase-Action, API_AddRecord

4. I think the Message Body is where I'm goofing up, but I find the "help" too advanced. Any good reading suggests with examples to help me get going?

Field 9 is the one to be updated in Table #2, and [Inventory Total] is the record in Table 1 that changed to cause the webhook to fire.

<qdbapi>

<apptoken>--app token here---</apptoken>

<field fid="9">[Inventory Total]</field>

</qdbapi>

Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb

Posted 2 years ago

  • 2
  • 1
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 62,478 Points 50k badge 2x thumb
Try add a line like this 

 <usertoken>bxv4tx_bjix_8xxxxxxxx</usertoken> 


The Webhook actually runs under a userid and takes on that userid's permisisons.  So decide what userid it will run under, and then sign on as that user and go to "My Preferences under the user's name at the top right and then

Manage User Tokens


That will give you a long code, similar to the App Token, but in this case it essentially logs in under that userid to execute the Webhook.

A consideration is to choose a userid which will perhaps out survive your personal access to the app.  For example if you are an App Admin for a Company and you set up a bunch of obscure webhooks under you own userid and then choose not to be immortal, or at least choose not to be an employee for te next 100 years, then its a better idea to set up a Userid which will be owned by the IT department, and last longer than perhaps your personal access to the app.  

Once that userid assciated with the Usertoken l no longer has access to the app, then it will fail.
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
Mark, Thank you. the usertoken worked perfectly!!!
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
Can you point me to any more good resources for learning how to more robustly write the "message body" portion of webhooks? I'm a quick learner but the help is pretty thin. I prefer more examples to emulate...Thanks!!!!!
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 62,478 Points 50k badge 2x thumb
The help is pretty thin, I agree.  The best examples are in the API help under a particular API call where they give examples.

here is the API guide

http://help.quickbase.com/user-assistance/Default.html#apicalls.html

here, for example is the example for API_AddRecord

<qdbapi>
   <udata>mydata</udata>
   <ticket>auth_ticket</ticket>
   <apptoken>app_token</apptoken>
   <field name="event_name">party at Lindisfarne</field>
   <field name="description">dress in style of the epoch</field>
   <field name="location">lindisfarne island</field>
   <field name="start_time">06-08-0793</field>
   <field name="end_time">10-14-1066</field>
</qdbapi>

Example Using Field IDs

<qdbapi>
<udata>mydata</udata>
<ticket>auth_ticket</ticket>
<apptoken>app_token</apptoken>
<field fid="8";>party at Lindisfarne</field>
<field fid="9">dress in style of the epoch</field>
<field fid="10">lindisfarne island</field>
<field fid="11">06-08-0793</field>
<field fid="12">10-14-1066</field>
</qdbapi>


So best I can figure you do not need that <udata> line
You do not need <ticket>
but you do need the <usertoken> which is not documented there.
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
Thanks. Here's another question: I had a table with 6 new records added (via connected CSV), but the webhook only fired on 1 of the records? Shouldn't it have recreated 6 new records ?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 62,478 Points 50k badge 2x thumb
I know that Webhooks are "gated" to not run more than 10 per second on any single table.  But I can't explain why 6 did not fire.  You will need to put in a support ticket on that one.
Photo of Eric

Eric

  • 40 Points
API_AddRecord is for single record changes. API_ImportFromCSV is what's needed for your multiple record changes however. Here's what I built to accomplish that previously:

<qdbapi>

<usertoken>USERTOKENREMOVED</usertoken>

<records_csv>

<![CDATA[

%repeatOn%

[old.FieldName1.csv],[old.FieldName2.csv],[old.FieldName3.csv],[old.FieldName4.csv],[old.FieldName5.csv]

%repeatOff%

]]></records_csv>

<clist>22.16.18.88.12</clist>

</qdbapi>
Photo of dmaskasky

dmaskasky

  • 0 Points
This issue is that with multi-record edits, only one webhook would fire.  You would need to add 6 records under one webhook fire to capture the 6 changes.

Similar to how multi-record notifications work, try wrapping your data in %repeatOn% so that if multiple records are added at the same time, all records will be added.  Also, switch your api to API_ImportFromCSV so you can add multiple records.
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
Thanks!
Photo of Johnny QuickBase

Johnny QuickBase

  • 300 Points 250 badge 2x thumb
Hate to ask this and sound like a dummy.  What is <udata> and what is <ticket>??
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
The API guide talks about both of them. I wish there were a better more basic resource to explain this stuff, but I do a lot of copying what works.....
Photo of Eric

Eric

  • 40 Points
Nope, that's a great question. The udata is a piece of information you can pass along with an API call, and the response you receive back will contain that same information. Its use can be to track internal transactions, response times, etc.

The ticket is explained in the API_Authenticate documentation here: https://help.quickbase.com/api-guide/index.html#authenticate.html. In general, because API calls are performed from somewhere outside of your database, your application needs to know it's a valid call. Think of your application being locked, and using the API_Authenticate action will generate an access code that's valid for a certain timeframe. Subsequent API calls to your application will include that ticket to be successful.
Photo of Johnny QuickBase

Johnny QuickBase

  • 300 Points 250 badge 2x thumb
Ah Ok.   I'm actually trying out my first webhook of creating a record in one table when another record is created.  Trying to figure all of this out.  Thanks
Photo of Johnny QuickBase

Johnny QuickBase

  • 300 Points 250 badge 2x thumb
Can't seem to get mine to either trigger or work either.  I have a task table.  So wanted a webhook when a task is added, and assigned To is not equal to blank.  Then I've got API_AddRecord for a time table.
Endpoint URL is my time record table.
HTTP POST
Message format XML
Message header is QuickBase-Action and API_AddRecord

<qdbapi>
<usertoken>USERTOKENREMOVED</usertoken>
<field fid="46";>[Assigned To]</field>
<field fid="3">[Date Created]</field>
<field fid="24">6-Administration</field>
<field fid="34">0</field>
<field fid="40">webhook test</field>
</bdbapi>

I thought maybe it was as simple as putting the fid of what I want changed in table 2 and then the values from table 1, or what i'm typing directly.
Photo of Eric

Eric

  • 40 Points
It looks like your closing xml element is </bdbapi> instead of </qdbapi>. I also don't know if your first line will work because of the semicolon there. Try this instead:
<qdbapi>
<usertoken>USERTOKENREMOVED</usertoken>
<field fid="46">[Assigned To]</field>
<field fid="3">[Date Created]</field>
<field fid="24">6-Administration</field>
<field fid="34">0</field>
<field fid="40">webhook test</field>
</qdbapi>
Photo of Johnny QuickBase

Johnny QuickBase

  • 300 Points 250 badge 2x thumb
now see I tried both.  I had </qdbapi> first but then the example when looking at configure a webhook in QB showed </bdbapi>  lol
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 62,478 Points 50k badge 2x thumb
Have you looked at the error message history for the webhook.  is it not firing or is it failing?
Photo of Johnny QuickBase

Johnny QuickBase

  • 300 Points 250 badge 2x thumb
I did make sure i had any "required" fields for that 2nd table.
Photo of Eric

Eric

  • 40 Points
Would you submit a new support case by clicking Help -> Manage Support Cases? In your description mention that the rep assigned should ask me for details and I'll be happy to help troubleshoot this for you
Photo of Johnny QuickBase

Johnny QuickBase

  • 300 Points 250 badge 2x thumb
Does the endpoint URL need to be the table I want the record created on or something else?  I've got it set to the table I want the record created in.  do I leave the "?" off the end.  Can't seem to find anythign in API guide or otherwise to tell me which.
Photo of Eric

Eric

  • 40 Points
The endpoint URL is the table you're creating the record on. So, for your situation that's the time table
Photo of Johnny QuickBase

Johnny QuickBase

  • 300 Points 250 badge 2x thumb
Thanks!
Photo of Ringoparr

Ringoparr

  • 844 Points 500 badge 2x thumb
John, did you ever figure this one out?  I'm stuck in the same spot you've described above.
Photo of Ringoparr

Ringoparr

  • 844 Points 500 badge 2x thumb
John, i figured out the issue you ran into!  Your user token needs to be enclosed with %

i.e. <usertoken>%USERTOKENREMOVED%</usertoken>