[SOLVED] Failed to invoke method addOrderItem in class com.infusionsoft.api.xmlrpc.XmlRpcInvoiceService: id must be valid

I was testing some code while trying to add an order item to an invoice and I’m getting this error:

Failed to invoke method addOrderItem in class com.infusionsoft.api.xmlrpc.XmlRpcInvoiceService: id must be valid

My PHP Code
// Create Order Item
$productId = 95;
$type = 4;
$price = (float)1500.00;
$qty = 1;
$item = $iSDK->addOrderItem($invoice_id, $productId, $type, $price, $qty, ‘Product Name’, ‘Added by API’);

… I’ve used this before w/o issue… is this a new bug, or have I truly done something wrong in my code?

I’ve seen some previous posts from 2017 where this similar issue was encountered, but I’ve used this as of the 15th of last month and it worked…

I don’t think you need to typecast the price but I guess it doesn’t hurt (technically a double on the server side). Otherwise it looks fine. So a couple of un-revealed questions. I’m assuming you’re using the api key method for auth? Unlike OAuth where you can login to your Mashery account and look at the log data, you’d have to ask support to check the server logs to run that down with the api key method. Do you keep a transaction log? If not I’d recommend doing that (for cases like this). If you know what the return message is then maybe share that?

Hi Marion, it may be the simple case that the Invoice was not found.

I am guessing that the “$invoice_id” variable has been set, as no example was provided.

Is the Invoice Id valid?

Yes, this is using the older iSDK. The server I’m working with won’t let me run composer, so using the new PHP code isn’t an option w/o a lot of hassle, but correct me if I’m wrong.

Type casting was the last ditch effort to try and get a different result.

Regarding the Invoice Id, I pulled the Job ID from the UI, and it’s the same as the Invoice Id, reported by the API as well.

$orderId = 4178;
$invoice_id = $iSDK->getInvoiceId($orderId);
echo ‘

’ .print_r($invoice_id, 1) . ‘
’;

… so if the Invoice ID is wrong, then I would assume the issue would be something else in the API reporting an invalid ID.

After some more testing I found that the files on my server were corrupted somehow.

I tried a different implementation on a different server w/ the same code base and the requests worked fine.

I copied the iSDK files from that server to my server, and my code worked fine.

Thanks for the comments trying to help resolve this issue.