Subscribers Email Through API

Discussion in 'General discussions' started by developer, Sep 24, 2015.

  1. developer

    developer Member

    Joined:
    Jul 24, 2015
    Messages:
    134
    Likes Received:
    3
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    7
  2. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,446
    Likes Received:
    2,430
    Exactly, you have to also edit the setup.php file to add your API info then when you submit that form, the info will be sent to your mailwizz app.
     
  3. developer

    developer Member

    Joined:
    Jul 24, 2015
    Messages:
    134
    Likes Received:
    3
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    7
    But i want a solution like

    www.example.com/?email=abc@mail.com

    and using the above link my application can subscribe a user. I do not want any forms.

    I want my to transfer email data from my custom application to mailwhizz via API
     
  4. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,446
    Likes Received:
    2,430
    Even simpler:
    PHP:
    // sub.php file
    require_once dirname(__FILE__) . '/setup.php';
    $listUid 'LIST-UNIQUE-ID';// you'll take this from your customers area, in list overview from the address bar.

    $email  = isset($_GET['email']) && filter_var($_GET['email'], FILTER_VALIDATE_EMAIL) ? $_GET['email'] : null;
    if (!
    $email) {
       exit;
    }

    $endpoint = new MailWizzApi_Endpoint_ListSubscribers();
    $response $endpoint->create($listUid, array(
         
    'EMAIL' => $email,
    ));
    Then simply accessing http://www.example.com/sub.php?email=whatever@domain.com will send your subscriber to mailwizz.
    Again, you need some PHP understanding to use the SDK.
     
  5. Simon Brown

    Simon Brown New Member

    Joined:
    Sep 29, 2015
    Messages:
    23
    Likes Received:
    0
    S.E:
    2019-11-29 21:58:10
    L.T:
    Regular
    L.C:
    2
    This doesn't work by the way. I'm trying to debug it at the moment. It looks like it breaks REST.
    MailWizzApi_Endpoint_ListSubscribers->create requires a POST. We're using a GET. Not sure if it's that though. All I know is, there is no new subscriber in mw_list_subscriber.

    I'm using PHPStorm - I can easily step through process - tell me what I should be looking for on access of this URI. Also should the accessor be logged in or better if they're logged out (I'm using xdebug so I'll log out on firefox and run the stepping from there.)
     
  6. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,446
    Likes Received:
    2,430
    @Simon Brown
    As long as you call :
    PHP:
    $endpoint = new MailWizzApi_Endpoint_ListSubscribers();
    $response $endpoint->create($listUid, array(
     
    'EMAIL' => $email,
    ));
    It does not matter that the data comes in your script from GET or from POST, because you take it and while calling the above, mailwizz sdk will do a POST request.

    If the SDK fails to do something, then you should get a proper error message. What is it?
     
  7. Simon Brown

    Simon Brown New Member

    Joined:
    Sep 29, 2015
    Messages:
    23
    Likes Received:
    0
    S.E:
    2019-11-29 21:58:10
    L.T:
    Regular
    L.C:
    2
    The code I'm running is this:

    Code:
    <?php
    // sub.php file
    require_once dirname(__FILE__) . '/setup.php';
    $listUid = 'jz3528x6ez7b1';// you'll take this from your customers area, in list overview from the address bar.
    $email = getCleanParam('email', FILTER_VALIDATE_EMAIL, null);
    if (!$email) {
        exit;
    }
    $fname = getCleanParam('fname');
    $lname = getCleanParam('lname');
    $endpoint = new MailWizzApi_Endpoint_ListSubscribers();
    $response = $endpoint->create($listUid, array(
        'EMAIL' => $email,
        'FNAME' => $fname,
        'LNAME' => $lname,
    ));
    function getCleanParam($param, $filter=FILTER_SANITIZE_STRING, $default="") 
    {
        $out = isset($_GET[$param]) && filter_var($_GET[$param], $filter) ? $_GET[$param] : $default;
        return $out;
    }
    No error message.

    When I visit http://email.artisansend.co.uk/api-access/my_client/lists.php I get:

    Code:
    MailWizzApi_Params Object
    (
    [_data:MailWizzApi_Params:private] => Array
    (
    [status] => error
    [error] => Not Found
    )
    
    [_readOnly:MailWizzApi_Params:private] =>
    )
    
    MailWizzApi_Params Object
    (
    [_data:MailWizzApi_Params:private] => Array
    (
    [status] => error
    [error] => Not Found
    )
    
    [_readOnly:MailWizzApi_Params:private] =>
    )
    
    MailWizzApi_Params Object
    (
    [_data:MailWizzApi_Params:private] => Array
    (
    [status] => error
    [error] => Not Found
    )
    
    [_readOnly:MailWizzApi_Params:private] =>
    )
    
    MailWizzApi_Params Object
    (
    [_data:MailWizzApi_Params:private] => Array
    (
    [status] => error
    [error] => Method Not Allowed
    )
    
    [_readOnly:MailWizzApi_Params:private] =>
    )
    
     
  8. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,446
    Likes Received:
    2,430
  9. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,446
    Likes Received:
    2,430
    P.S:
    Code:
    $fname = getCleanParam('fname');
    $lname = getCleanParam('lname');
    $endpoint = new MailWizzApi_Endpoint_ListSubscribers();
    $response = $endpoint->create($listUid, array(
    'EMAIL' => $email,
    'FNAME' => $fname,
    'LNAME' => $lname,
    ));
    
    You should do a var_dump on $response to see the actual response message.
     
  10. Simon Brown

    Simon Brown New Member

    Joined:
    Sep 29, 2015
    Messages:
    23
    Likes Received:
    0
    S.E:
    2019-11-29 21:58:10
    L.T:
    Regular
    L.C:
    2
    Code:
    $config = new MailWizzApi_Config(array(
    'apiUrl' => 'http://email.artisansend.co.uk/api',
    'publicKey' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
    'privateKey' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
    // components
    'components' => array(
    'cache' => array(
    'class' => 'MailWizzApi_Cache_File',
    'filesPath' => dirname(__FILE__) . '/MailWizzApi/Cache/data/cache', // make sure it is writable by webserver
    )
    ),
    ));
    
    I moved everything up 1 directory from examples and changed $config['filespath'] accordingly.

    Yeah I'll var_dump $response, I appreciate you can't see my PHPStorm debug window ;)
     
  11. Simon Brown

    Simon Brown New Member

    Joined:
    Sep 29, 2015
    Messages:
    23
    Likes Received:
    0
    S.E:
    2019-11-29 21:58:10
    L.T:
    Regular
    L.C:
    2
    got something:

    Your app doesn't use .htaccess and url rewriting does it...

    Because when I have the config like that (see above) var_dump does this:

    Code:
    object(MailWizzApi_Http_Response)[16]
    public 'url' => string 'http://email.artisansend.co.uk/api/lists/jz3528x6ez7b1/subscribers' (length=66)
    public 'headers' => null
    public 'contentType' => string 'text/html; charset=utf-8' (length=24)
    public 'httpMessage' => string 'Not Found' (length=9)
    public 'curlCode' => int 0
    public 'curlMessage' => string '' (length=0)
    public 'storeCurlInfo' => boolean false
    public 'curlInfo' => null
    public 'body' =>
    object(MailWizzApi_Params)[14]
    private '_data' =>
    array (size=2)
    'status' => string 'error' (length=5)
    'error' => string 'Not Found' (length=9)
    private '_readOnly' => boolean false
    public 'request' => null
    private '_httpCode' => int 404
    
    And when I put the name of the index file in there, I get this:
    Code:
    object(MailWizzApi_Http_Response)[16]
    public 'url' => string 'http://email.artisansend.co.uk/api/index.php/lists/jz3528x6ez7b1/subscribers' (length=76)
    public 'headers' => null
    public 'contentType' => string 'application/json; charset=UTF-8' (length=31)
    public 'httpMessage' => string 'Created' (length=7)
    public 'curlCode' => int 0
    public 'curlMessage' => string '' (length=0)
    public 'storeCurlInfo' => boolean false
    public 'curlInfo' => null
    public 'body' =>
    object(MailWizzApi_Params)[14]
    private '_data' =>
    array (size=1)
    'status' => string 'success' (length=7)
    private '_readOnly' => boolean false
    public 'request' => null
    private '_httpCode' => int 201
    
    And the user is in the database :)

    Thank you for your help
     
  12. Simon Brown

    Simon Brown New Member

    Joined:
    Sep 29, 2015
    Messages:
    23
    Likes Received:
    0
    S.E:
    2019-11-29 21:58:10
    L.T:
    Regular
    L.C:
    2
    How do I ensure security - how do I make sure that only the correct person can operate this API? Is there any authentication in place that can do this? We put the public and private keys into setup.php on the server - is that secure? That means anyone with access to the server could potentially run the code and add subscribers. I'm also building an API URI for removing subscribers, that definitely needs authentication. How is this done?
     
  13. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,446
    Likes Received:
    2,430
  14. Martino Hugo

    Martino Hugo Member

    Joined:
    Feb 2, 2016
    Messages:
    38
    Likes Received:
    3
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    Thank @twisted1919

    And i want insert FullName, How to insert filter fullname? Thank you

     
  15. laurentiu

    laurentiu Active Member Staff Member

    Joined:
    Mar 13, 2018
    Messages:
    294
    Likes Received:
    40
    @Martino Hugo - If in your list exist custom tag for full name simply add tag name in your code:
    PHP:
    $response $endpoint->create($listUid, array(
         
    'EMAIL' => $email,
         
    'FULLNAME' => $fullname
    ));
     

Share This Page