如何使用API​​和PHP删除单个Marketing Campaign收件人

时间:2017-01-25 17:47:15

标签: php curl sendgrid sendgrid-api-v3

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

以下是我从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);
?>

错误消息&#34;未提供有效的收件人&#34;让我觉得我应该使用数字收件人ID,但我还没能找到有问题的电子邮件地址。它在哪里?

另外,上面的代码中是否有其他原因导致我出现问题?

0 个答案:

没有答案