# Update after Form Submit

**URL:** <https://forums.knack.com/t/update-after-form-submit/6685>\
**Category:** API & Custom Code\
**Created:** [August 2, 2019, 4:00pm UTC](https://forums.knack.com/t/update-after-form-submit/6685 "2019-08-02T16:00:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartinCraw46088](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@MartinCraw46088](https://forums.knack.com/u/MartinCraw46088)\
**Post date:** [August 2, 2019, 4:00pm UTC](https://forums.knack.com/t/update-after-form-submit/6685/1 "2019-08-02T16:00:34Z")

</div>

I need some help with updating a record after a form submit.

The following code work nicely, except it exposes the API Key. My understanding is this is an object update.

$(document).on('knack-record-create.view\_1084', function(event, view, record) {

$.ajax({  
 url: "[https://api.knackhq.com/v1/objects/object\_79/records/](https://api.knackhq.com/v1/objects/object_79/records/)" + record.id,  
 type: "PUT",  
 headers: {  
 "X-Knack-Application-Id": KnackAppID,  
 "X-Knack-REST-API-Key": KnackAPIKey  
 },   
 data: {  
 field\_760 : NewDescription,  
 },  
 success: function(response) {   
 console.log("Done!");   
 alert(record.field\_760\_raw);  
 }  
});

});

I have tired converting to using a View Update using the following code and it does not work.

$(document).on('knack-record-create.view\_1084', function(event, view, record) {

$.ajax({  
 url: "[https://api.knack.com/v1/pages/scene\_556/views/view\_1084/records/"+record.id](https://api.knack.com/v1/pages/scene_556/views/view_1084/records/%22+record.id),  
 type: "PUT",   
 headers: {  
 "X-Knack-Application-Id": KnackAppID,   
 "Authorization": Knack.getUserToken()  
 },  
 data: {  
 field\_760 : NewDescription,  
 },  
 success: function(response) {   
 console.log("Done!");   
 alert(NewDescription);  
 }

});

The alert shows the correct data to be saved, however it does not make the change using the second set of code.

Thanks

Martin

---

<div class="post-metadata">

**Author:** ![BradStevens](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/bradstevens/32/140_2.png) [@BradStevens](https://forums.knack.com/u/BradStevens)\
**Post date:** [August 9, 2019, 9:33pm UTC](https://forums.knack.com/t/update-after-form-submit/6685/2 "2019-08-09T21:33:59Z")

</div>

Martin - looks okay to me but a few things to check:

- Scene & views numbers are correct for your app.
- The variable KnackAppID is correctly set (it's not set inside this code) - perhaps use the Knack function Knack.app.id instead.

---

<div class="post-metadata">

**Author:** ![TingLing03337](https://avatars.discourse-cdn.com/v4/letter/t/9e8a1a/32.png) [@TingLing03337](https://forums.knack.com/u/TingLing03337)\
**Post date:** [August 8, 2019, 4:13am UTC](https://forums.knack.com/t/update-after-form-submit/6685/3 "2019-08-08T04:13:09Z")

</div>

Hi, I had some success in using the API without exposing my key when I was fiddling with Power query in Excel or using Power BI last year.. and I remember I had to pass a request to Knack firstly to get a user token.. and then passing a second request back to Knack after getting the token back from Knack from the first request. Not sure if that's the issue here, but hope it helps you somehow

I wrote my experience here.. Good luck anyway

[https://support.knack.com/hc/en-us/community/posts/360029613471-Remote-login-request-with-Power-query-Power-BI](https://forums.knack.com/hc/en-us/community/posts/360029613471-Remote-login-request-with-Power-query-Power-BI)
