Insightly PHP API

346 views Asked by At

I'm using https://github.com/Insightly/insightly-php and having a problem passing a simple variable to a method in it:

require("insightly.php");
$i = new Insightly('my-base64-encoded-api-key');

Do you know why getContacts() doesn't seem to see the variable $lastname here?

Example:

$lastname = $_GET["lastname"];
$contacts = $i->getContacts(array("filters" => array('LAST_NAME=\'$lastname\'')));

If I hard code a name in the array for example:

$contacts = $i-getContacts(array("filters" => array('LAST_NAME=\'Smith\'')));

it accepts it and returns results,

but with the variable $lastname it returns nothing - and there is no error so it must not see it. - It's probably a syntax error on my part but I would appreciate anyone pointing me in the right direction :)

1

There are 1 answers

1
bnahin On

Because you used apostrophes when setting the array, PHP will interpret it as literal text.
Because of this, the array would read:

Array ( [filters] => Array ( [0] => LAST_NAME='$lastname' ) )

$contacts should be defined like this:

$contacts = $i->getContacts(array("filters" => array("LAST_NAME=$lastname")));

See this S.O. thread for more information.