'xxx', 'clientSecret' => 'xxx', 'redirectUri' => 'http://lf7.listflex.com/api/wrappers/infusionsoft.php?action=auth', )); if($action == 'auth'){ if(isset($_GET['code'])){ $infusionsoft->requestAccessToken($_GET['code']); ?>

Your Access Token:


Use the above token to post contacts into your infusionsoft account getAuthorizationUrl() . '">Click here to authorize'; } }elseif($action == 'add'){ $token = $_REQUEST['token']; //this will be base 64 encoded serialized token info $email = $_REQUEST['email']; $phone = $_REQUEST['phone']; $fname = $_REQUEST['fname']; $lname = $_REQUEST['lname']; if($token == ''){ die("error: token is required"); } $token = base64_decode($token); $infusionsoft->setToken(unserialize($token)); $contact_info = array('email'=>$email, 'phone'=>$phone, 'fname'=>$fname, 'lname'=>$lname); try{ try{ $cid = $infusionsoft->contacts()->where('email', $email)->first(); }catch (\Infusionsoft\InfusionsoftException $e) { $cid = addContact($infusionsoft, $contact_info); } }catch(\Infusionsoft\TokenExpiredException $e) { // If the request fails due to an expired access token, we can refresh // the token and then do the request again. $infusionsoft->refreshAccessToken(); $cid = addContact($infusionsoft, $contact_info); } $email_service = new Infusionsoft\Api\APIEmailService($infusionsoft); $email_service->optIn($email, 'Email Marketing'); $contact = $infusionsoft->contacts()->with('custom_fields')->find($cid->id); print_r($contact); if($contact){ die("success: contact added."); }else{ die("error: failed to add contact."); } } function addContact($infusionsoft, $contact_info){ $email1 = new \stdClass; $email1->field = 'EMAIL1'; $email1->email = $contact_info['email']; $phone1 = new \stdClass; $phone1->field = 'PHONE1'; $phone1->number = $contact_info['phone']; //$phone1->type = 'mobile'; $contact = [ 'given_name' => $contact_info['fname'], 'family_name' => $contact_info['lname'], 'email_addresses' => [$email1], 'phone_numbers' => [$phone1] //"opt_in_reason" => 'Email Marketing', //'email_opted_in' => true ]; return $infusionsoft->contacts()->create($contact); }