Connecting multiple records through APIs

I’m trying to connect coinciding public holidays to an employees holiday record. In other words, if an employee makes a holiday request I want to connect all of the bank holidays that coincide with that holiday to the holiday record.

I’ve tried numerous things. Creating a string that separates the Public Holiday’s ID’s by a comma, the same with the date field, I’ve tried updating the raw version of the holiday record etc. This is my latest iteration using an array which doesn’t work. Does anyone know how to do this? Thanks!

//ADD PUBLIC HOLIDAYS TO HOLIDAY RECORD
    var publicHolidayArray =  new Array();
    // go through coinciding public holidays and add them to an array
    for (let i = 0; i < coincidingPublicHolidays.length; i++) {
      publicHolidayArray.push({
        id: coincidingPublicHolidays[i].publicHolidayID
      });
    }
    $.ajax({
            url: String("https://api.knack.com/v1/objects/object_29/records/" + userHolidayRecords[x].holidayID),
            async: false,
            type: "PUT",
            headers: {"X-Knack-Application-Id": "", "X-Knack-REST-API-KEY" : "f", "Content-Type" : "application/json"},
            data: JSON.stringify({
                 "field_374_raw": publicHolidayArray //connect public holidays to user records
            })  
    })

Hello Harry,

Try below code.

Var data={};
data.field_374=;
// go through coinciding public holidays and add them to an array
for (let i = 0; i < coincidingPublicHolidays.length; i++) {
data.field_374.push(coincidingPublicHolidays[i].publicHolidayID);
}
$.ajax({
url:“https://api.knack.com/v1/objects/object_29/records/” + userHolidayRecords.holidayID,
async: false,
type: “PUT”,
headers: {“X-Knack-Application-Id”: “627ceb9474c5cd001e8c79a0”, “X-Knack-REST-API-KEY” : “aa22e3b7-8a61-4d3a-b023-85878613242f”},
data: data,
success:function(){}
})

Thanks,
Sunny Singla

Hi Sunny,

Thanks for the response. I’ve tried the code and it doesn’t seem to work either.

Thanks,
Harry

Hello Harry,

What was the issue now?

Maybe IDs are not passing correctly or the connection is not many to many.

Thanks,
Sunny Singla