Foreach returns no value

0

I have a API that returns me some results, but with your help I managed to make the code work but after a few days the code stopped.

I have this code:

<?php
    $email = $_GET['email'];
    $nome  = $_GET['nome'];

    //Não mexer//
    require_once "vendor/autoload.php"; 
        use Intercom\IntercomClient;
            $client = new IntercomClient('App_ID', 'App_Key');
    //Não mexer//
$client->leads->create(["email" => $email]);
    sleep(40);

    //Pega dados Lead//
        $leads = $client->leads->getLeads(['email' => $email]); 

        foreach($leads->contacts as $contact){
            echo "type: " . $contact->type ."<br>";
            echo "id: " . $contact->id ."<br>";
            echo "user_id: " . $contact->user_id ."<br>";
            echo "email: " . $contact->email ."<br>";
            echo "name: " . $contact->name ."<br>";
            $id = $contact->id;
        }
    //Termina de Pegar//

    //Cria a Tag//
    $client->tags->tag([
      "name" => "beneficio-em-dobro",
      "users" => [
        ["id" => $id]
      ]
    ]);
    //end//

As you can see, I have to give a "pause" of 40 seconds, otherwise the code does not work. I did not understand why, if it was working normally.

Git Hub SDK & Docs

    
asked by anonymous 23.08.2016 / 14:40

1 answer

0

Attempts to declare the variables as null before the foreach. Enable the error return on the PHP variables tb, can help in the solution.

    
23.08.2016 / 15:14