EspoCRM PHP API Client - add contacty to target list after contact is created.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JacquesG
    Junior Member
    • May 2025
    • 1

    #1

    EspoCRM PHP API Client - add contacty to target list after contact is created.

    Hi there

    I am successfully creating a contact via an API call. I now want to add that created contact to a existing target list. Here is what I have so far:



    public function subscribe(Request$request)

    {


    try {

    $client = newClient('https://mywebsite.com');


    $client->setApiKey('xxxx);



    // Validate input


    $request->validate([


    'name' => 'required|string|max:255',


    'email' => 'required|email|max:255',


    ]);



    // Split full name into first and last name

    $fullName = trim($request->name);

    $parts = explode(' ', $fullName, 2);

    $firstName = $parts[0];

    $lastName = $parts[1] ?? '?';


    // 1. Create the contact

    $contactResponse = $client->request(Client::METHOD_POST, 'Contact', [

    'firstName' => $firstName,

    'lastName' => $lastName,

    'emailAddress' => $request->email,


    'cType' => 'Guest',


    ]);

    // 2 Here I want to add the created contact to a target list but I cannot find documentation for it. Please help.



    } catch (\Throwable$e) {


    $message = $e->getMessage();





    returnresponse()->json([


    'error' => 'Subscription failed.',


    'message' => $message,


    ], 500);


    }


    }


    Thanks

    Jacques zz0.x0pm5t1iy6zz
    Last edited by JacquesG; Today, 08:33 AM.
  • rabii
    Active Community Member
    • Jun 2016
    • 1293

    #2
    check this out simple just use the api link

    Rabii
    Here to help :)

    Comment

    Working...