Mailchimp v3 - 仅从特定列表中检索成员姓名和电子邮件

时间:2016-02-02 03:31:07

标签: php curl mailchimp

我想从特定列表中检索一组成员。但是,我只对他们的名字,电子邮件以及他们的身份证明感兴趣,而不是大回应。

我得到的代码可以很好地检索列表中成员的每个细节

Public Class Functions
    Inherits BaseClass
    Public Function KesDetails(KesID As Integer) As KesH

        Dim Sql As New SqlClass
        Dim lRd As DataTableReader


        Sql.OpenConnection()

        Sql.lCmd.CommandText = " SELECT"
        Sql.lCmd.CommandText &= " Case WHEN KAHStatus = 'M' THEN 'LULUS'  ELSE cast(DATEDIFF(Day, KAHCreatedOn, GetDate()) as varchar(10)) END As DayCount"
        Sql.lCmd.CommandText &= " ,KAHID,KAH_AKJID,KAHCreatedBy,KAHCreatedOn"
        Sql.lCmd.CommandText &= " ,KAHLokasi,KAHHirarki,KAHPenjaga,KAHBertanggungjawab,KAHInden,KAHMelulus,KAH_KAJID,KAJNAMA,G.FPNoTender,G.FPNoKontrak,G.FPTajukProjek,G.FPKontrakNamaSyarikat,KAHUpdatedOn"
        Sql.lCmd.CommandText &= " FROM HartaMajlis..KejuruteraanArahanH A "
        Sql.lCmd.CommandText &= " LEFT JOIN HartaMajlis..KejuruteraanArahanProd B ON A.KAH_KAPID=B.KAPID"
        Sql.lCmd.CommandText &= " LEFT JOIN HartaMajlis..AduanKejuruteraan C ON A.KAH_AKJID=C.AKJProjekID"
        Sql.lCmd.CommandText &= " LEFT JOIN hartamajlis..hartabangunan D ON C.AKJ_ITEMID = D.HTBgnID"
        Sql.lCmd.CommandText &= " LEFT JOIN hartamajlis..KejuruteraanArahanJenis E ON A.KAH_KAJID = E.KAJID"
        Sql.lCmd.CommandText &= " LEFT JOIN hartamajlis..KejuruteraanArahanHirarki F ON A.KAHHirarki = F.KAHHID"
        Sql.lCmd.CommandText &= " LEFT JOIN hartamajlis..FailProjek G ON F.KAHH_FKJTenderNo = G.FPNoTender"
        Sql.lCmd.CommandText &= " WHERE A.KAHDeleted<>'Y'"
        Sql.lCmd.CommandText &= " AND A.KAHID = " & KesID
        Sql.lCmd.CommandText &= " ORDER BY A.KAHUpdatedON DESC"

        lRd = Sql.QueryData().CreateDataReader

        Dim lsData As New KesH

        If lRd.Read() Then
            'lsData.DayCount = Convert.ToString(lRd("DayCount"))
            'lsData.KAHID = Convert.ToInt32(lRd("KAHID"))
            'lsData.KAH_AKJID = Convert.ToString(lRd("KAH_AKJID"))
            'lsData.KAHCreatedOn = Convert.ToString(lRd("KAHCreatedOn"))
            'lsData.KAHLokasi = Convert.ToString(lRd("KAHLokasi"))
            'lsData.KAHCreatedBy = Convert.ToString(lRd("KAHCreatedBy"))
            'lsData.KAHLokasi = Convert.ToString(lRd("KAHLokasi"))
            'lsData.KAHHirarki = Convert.ToString(lRd("KAHHirarki"))
            'lsData.KAHPenjaga = Convert.ToString(lRd("KAHPenjaga"))
            'lsData.KAHBertanggungjawab = Convert.ToString(lRd("KAHBertanggungjawab"))
            'lsData.KAHInden = Convert.ToString(lRd("KAHInden"))
            'lsData.KAHMelulus = Convert.ToString(lRd("KAHMelulus"))
            'lsData.KAH_KAJID = Convert.ToString(lRd("KAH_KAJID"))
            'lsData.KAJNAMA = Convert.ToString(lRd("KAJNAMA"))
            'lsData.FPKontrakNamaSyarikat = Convert.ToString(lRd("FPKontrakNamaSyarikat"))
            'lsData.FPNoKontrak = Convert.ToString(lRd("FPNoKontrak"))
            'lsData.FPNoTender = Convert.ToString(lRd("FPNoTender"))
            'lsData.KAHUpdatedOn = Convert.ToDateTime(lRd("KAHUpdatedOn"))

            Dim properties As PropertyInfo() = GetType(KesH).GetProperties()
            For Each Names As PropertyInfo In properties
                If Names.PropertyType = GetType(String) Or Names.PropertyType = GetType(Integer) Or Names.PropertyType = GetType(DateTime) Then
                    MsgBox(Names.Name & Names.PropertyType.ToString)
                    lsData.(Names.Name) = lRd(Names.Name)

                End If
            Next

        End If

        Sql.CloseConnection()
        Return lsData
    End Function
End Class

但是如果我尝试在请求URL中添加我想要的字段,我会收到422错误:

  

&#34;请求的字段无效&#34; &#34;请求的某些字段无效:   member.first_name&#34;

提出此请求的正确方法是什么?只有特定列表中所有成员的某些字段?

谢谢你们!

1 个答案:

答案 0 :(得分:8)

以下是传递必填字段的方法

$ch = curl_init(REQUEST_URL.$list.'/members/?fields=members.id,members.email_address');

  curl_setopt($ch, CURLOPT_USERPWD, 'user:' . API_KEY);
  curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  $result = curl_exec($ch);
  $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  $error = curl_error ( $ch );
  curl_close($ch);