Can't add Invoice to sales order

Can't add Invoice to sales order

I'm writing an api script in php that creates a sales order and invoice when a customer submits an order on our website. The script has no problem making both the invoice and the sales order.  But when I goto the sales order's invoice tab, it hasn't added the invoice that I created to the sales order, even though the invoice is listed in the invoices section of Zoho inventory. Does anyone have any idea how to add the invoice to the sales order?

  1.  
  2. $params ='{
  3. "customer_id": '.$contactsDecode->contacts[0]->contact_id.',
  4. "salesorder_number": '.$lastOrder['Order Number'].',
  5. "date": '.$combinedTime.',
  6. "reference_number": '.$newInvoiceNum.',
  7. "invoices": [
  8.         {
  9.             "invoice_id": '.$newInvoiceNum.',
  10.             "invoice_number":  '.$newInvoiceNum.',
  11. "status": "fulfilled",
  12. "total": 350,
  13.             "balance": 0
  14.         }
  15.     ],
  16. "line_items": [
  17. '.$item .'
  18. ],
  19. "is_emailed": "true",
  20. "delivery_method": "USPS",
  21. "salesorder_id" : '.$lastOrder['Order Number'].',
  22. "customer_name" : "'.$lastOrder['Customer Name'].'"
  23. }';
  24. $invoiceParams ='{
  25. "customer_id": '.$contactsDecode->contacts[0]->contact_id.',
  26. "invoice_number":  '.$newInvoiceNum.',
  27. "status": "paid",
  28. "date": '.$combinedTime.',
  29. "reference_number": '.$lastOrder['orderID'].',
  30.     "discount": 0,
  31. "line_items": [
  32. '.$item .'
  33. ],
  34.     "is_discount_before_tax": true,
  35.     "discount_type": "item_level",
  36.     "is_inclusive_tax": false,
  37.     "exchange_rate": 1
  38. }';
  39. $connectionStatus .= $zohoClient->createSalesOrder($params, true);
  40. $connectionStatus .= $zohoClient->createInvoice($invoiceParams, true);