Api in Web Pages

Hello Team!!
I created a web page.
I wrote an API to get the data entered in that web page and i trying to save the data in doctype.

In the doctype, there is a child table. All fields of that doctype are saved but the fields in child table are not saved.

Can anyone pls help me.

This is my function in js.

function saveForm() {
    // Extract form data
    var series = document.getElementById("series").value;
    var date = document.getElementById("date").value;
    var postingDate = document.getElementById("posting_date").value;
    var deliveryDate = document.getElementById("delivery_date").value;
    var shippingAddress = document.getElementById("shipping_address").value;
    var billingAddress = document.getElementById("billing_address").value;
    var customer = document.getElementById("customer").value;
    var totalQty = document.getElementById("total_qty").value;
    var totalAmount = document.getElementById("total_amount").value;

    // Extract product details
    var items = [];
    var table = document.getElementById("product_table");
    for (var i = 1; i < table.rows.length; i++) {
        var productName = table.rows[i].cells[0].querySelector("select").value;
        var quantity = table.rows[i].cells[1].querySelector("input").value;
        var rate = table.rows[i].cells[2].querySelector("input").value;
        var amount = table.rows[i].cells[3].querySelector("input").value;
        items.push({ item_code: productName, qty: quantity, rate: rate, amount: amount });

    // Call the API
        method: "hilltop.hilltop.web_template.customer_so.customer_so.save_data",
        args: {
            series: series,
            date: date,
            posting_date: postingDate,
            delivery_date: deliveryDate,
            shipping_address: shippingAddress,
            billing_address: billingAddress,
            customer: customer,
            total_qty: totalQty,
            total_amount: totalAmount,
            items: items
        callback: function(response) {
            // Check the response and display message
            if (response && response.message === "/save_data?status=success") {
                document.getElementById("message").textContent = "Data saved successfully.";
            } else {
                document.getElementById("message").textContent = "Error saving data. Please try again.";

this is api

# Import the frappe module
import frappe

def save_data():
        # Extract form data
        series = frappe.request.form.get("series")
        date = frappe.request.form.get("date")
        posting_date = frappe.request.form.get("posting_date")
        delivery_date = frappe.request.form.get("delivery_date")
        shipping_address = frappe.request.form.get("shipping_address")
        billing_address = frappe.request.form.get("billing_address")
        customer = frappe.request.form.get("customer")
        total_qty = frappe.request.form.get("total_qty")
        total_amount = frappe.request.form.get("total_amount")
        # Extract item table data
       # Extract item table data
        items = []
        for i in range(len(frappe.request.form.getlist("product_name[]"))):
            item_code = frappe.request.form.getlist("product_name[]")[i]
            qty = frappe.request.form.getlist("quantity[]")[i]
            rate = frappe.request.form.getlist("rate[]")[i]
            amount = frappe.request.form.getlist("amount[]")[i]
                "item_code": item_code,
                "qty": qty,
                "rate": rate,
                "amount": amount

        # Print extracted items data
        frappe.msgprint("Extracted Items:")
        for item in items:
            frappe.msgprint(f"Item Code: {item['item_code']}, Quantity: {item['qty']}, Rate: {item['rate']}, Amount: {item['amount']}")

        # Create the Customer Sales Order document
        sales_order = frappe.new_doc("Customer Sales Order")
        sales_order.series = series
        sales_order.date = date
        sales_order.posting_date = posting_date
        sales_order.delivery_date = delivery_date
        sales_order.shipping_address = shipping_address
        sales_order.billing_address = billing_address
        sales_order.customer = customer
        sales_order.total_qty = total_qty
        sales_order.total_amount = total_amount
        # Add items to the Customer Sales Order
        for item_data in items:
            item = sales_order.append("items", {})
            item.item_code = item_data["item_code"]
            item.qty = item_data["qty"]
            item.rate = item_data["rate"]
            item.amount = item_data["amount"]

        # Save the Customer Sales Order document
        return "/save_data?status=success"  # Redirect with success status
    except Exception as e:
        frappe.log_error(frappe.get_traceback(), "Error saving data")  # Log error
        return "/save_data?status=error"  # Redirect with error status

Data is not saved in child table