Skip to main content
se añadieron 188 caracteres en el cuerpo
Origen Enlace
Miguel
  • 1.5k
  • 1
  • 21
  • 53
$key = "miapikey";
        $headers = [
           'content-type' => 'application/json',
           'Api-Token' => $key,
           "Cache-Control" => "no-cache",
         ];

        $client = new Client();

        $body = [
            'contact' => [
                "email" => $request->input('email'),
                "firstName" => "",
                "phone" => "",
                "tags" => 'api',
            ],
        ];

De este modo creo un contacto, incluso a la vez lo puedo modificar para añadirlo a una lista:


       $response = $client->request('POST', 'https://url.api-us1.com/api/3/contacts', [
                'headers' => $headers, 
                'json' => $body,
            ]);

Arriba creo el contacto, incluso a la vez lo puedo modificar para añadirlo a una lista:

          if($response->getStatusCode() == "200" || $response->getStatusCode() == "201"){
            $arrResponse = json_decode($response->getBody(),true);
            foreach($arrResponse as $arr){
                    //Log::debug($arr['id']);
                     $body = [
                         'contactList' => [
                             "contact" => $arr['id'],
                             "list" => 3,
                             "status" => 1
                         ]
                     ];
         
               $response = $client->request('POST', 'https://url.api-us1.com/api/3/contactLists', [
                'headers' => $headers, 
                'json' => $body,
             ]);
            }
           }
$key = "miapikey";
        $headers = [
           'content-type' => 'application/json',
           'Api-Token' => $key,
           "Cache-Control" => "no-cache",
         ];

        $client = new Client();

        $body = [
            'contact' => [
                "email" => $request->input('email'),
                "firstName" => "",
                "phone" => "",
                "tags" => 'api',
            ],
        ];

De este modo creo un contacto, incluso a la vez lo puedo modificar para añadirlo a una lista:

$response = $client->request('POST', 'https://url.api-us1.com/api/3/contacts', [
                'headers' => $headers, 
                'json' => $body,
            ]);

            foreach($arrResponse as $arr){
                    //Log::debug($arr['id']);
                     $body = [
                         'contactList' => [
                             "contact" => $arr['id'],
                             "list" => 3,
                             "status" => 1
                         ]
                     ];
         
               $response = $client->request('POST', 'https://url.api-us1.com/api/3/contactLists', [
                'headers' => $headers, 
                'json' => $body,
             ]);
            }
$key = "miapikey";
        $headers = [
           'content-type' => 'application/json',
           'Api-Token' => $key,
           "Cache-Control" => "no-cache",
         ];

        $client = new Client();

        $body = [
            'contact' => [
                "email" => $request->input('email'),
                "firstName" => "",
                "phone" => "",
                "tags" => 'api',
            ],
        ];

       $response = $client->request('POST', 'https://url.api-us1.com/api/3/contacts', [
                'headers' => $headers, 
                'json' => $body,
            ]);

Arriba creo el contacto, incluso a la vez lo puedo modificar para añadirlo a una lista:

          if($response->getStatusCode() == "200" || $response->getStatusCode() == "201"){
            $arrResponse = json_decode($response->getBody(),true);
            foreach($arrResponse as $arr){
                    //Log::debug($arr['id']);
                     $body = [
                         'contactList' => [
                             "contact" => $arr['id'],
                             "list" => 3,
                             "status" => 1
                         ]
                     ];
         
               $response = $client->request('POST', 'https://url.api-us1.com/api/3/contactLists', [
                'headers' => $headers, 
                'json' => $body,
             ]);
            }
           }
se eliminaron 10 caracteres en el cuerpo
Origen Enlace
Miguel
  • 1.5k
  • 1
  • 21
  • 53
$response = $client->request('POST', 'https://medapolourl.api-us1.com/api/3/contacts', [
                'headers' => $headers, 
                'json' => $body,
            ]);

            foreach($arrResponse as $arr){
                    //Log::debug($arr['id']);
                     $body = [
                         'contactList' => [
                             "contact" => $arr['id'],
                             "list" => 3,
                             "status" => 1
                         ]
                     ];
         
               $response = $client->request('POST', 'https://medapolourl.api-us1.com/api/3/contactLists', [
                'headers' => $headers, 
                'json' => $body,
             ]);
            }
$response = $client->request('POST', 'https://medapolo.api-us1.com/api/3/contacts', [
                'headers' => $headers, 
                'json' => $body,
            ]);

            foreach($arrResponse as $arr){
                    //Log::debug($arr['id']);
                     $body = [
                         'contactList' => [
                             "contact" => $arr['id'],
                             "list" => 3,
                             "status" => 1
                         ]
                     ];
         
               $response = $client->request('POST', 'https://medapolo.api-us1.com/api/3/contactLists', [
                'headers' => $headers, 
                'json' => $body,
             ]);
            }
$response = $client->request('POST', 'https://url.api-us1.com/api/3/contacts', [
                'headers' => $headers, 
                'json' => $body,
            ]);

            foreach($arrResponse as $arr){
                    //Log::debug($arr['id']);
                     $body = [
                         'contactList' => [
                             "contact" => $arr['id'],
                             "list" => 3,
                             "status" => 1
                         ]
                     ];
         
               $response = $client->request('POST', 'https://url.api-us1.com/api/3/contactLists', [
                'headers' => $headers, 
                'json' => $body,
             ]);
            }
Origen Enlace
Miguel
  • 1.5k
  • 1
  • 21
  • 53

Comprobar si un contacto existe para modificarlo - ActiveCampaign

Buenas estoy trabajando con una api llamada ActiveCampaign, de la cual los contactos que me entran a través de un formulario, los envio por una api ActiveCampaign, pero no consigo encontrar como comprobar si el contacto existe ya en ActiveCampaign y si es así actualizarlo, en el caso que no exista lo creo nuevo.

Estoy trabajando en una aplicación con Laravel 5.8 y Guzzle 7.4.

Este es mi código.

$key = "miapikey";
        $headers = [
           'content-type' => 'application/json',
           'Api-Token' => $key,
           "Cache-Control" => "no-cache",
         ];

        $client = new Client();

        $body = [
            'contact' => [
                "email" => $request->input('email'),
                "firstName" => "",
                "phone" => "",
                "tags" => 'api',
            ],
        ];

De este modo creo un contacto, incluso a la vez lo puedo modificar para añadirlo a una lista:

$response = $client->request('POST', 'https://medapolo.api-us1.com/api/3/contacts', [
                'headers' => $headers, 
                'json' => $body,
            ]);

            foreach($arrResponse as $arr){
                    //Log::debug($arr['id']);
                     $body = [
                         'contactList' => [
                             "contact" => $arr['id'],
                             "list" => 3,
                             "status" => 1
                         ]
                     ];
         
               $response = $client->request('POST', 'https://medapolo.api-us1.com/api/3/contactLists', [
                'headers' => $headers, 
                'json' => $body,
             ]);
            }

La documentación de la API esta aquí