Home Forums Newsletter Plugin Support REST API Problem

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #304192
    promotika
    Participant

    Hi, I’m trying to delete a subscriber, using an API call to the ENDPOINT, using PHP. Here is my code:

    <?php
    $email = “john@email.com”;
    $url = “websiteurl/newsletter/wp-json/newsletter/v2/subscribers/” . $email;

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “DELETE”);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $headers = [
    ‘X-TNP-KEY: admin:123456’,
    ‘X-TNP-SECRET-KEY: 654321’
    ];

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $response = curl_exec($ch);

    if(curl_errno($ch)){
    echo ‘Request Error:’ . curl_error($ch);
    } else {
    echo $response;
    }

    curl_close($ch);
    ?>

    ______________________________________

    All I get is this error:

    {“code”: “rest_forbidden”, “message”: “You do not have permission to do so.”, “data”:{“status”:401}}

    Why ?

    Thank you!
    Alex

    #304262
    Stefano
    Keymaster

    Hi, those headers are not valid for authentication. You should use a basic auth header (https://en.wikipedia.org/wiki/Basic_access_authentication) or just use the client and secret as query string parameters (easy way).

    The API key should’ve generated from the API addon admin panel.

    https://www.thenewsletterplugin.com/documentation/developers/newsletter-api-2-authentication/

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