Foreach returns no value

Asked

Viewed 77 times

0

I have a API that returns 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 take a 40-second "break" if the code doesn’t work. I didn’t understand why, if it was working normally.

Git Hub SDK & Docs

  • Response is taking its time, that?

  • Yeah, at least if I don’t put the 40s it returns a huge error of not Fund etc..

1 answer

0

Try declaring variables to be null before foreach. Enable error return on PHP tb variables, it may help in the solution.

  • .... .... ... $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; }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.