Error while displaying Json in PHP

Asked

Viewed 46 times

1

I have the following code.

<?php

$email = $_POST['email'];
$nome  = $_POST['nome'];

//Não mexer//
require_once "vendor/autoload.php"; 
    use Intercom\IntercomClient;
        $client = new IntercomClient('App_ID', 'App_Key');
//Não mexer//

//Cria o Lead//
    $client->leads->create([
            "name"  => "$nome",
            "email" => "$email"
    ]);
//Termina de Criar//

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

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

//Adiciona a Tag//
    $client->tags->tag([ 
    "name" => "Beneficio-em-Dobro", 
    "leads" => [ 
            ["id" => "$id"] 
        ] 
    ]);
//Termina de Adicionar//    ?>

But when executing this code, it creates the bad 'Lead' does not create the TAG. and does not show me his data. I have tried to pass inside "" bad will not.

  • 1

    Lucas, it’s not clear to me what you’re trying to do. If tags is an array, to add an element you need to do something like $client->tags[] = new Tag();, but it seems more that this is a kind of DSL. Does the API not have a function tags->create of life? We need to understand more about this API that you are using, by chance it would be this one? Post more information.

  • @Anthonyaccioly the API you quoted is the one you use!

  • @Anthonyaccioly when I pass the code so: $leads = $client->leads->getLeads(["email" => "$email"]); it won’t, but if I pass like this: $leads = $client->leads->getLeads(["email" => "[email protected]"]); It’s normal. .

  • Ok, you’re probably hurting some API contract at the time of creating this tag. Take a look in the description of the REST service, $id is pointing to a valid system id? See that in the REST API it is also possible to taggear users by user_id or email, as I don’t know the API I have no idea what the difference is between id and user_id.

  • Lucas, you must not pass a string, you must pass the variable (in your case $email (that comes from the request post). Most likely the same thing is happening to this $id (you have to pass a real id coming from somewhere, or an email according to the API).

  • $leads = $client->leads->getLeads(["email" => $email]); if I pass like this also returns me error, I will give a read more I’ve read everything :/

  • Can print the value of $email? Sometimes your request is not coming right (this is, $email is not a valid email). Also check in the description of the PHP API if it is possible to make this query by filtering by email.

  • @Anthonyaccioly , here I managed to do it , with the right user but not with Lead. [http://answall.com/questions/147528/como-exibir-json-em-php?rq=1]

Show 3 more comments
No answers

Browser other questions tagged

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