Using a View-based POST to make a connected record is NOT connecting

Has anyone had success using a View-based POST? (with ajax is even better) Or is there another way?
I need to enter a new connected record but I am running the api from the child table. (I am basically taking an existing child and splitting it into two records. Each child represents a payment.)

I am successfully posting from the parent instead of the child, but the connection is not being made like the documentation suggests: View-Based POST for Inserting a Connected Record

I constructed the URL properly because it works and does POST a new record. :slight_smile:
https://api.knackhq.com/v1/pages/scene_XX/views/view_RRR/records

However, the connection to the child is still missing.

The instructions say that the connection is made manually by using field_1 but I cannot get that to work.
(cURL)
–data-raw ‘{
“field_1”: “5d65bad5614e4d001047b585”
}’

So I am sending field_1 with my parent id, but it does not enter the connection.
I have also tried field_1_raw and neither works.

                    var ParentURL = "https://api.knackhq.com/v1/pages/scene_xxx/views/view_238/records";   
                    var MyDataObject = {						   
                        //"field_1": MyParentID,                 // does not work
                        "field_1_raw": MyParentID,          // does not work
                        "field_105": SampleVariable,        
                        ...      
                        "field_103": 'Approved'       
                    }; 
                    
                    DoSomeAjax(ParentURL, 'POST', MyDataObject, function(NewPaymentData) {
                        console.log(NewPaymentData);  // dumps new record, looks good but no connection to parent
                        var NewPaymentID = NewPaymentData.id;  
                        console.log("Payment " + NewPaymentID + " created.");  
                    }); 

Hi Robin,

When you want to insert connected records via API then you need to send that connected Key in URL as well.

you can watch that proper URL by inserting that record manually from that page in network tab.

Regards,
sunny Singla

Okay, I have that, but what do I do with it? I assume you mean the end of this url, which is the id of the parent record.
https://myapp.knack.com/myapp#activities-new/activity-payments/623c602239e4c8001fcd250a/

But where do I put that? I tried on the end of my api URL but it did not work, I tried both of these
https://api.knackhq.com/v1/pages/scene_xxx/views/view_238/623c602239e4c8001fcd250a”;
https://api.knackhq.com/v1/pages/scene_xxx/views/view_238/records/623c602239e4c8001fcd250a”;

I must be so close…

Hello Robin,

Try below

var ParentURL = “https://api.knackhq.com/v1/pages/scene_xxx/views/view_238/records”;
var MyDataObject = {
//“field_1”: MyParentID, // does not work
“field_1_raw”: MyParentID, // does not work
“field_105”: SampleVariable,

“field_103”: ‘Approved’
};

MyDataObject.crumbtrail={};
MyDataObject.crumbtrail[“edit-parent_id”]=“623c602239e4c8001fcd250a”;

Then Post

Thanks
Sunny Singla

Hmm, I understand at least what that is trying to do, but it still does not create the connection to the record.
I have tried multiple iterations, with field_1, with field_1_raw, without field_1 at all, with double and single quotes around edit-parent_id
When I type .crumbtrail into my JS code window, it puts … underneath it, does that mean something? It does recognize it as valid for an object because it appears in the data list.
It does add the record, just does not connect it.

                MyActivityID = "623c602239e4c8001fcd250a"
               var ActivityPaymentURL = "https://api.knackhq.com/v1/pages/scene_xxx/views/view_238/records";
                var ActivityPaymentObject = {						   
                    "field_1": MyActivityID,                          // I have tried this
                    //"field_1_raw": MyActivityID,              // and this
                     ... 
                    "field_103": 'Approved'                
                }; 
                ActivityPaymentObject.crumbtrail={};
                ActivityPaymentObject.crumbtrail["edit-parent_id"]=MyActivityID;

Remove
“field_1”: MyActivityID, // I have tried this
//“field_1_raw”: MyActivityID,
if then still not work you can reach out for this on email we can check on your app.

As above code works for me.

Regards,
Sunny Singla

(this conversation has been moved).

Without credentials, I’m not able to test.

for any professional help, you can email me or whatsapp me.

Regards,
Sunny Singla
+919855089359

Apparently I could not make that connection that way BECAUSE I had made my connection from the parent table instead of from the child.

I deleted the connection, reconnected from the child table, redid all my forms and views and functions which used the connection (that was fun) and then just posted to the child object in the first place. Sigh. But it WORKS now.