Skip to content
Advertisement

Quickbooks PHP JSON Array Variable?

I’m trying to use the Quickbooks PHP SDK to submit an API call to create an invoice. I can get the call to work using a hardcoded JSON array, but when I attempt to pass it with a variable, the call fails.

This is the version that works:

JavaScript

When I try to pass a variable (which I need to for a dynamic call), the code fails.

Failed attempt 1 with an imploded array of strings

JavaScript

This is error from attempt #1:

JavaScript

This is failed attempt #2 with an array encoded with json_encode

JavaScript

]);

Here is the error message from the failed attempt #2:

JavaScript

I’m sure this is a simple fix like the removal of quotes or something.

If someone could reply with a working example that allows the dynamic passing of variables for those “Line” values I would greatly appreciate it!

Advertisement

Answer

Seems you need to push $line1 and $line1 to your $lines array and then use it on your $theResourceObj object like below before invoice API call.

Quick Fixes,

  1. Keep in mind $line1 and $line2 should be array, not a string.
  2. No need to encode $lines just send it as it is.

Code:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement