Home Forums Newsletter Plugin Support A way to send an email or file to the account and automatically add subscribers?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #100635
    James LeDoux
    Participant

    Is there any way to send an email or upload a file to the WordPress account, and have Newsletter Plugin automatically add the emails & names listed to the newsletter subscriber list? Or some way of communicating from outside, by uploading a file to a certain location or something?

    It would be very helpful, as that way, somebody who signs up for something else on another site, for example, outside of the website, could have the choice of signing up for the newsletter, and said site could send the email.

    Thank you for any help or suggestions.

    #100711
    Stefano
    Keymaster

    Maybe the rest api can be useful, it depends on your specific needs.

    https://www.thenewsletterplugin.com/developers/dev-newsletter-api

    Stefano.

    #100715
    James LeDoux
    Participant

    Great, that looks like it should work, but could you help me understand how to use it exactly? What we have is another subscription program for our hard-copy magazine on a subdomain of the same website that this plugin is on. We want to give magazine subscribers the option of subscribing to the newsletter. So, if they opt in, how do we send the api call exactly?

    In the php, would we simply put this line in the code for an opted-in person, in an IF statement, for example?
    curl -X POST http://<your-site>/wp-json/newsletter/v1/subscribe -d ‘{“email”:”test@example.com”, “name”:”My name”, “gender”:”f”}’

    Also, what’s the difference between that and this method?
    curl -X POST -H “Content-Type: application/json” http://<your-site>/wp-json/newsletter/v1/subscribers/add -d ‘{“email”:”test@example.com”, “api_key”:”…”}’

    It says the latter works directly with the database, but wouldn’t they both add a subscriber to the db? and could we use the api key with the first one too? Is it more secure that way? In the second example, I suppose you could add the name and other info the same way you do in the first, correct?

    Thanks for your help!

    #100754
    James LeDoux
    Participant

    This is SO awesome! Newsletter Plugin, you rock!

    Okay, should’ve just done my homework first before asking those last questions. The examples given in the documentation are command line arguments. I did some research, and for anyone else trying to figure this out, here’s how to make it work in a PHP script. (Variables like $email have to be established first, of course):

        // Data in JSON format
        $data = array("email" => $email, "api_key" => "your_key", "name" => $name, "status" => "C");
        $data_string = json_encode($data);
        
        // Prepare new cURL resource
        $ch = curl_init('https://www.your_website.com/wp-json/newsletter/v1/subscribers/add');
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        
        // Set HTTP Header for POST request
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($data_string))
            );
        
        $result = curl_exec($ch);
        
        // Close cURL session handle
        curl_close($ch);
        
        # Print response to check success.
        echo "<pre>" . $result. "</pre>";
    #146615

    how yo add subscriber to a specific list with this script?

    #146643
    James LeDoux
    Participant

    As shown in their documentation on the Newsletter REST API, user lists are designated with “lists”, so, you’d add that to the array, like:

    
    $data = array("email" => $email, "api_key" => "your_key", "name" => $name, "lists" => $lists, "status" => "C");
        $data_string = json_encode($data);

    Again, you’d have to establish what your own variable names refer to, in this case, $name, $lists, etc. So, in your script, you’d have to tie $name to the person’s name you’re dealing with at the time, $lists to the lists they belong to, etc.

    At least, I believe this should work, I haven’t tried it with lists.

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