There is a default Magento REST API available to create shipment/invoice for the order.
You can use it as follows.
POST to URL
https://vaseemansari.com/rest/V1/order/order_id/invoice
https://vaseemansari.com/rest/V1/order/1199305/invoice
Body
{
"capture": true,
"items": [
{
"extension_attributes": {},
"order_item_id": 2679144, // This is the sales_order_item ID
"qty": 1
}
],
"appendComment": true,
"comment": {
"extension_attributes": {},
"comment": "Order Invoice generated via REST API",
"is_visible_on_front": 0
},
"arguments": {
"extension_attributes": {}
},
"notify": false
}
Or you can try this CURL as well
curl --location --request POST 'https://vaseemansari.com/rest/V1/order/1199305/invoice' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer bobkb32j4uv5ym3px6nfjkg5jzmoy7cc' \
--header 'Cookie: PHPSESSID=kafslfq30gv0gf7uptb92rjmnf; PHPSESSID=kafslfq30gv0gf7uptb92rjmnf; form_key=OOuH11iCJ3nLS7qS; persistent_shopping_cart=OWDN0gl7nnrU8lGZPHG2cFhzd6xS57WIwDY5zvJIwsMkvWeobu; private_content_version=9f66c6ed545f829348df1e1d26bcf368' \
--data-raw '{
"capture": true,
"items": [
{
"extension_attributes": {},
"order_item_id": 2679144,
"qty": 1
}
],
"appendComment": true,
"comment": {
"extension_attributes": {},
"comment": "Order Invoice generated via REST API",
"is_visible_on_front": 0
},
"arguments": {
"extension_attributes": {}
},
"notify": false
}'