0

I am trying to connect to my Insightly account via API given on this link: https://github.com/Insightly/insightly-php

When I test the given code:

<?php
    require('insightly.php');
    function run_tests($apikey){
      $insightly = new Insightly($apikey);
      $insightly->test();
    }
    run_tests($argv[1]);
?>

Nothing actually happens, meaning it gives out a blank page. Of course I have changed the variable $apikey with the key given. I have tried with base64 encoding, single quotes, double quotes, but nothing really works. I have also tried on localhost as well as on my server.

Then I tried the code given on Github:

require("insightly.php");

$i = new Insightly('your-api-key');

$contacts = $i->getContacts();

Again, changing the api key with the one given, once normal and once in base64 encoding. This just gives me a 500 error.

Does anybody have any idea how to even connect to Insightly via API in PHP?

Grokify
  • 15,092
  • 6
  • 60
  • 81
Tadej Bogataj
  • 399
  • 1
  • 4
  • 13
  • The code that you are trying to run, it's supposed to run from the `php-cli`. Open a terminal and go to your php folder, then run the following command `php -f yourphpfile.php yourapikey`....f.i: `php -f thefile.php 124235656`....now if you want to run it from your browser, just refactor the code, and this line `run_tests($argv[1]);`, should be `run_tests("yourapikey");`, like `run_tests("235234564");`. – Hackerman Jan 03 '17 at 13:14
  • Unfortunately nothing changes... The only output it gives me is: "Test API ..... Testing authentication". And nothing more. When i check the source code i see that that means that there has been an arreor and the code stops at this point. – Tadej Bogataj Jan 03 '17 at 13:23

1 Answers1

0

This code is made for executing in cli. If you use it like this is will run in a browser or anything else for that matter.

<?php
require('insightly.php');

function run_tests($apikey){
  $insightly = new Insightly($apikey);
  $insightly->test();
}

$apikey = "[PLACE API KEY HERE]";
run_tests($apikey);

otherwise try the following:

require("insightly.php");

$i = new Insightly('your-api-key');
$contacts = $i->getContacts();
var_dump($contacts);
Juun
  • 26
  • 4
  • I have tried your code, but it outputs the exact same thing as before: "Test API ..... Testing authentication". I have tried to get all the contacts as well, thinking that that is all that it would output with this peace of code: $contacts = $i->getContacts(); but the array is completely empty and if i try to echo anything after it nothing shows up. – Tadej Bogataj Jan 03 '17 at 13:26
  • I don'y have a working account so i can not test it. What output are you expecting when executing `test()` function? – Juun Jan 03 '17 at 13:29
  • If i run the code localhost it ouputs this error: Fatal error: Uncaught Exception: HTTP Error (60): SSL certificate problem: self signed certificate in certificate chain in D:\Programi\Xampp\htdocs\test\insightly.php:1524 Stack trace: #0 D:\Programi\Xampp\htdocs\test\insightly.php(1542): InsightlyRequest->asString() #1 D:\Programi\Xampp\htdocs\test\insightly.php(264): InsightlyRequest->asJSON() #2... – Tadej Bogataj Jan 03 '17 at 13:30
  • Then you should look in to that problem. The code is not the problem as this should work fine! Please debug problem further with error reporting on in PHP. – Juun Jan 03 '17 at 13:32
  • It should output: "Authentication passed..." – Tadej Bogataj Jan 03 '17 at 13:32