如何使用API和PHP删除单个营销活动收件人

如何使用API和PHP删除单个营销活动收件人,php,curl,sendgrid,sendgrid-api-v3,Php,Curl,Sendgrid,Sendgrid Api V3,试图实现DELETE{list_id}/recipients/{recipient_id}HTTP/1.1,以便从列表中删除单个电子邮件收件人,但我收到此错误消息,结果是:{“errors”:[{“message”:“未提供有效收件人”}]} 下面是我修改的代码: 刷新页面,看看是否有改进……否则,请转到此处:可能重复 <?php $list = "971292"; $recipient = "joe@joeblowxyz.com"; $url = 'https:

试图实现DELETE{list_id}/recipients/{recipient_id}HTTP/1.1,以便从列表中删除单个电子邮件收件人,但我收到此错误消息,结果是:{“errors”:[{“message”:“未提供有效收件人”}]}

下面是我修改的代码:


刷新页面,看看是否有改进……否则,请转到此处:可能重复
<?php

    $list = "971292";
    $recipient = "joe@joeblowxyz.com";
    $url = 'https://api.sendgrid.com/v3/contactdb/lists/' . $list . '/recipients/' . $recipient;

    //this is the data you will send with the DELETE
    **# DO I NEED THIS?**
    $fields = array(
        'field1' => 'field1',
        'field2' => 'field2',
        'field3' => 'field3'
    );

    /*ready the data in HTTP request format
    *(like the querystring in an HTTP GET, after the '?') */
    $fields_string = http_build_query($fields);

    //open connection
    $ch = curl_init();

    /*if you need to do basic authentication use these lines,
    *otherwise comment them out (like, if your authenticate to your API
    *by sending information in the $fields, above. */
    $username = 'myusername';
    $password = 'mypassword';

    curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
    /*end authentication*/

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);

    /*unless you have installed root CAs you can't verify the remote server's
    *certificate. Disable checking if this is suitable for your application*/
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    //perform the HTTP DELETE
    $result = curl_exec($ch);

    //close connection
    curl_close($ch);
?>