Invoices API Creating Line Items

I am playing around with the invoices API explorer.
I am attempting to create an invoice for myself just so that I can get it figured out how it works and then attempt to implement it on our website.
First of all, the documentation is severely lacking in understandability and you have so much deprecated stuff on there that you have to wade through it to get to the actual items.
I tried to create an invoice by just filling in the explorer info that it said was needed. I got errors. After searching for a good 5-10 minutes, I figured out that you have to Create an Order that is left open, so that you have the order id, then you use that order id for creating the invoice. Documentation stating that, even in the explorer would have been helpful.
So, order created, copied that order id over to the create invoice explorer. Fill in the appropriate information, that I know of.
I am getting this error

"errors": [
      "code": "BAD_REQUEST",
      "detail": "fixed_amount_requested_money cannot be set on BALANCE payment requests",
      "field": "invoice.payment_requests",
      "category": "INVALID_REQUEST_ERROR"

So I change the payment_requests to deposit and then it tells me that I cannot have just 1 payment request for a deposit, which makes sense.
I just want to create a simple invoice with 1 or more line items that have an amount, I don’t need anything special or anything extra. I want something similar to the invoice line items that I am currently using to bill our customers twice a month when I enter them manually on the PC every 2 weeks.
Is this even something possible with the Invoices API?
Anything would be helpful at this point.

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Create and Publish Invoices
Make your First API Call
Pay or Refund Invoices

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

Yes, it is possible to create a simple invoice with one or more line items using the Invoices API. However, you need to follow a specific process:

  1. Create an Order: As you’ve already figured out, you need to create an order first using the Orders API. This order should include all the line items that you want to include in your invoice.

  2. Create an Invoice: Once you have the order ID, you can create an invoice using the Invoices API. In the payment_requests field, you should specify a BALANCE request type, which indicates that the payment request is for the total balance of the invoice. You don’t need to specify the fixed_amount_requested_money field for BALANCE payment requests, as the total balance is automatically calculated based on the associated order.

Here’s an example of how you might structure your payment_requests field:

"payment_requests": [
      "request_type": "BALANCE",
      "due_date": "2022-12-30",
      "reminder_date": "2022-12-28"

In this example, the due_date is the date the payment is due, and the reminder_date is the date a reminder for the payment is sent. Adjust these dates as needed for your invoice.

Remember, the total balance of the invoice is automatically calculated based on the associated order, so you don’t need to specify an amount for BALANCE payment requests.

This answer was reviewed by @Bryan-Square.

I have it so that I am creating the invoice from the Create Orders but now I need to pass the OrderID over to the Create Invoices API, these are private values. Any quick and easy suggestions?

I’m not sure I fully understand the question. Once you’ve created the order you’ll call CreateInvoice with the order_id. Once you’ve created the invoice you’ll then call PublishInvoice to send it to the customer. :slightly_smiling_face:

Yes, but you have to access the OrderID that is given from the Create Order in order to publish the invoice. I am trying to find an easy way to pass that Private variable from the CreateInvoice call to the PublishInvoice call. Since it is a private string, you cannot just assign it to a random variable and call it, you get this error,

Uncaught Error: Cannot access private property

The property needs to be public so that it can be assigned to a variable and then passed to the PublishInvoice code.
This is the problem that I am now trying to solve, accessing private properties so that I can pass them along to the next part of code.

It’s not private. The IDs for the order and the invoices are returned in the API responses. You can take those and pass them to the CreateInvoice and PublishInvoice. What language are you using? :slightly_smiling_face:

Using PHP. I can check it again, but I am pretty sure that it comes back as Cannot access private property when I try to assign it to a variable.

For example here is a sample code that creates an order then an invoice from the order.

require 'vendor/autoload.php';

// Replace these values with your Square application credentials
$accessToken = 'YOUR_ACCESS_TOKEN';
$locationId = 'YOUR_LOCATION_ID';

// Create and configure a new API client object
$client = new Square\SquareClient([
    'accessToken' => $accessToken,
    'environment' => Square\Environment::SANDBOX,

// Create an order with one line item
$orderApi = $client->getOrdersApi();
$lineItem = new Square\Models\OrderLineItem('1');
$lineItem->setBasePriceMoney(new Square\Models\Money(300, 'USD'));
$order = new Square\Models\CreateOrderRequest();
$createOrderResponse = $orderApi->createOrder($order);
$createdOrder = $createOrderResponse->getResult()->getOrder();

// Create an invoice for the order
$invoiceApi = $client->getInvoicesApi();
$invoice = new Square\Models\Invoice();
$invoice->setPrimaryRecipient(new Square\Models\InvoiceRecipient([
    'customer_id' => 'CUSTOMER_ID', // Replace with a valid customer ID
    new Square\Models\InvoicePaymentRequest([
        'requestType' => 'BALANCE',
        'dueDate' => date('Y-m-d', strtotime('+7 days')), // Set due date to 7 days from now
        'tippingEnabled' => false,