Support » Plugin: Newsletter » The code to call API handle subscription

  • Resolved Jing

    (@gujingc)


    Following our previous thread, we would like to add people to different lists based on the user type they select.

    This is the code we used:

    $array = array(1,2,13);
    $curl = curl_init();
    curl_setopt_array($curl, array(
    CURLOPT_URL => site_url()."/wp-json/newsletter/v1/subscribe",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => "email=".$_POST['tiny_email']."&name=".$_POST['tiny_dispaly_name']."&lists=".$array."",
    CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: application/x-www-form-urlencoded"
    ),
    ));
    $response = curl_exec($curl);
    $err = curl_error($curl);
    curl_close($curl);

    With this code, users are added as a wordpress subscriber but not added to a target list.

    We want to also add the user to respective lists.

    Please advise. Thanks a lot.

    Jing

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Stefano Lissa

    (@satollo)

    Probably the lists are not marked as “public”?
    If you’re controlling all that from the backend you should use the class TNP:: methods to manage subscription and you can use “add” instead of “subscribe” to just manipulate the database.

    Stefano.

    Jing

    (@gujingc)

    Thank you!

    It works.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.