CORS violations on API calls?

None of what you are asking is dumb, we found it very frustrating when we started. I completely agree about the limitations of Knack. When we first started, we could not believe that you could only update one object at a time with a form.

Having said that, the view-based requests are the way to go. We have quite a few views that are hidden and we have a whole login page where we store views that are only used for API calls, which we untick the box show in menu:

image

If you are updating existing records, then you will need tables that show each field you would like to update. With inline editing turned on. You will also need the Knack record ID of the record that connects all your objects. You can get this dynamically using code or from an API GET or even from the URL.

You can also use filters to zone in on specific records, so you don’t have to do as much cycling through records.

Here is an example of a function that will create some filters:

function createFilters(recordId, valToMatch) {
    return {
         'match': 'and',
         'rules': [
             {'field': 'field_xxx', 'operator': 'is', 'value': recordId}, 
             {'field': 'field_yyy', 'operator': 'is', 'value': 'valToMatch' }
         ]
    };
}

We have an API function that deals with all of our call and it got quite complex but it will do:

  • Parent > Child GET - used if you need data from the child record of the record ID you pass in this works slightly differently to other type of GET as you need to pass in the recordId and the slug of the scene where the view exists that you are trying to get the data the URL looks a bit like this:
https://api.knack.com/v1/pages/" + sceneId + "/views/" + viewId+ "/records/?" + sceneSlug + "_id=" + recordId
  • It can also take filters to get specific records the URL looks like this:
https://api.knack.com/v1/pages/" + sceneId + "/views/" + viewId+ "/records/?filters=" + encodeURIComponent(JSON.stringify(apiFilter))
  • PUT URL:
"https://api.knack.com/v1/pages/" + sceneId + "/views/" + viewId+ "/records/" + recordId
  • POST URL:
"https://api.knack.com/v1/pages/" + sceneId + "/views/" + viewId+ "/records/"

In all URLs
sceneId = scene_1234
viewId = view_5678
recordId = The Knack record id which can be found in the URL or the row Id of a grid
sceneSlug = the Page URL

I hope this makes sense. It took us quite a while to figure everything out.

The link above is a question my partner and I asked which has the Ajax call we pretty much use for all API types.

If you need any help with this or something isn’t clear please let me know.

Craig