0

尝试实施 DELETE https://api.sendgrid.com/v3/contactdb/lists/ {list_id}/recipients/{recipient_id} HTTP/1.1 以便从列表中删除单个电子邮件收件人,但我收到此错误消息结果:{"errors":[{"message":"没有提供有效的收件人"}]}。

这是我从Sending DELETE to API using PHP修改的代码:

<?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);
?>

错误消息“没有提供有效的收件人”让我觉得我应该使用数字收件人 ID,但我无法为有问题的电子邮件地址找到它。它在哪里?

此外,上面的代码中还有什么其他问题导致我出现问题吗?

4

0 回答 0