Record ID for use in the API

Hi all,

I'm just starting work with the API data and it is asking me for a record id that doesn't seem to appear anywhere in the builder. Its the long gibberish kind (see below). Any recommendations on where to find it?

"id": "5ee2517d7b94b2001587ea41",

 

I don't want to get in trouble for solicitation here but if you type in knack or integromat for skills, I should be one of the first people that pops up :)

Hi Boris,

You need to get the record.id for the connection field from the dom and save it as a variable. Then add that field and value to the 'data' section of the script. It would look something like this.

var connectionId = $(''#selector').text();  //Find the recordId of the record you want to connect in the dom or extract from the url.

then later on in the data section, find this:

 

  // Replace scene ID and view ID from new scene created in step 2

    url: Knack.api_url + '/v1/pages/scene_XXX/views/view_XXX/records',

    data: {

      field_XXX: fileId // Replace Field ID of the new object

     Field_xxx: connectionId //Match to correct field ID, connectionId will be the variable we saved befroe

    }

I can't tell you exactly where to find that value without access to your app. Hope this helps.

You can find me on Upwork if you want a little scripting help.

 

All the best,  Justin

Thanks Justin!

Thank you Justin!

If you inspect (right click and then click inspect) any record you can manually get the record id that way.

Another way is to create a text field for the record.id on the object and then use integromat, zapier or javascript to populate that field when a record is created. 

Something like this but it's even easier to do with integromat.

//scene_210/views/view_734
$(document).on('knack-record-create.view_432', function(event, view, record) {


var UrlBase = "https://api.knack.com/v1/pages/page_210/views/view_734/records/";  //replace with your scene and view

/* THE URL BASE represents a page where you edit a particular record that you would like to record a record id for. make sure that there the record.id field is in the form. You can hide the page that hosts this view or use an existing edit view accesible to the user role and just hide the record id field using display rules or css. Knack has a similar example in the dev docs but this is the better way to do it as you will not expose your api key*/


// var target = url[url.length - 2];
var target = record.id
console.log('target is:', target);
var url = UrlBase + target;
var headers = {
'Authorization': Knack.getUserToken(),
'X-Knack-Application-Id': Knack.application_id,
'Content-Type': 'application/json'
};
// Set our short text field's value to the newly created record's Knack ID
var data = { field_468: record.id } //this is the record.id field.
console.log("Sending request - update record.id field");
Knack.showSpinner();
// Make the AJAX call
$.ajax({
url: url,
type: 'PUT',
headers: headers,
data: JSON.stringify(data),
}).done(function(responseData) {
console.log('Record updated!');
Knack.hideSpinner();
});
});