How To Delete Record From Report Embedded On External Website

  • 0
  • 2
  • Question
  • Updated 11 months ago
  • In Progress
I have a delete button on my report, which works fine when I'm in QuickBase, but it will not work when the report is embedded on another website. My goal is to have the capability to delete a record from an external site, so if there's other suggestions how to do this, that's ultimately what I'm trying to achieve. 
Here's the code I'm using on the button:

////////// ATTEMPT #1: CODE I FOUND FROM FORUM
"javascript:if(confirm ('Are you sure you want to delete this record?')){location.assign( '/db/" & Dbid() & "?act=API_DeleteRecord&apptoken=xxxxxxxxx&rid=" & [Record ID#]& "&rdr=" & URLEncode("https://www.website.com") & "')}"
//////////
I have attempted hardcoding the root domain since it assumes you're in QB, but had not luck.

/////////// ATTEMPT #2: ANOTHER CODE I FOUND ON THE FORUMS
var text URL= URLRoot() & "db/" & Dbid() & "?act=API_DeleteRecord&rid=" & [Record ID#]
& "&apptoken= xxxxxxxxx";
"javascript: " &
"if ( confirm('Are you sure you want to permanently delete this record ? ') == true ){ "&
"$.get('" & 
$URL & 
"',function(){" &
"location.reload(true);" &
"});" 
& "void(0);"&
"}"
//////////

The 2nd attempt works the same, but does not have a redirect on it back to the page I'd like it to go back to.

1. Is there a way for a externally embedded report to delete a record and redirect back to the external page? If not,
2. Is there a better way of deleting records from an external Wordpress site? I looked into the API integrations, but haven't found any clear examples.
Photo of Quincy Adam

Quincy Adam

  • 268 Points 250 badge 2x thumb

Posted 11 months ago

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

QuickBaseCoach App Dev./Training, Champion

  • 53,722 Points 50k badge 2x thumb
I can't help you on the javascript syntax, but I do know that everything in Quick Base has to operate under the permissions of a userid.

You can use a usertoken to provide that Authentication.
https://help.quickbase.com/api-guide/create_user_tokens.html

you need to add the string

&usertoken=xxxxxxxxxxxxx

 and provide a valid user token.
Photo of Avi Sikenpore

Avi Sikenpore

  • 544 Points 500 badge 2x thumb
Quincy,

Mark's method should be able to easily delete the record. However you need be aware of the fact that exposing usertoken on an external website is a security risk.

If you external website is public, I would suggest you basically add a new record in some table known as delete requests capturing the record ID of the original record.

Setup a webhook from that table to perform an API_DeleteRecord at the desired table.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,612 Points 50k badge 2x thumb
Good thought.
Photo of Kevin O'Boyle

Kevin O'Boyle

  • 602 Points 500 badge 2x thumb
Avi - would you create a new/unique usertoken in this instance only for the delete requests tables ?(is that the best way)
Photo of Quincy Adam

Quincy Adam

  • 268 Points 250 badge 2x thumb
Thanks. I figured out the JS piece above. I just prepended the base URL onto /db like this:

"javascript:if(confirm ('Are you sure you want to delete this record?')){location.assign( 'https://company.quickbase.com/db/"; & Dbid() & "?act=API_DeleteRecord&apptoken=xxxxxxxx&rid=" & [Record ID#]& "&rdr=" & URLEncode(“WEBSITE TO REDIRECT TO”) & "')}"

I didn't assign a user token, since the report is public (or set to Everyone On The Internet). I need to do more reading up the link you had sent over, since I don't fully understand the difference between the different tokens and tickets.  

In the event that I restrict it and I choose to use an API_DeleteRecord, what is the best method to fire the delete record. For example, do I just hardcode the link (https://company.quickbase.com/db/xxxx?a=API_DeleteRecord&rid=13&rdr=WEBSITETOREDIRECTTO), which achieves the same as the JS above, or to Avi's point, would I use like a PHP POST to hide the apptoken?