GETRESPONSE API 2(添加自定义字段和使用PHP触点) [英] Getresponse API 2 (Adding Custom fields and contacts using PHP)

查看:278
本文介绍了GETRESPONSE API 2(添加自定义字段和使用PHP触点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进出口新的编码和网络的发展,因为它是和潜水与API的深水的一端是我希望我从来没有做过的事!不过说来我比预期的进一步发展了。试图自定义字段添加到添加联系人功能时,我现在遇到的问题。我试着去获得code到当用户点击我的三江源页面中添加隐藏的表单输入字段。我不想使用自己的Getresponses表单生成器为我的主页所以这是更好地使用API​​。我有code运行完美,当谈到刚刚添加联系人然而,当我添加code不执行set_contact_customs和失败,出现以下错误:(要求有回报的错误:数组),所以我理解它与set_contact_customs做阵列但即时通讯无能,它是我做错了..任何建议和帮助是pciated因为我仍然在学习的基础上你的专家这样说捡了极大的AP $ p $是一个很好的学习曲线。谢谢你。

---下面是没有set_contact_customs工作版本----

 < PHP
//添加联系人到选定的广告系列ID
尝试{
$ result_contact = $客户 - > add_contact(
$ API_KEY,
阵列(
'运动'=> 我的阵营-ID',
'名'=> $全名,
电子邮件=> $ EMAILADDRESS

);回声< p =风格'的颜色:蓝色; FONT-SIZE:24px的;'>没有错误,联系人和自定义字段已添加...< / P>中;
}赶上(例外$ E){回声$ E->的getMessage();
}?>

---这是导致该问题(与set_contact_customs)在code ----

 < PHP
//添加联系人到选定的广告系列ID
尝试{
$ result_contact = $客户 - > add_contact(
$ API_KEY,
阵列(
'运动'=> 我的阵营-ID',
'名'=> $全名,
电子邮件=> $ EMAILADDRESS

);
$ result_contact = $客户 - > set_contact_customs(
        $ API_KEY,
            阵列(
                调查型'=> $ surveytype,
                调查成本'=> $ surveycost
                )
);
回声< p =风格'的颜色:蓝色; FONT-SIZE:24px的;'>联系和增加LT; / P>中;
}赶上(例外$ E){回声$ E->的getMessage();
}?>


解决方案

  1. 2 API实际上并不存在:在他们说版 1.5.0 - 这是我们的API的最后JSON / RPC版本,尤其是如果你是11个月前讲话。现在,他们是preparing到beta测试V3。所以我会假设你在谈论1.5,并回答有关它(我不熟悉的V3,也许有它的不同)。


  2. 您必须发送联系人ID与set_contact_customs ,而你没有。


  3. 当它说,请求错误:数组,它不涉及到你的数组(即使这个问题是您的数组中,因为你不发送CONTACT ID),他们发送数组作为错误消息的响应。


  4. 我很想告诉你,在哪里得到的接触ID,以发送,但现在我正在寻找它自己。 :)


更新:

好吧,我从片结合它在互联网上,现在这里的工作形式。


  • 您不必add_contact,然后更新它,你可以一步到位做到这一点,添加海关参数来调用add_contact(GR比方说,我们不应该期待的接触立即加入,所以你可能甚至不会为之更新,如果你调用该函数的时候了)。

    描述了add_contact字段 rel=\"nofollow\">。


  • 在'关'参数应该是不同的。相反的:

     阵列(
        调查型'=> $ surveytype,
        调查成本'=> $ surveycost
        )

    应该是:

     阵列(
        阵列('名'=>调查型','内容'=> $ surveytype)
        阵列('名'=>'调查成本','内容'=> $ surveycost)
        )

    顺便说一句,从我的测试, - 幸好,你不需要在GR UI定义第一的自定义字段,无论你送,将被添加或更新(在他们的极限自定义字段名称和值)。

    我得到的错误,当试图发送一个自定义字段为空的内容,呼吁add_contact时。当我与set_contact_customs送了它,我没有得到任何错误;我想看看,它是否会删除字段或字段值 - 它没有做的事情


  • 如果您仍然希望以更新现有的联系人,这里是如何与更新调用发送的联系人ID:

      $结果= $客户 - > set_contact_customs(
       $ API_KEY,阵列(
          接触= GT; $ CONTACT_ID,
          '关'=> $ custom_fields_array
        )
    );


  • 要先找接触ID,你应该叫 get_contacts 。而且由于它被说(我没有测试过),在不同活动使用相同的电子邮件地址,联系方式有不同的接触ID,您应该同时通过运动,与它的电子邮件。

    当你可以看到,运动可以在发送'运动'参数(当时的广告系列ID,你得到了add_contact,应该使用),或在get_campaigns(那么可以使用广告活动的名称,甚至preFIX)。

    下面的系列ID的号召,为您的code:

      $结果= $客户 - > get_contacts(
        $ API_KEY,阵列(
           '运动'=>阵列(我的阵营-ID),
           电子邮件=>阵列('等于'=> $ EMAILADDRESS)
        )
    );


  • 要检索get_contacts接触ID,做同样的建议检索广告系列ID:

      $ CONTACT_ID = array_pop(array_keys($结果));
    如果(空($ CONTACT_ID)){
        //仍不确定
    }
    其他{
        //你可以调用set_contact_customs
    }


  • 为了该错误消息是更具描述性的,而不是仅仅要求有回报的错误:数组,打开你的jsonRPCClient.php,你最肯定包括与这些GR函数调用您的文件,查找以下行:

      is_null($响应['错误'])=&GT!; 要求有回报的错误:。 $响应['错误'],

    和用下面的替换它,至少包括:

      is_null($响应['错误'])=&GT!; 请求已返回错误:'。 var_export($响应['错误'],真实)

    现在您的code将用心爱的 var_export 的功能,如果你犯了一个错误,你会在你的错误日志是这样看:

     请求都返回错误:阵列(
      '消息'= GT; 参数无效,
      code'=> -32602,


  • 我献给彻底解决所有这些,谁帮我在这里没完没了的StackOverflow,只是给他们的回答别人的问题,有时年前。谢谢!希望我的回答可以节省时间的人,努力和情绪,太。 :)

    Im new to coding and web development as it is and diving into the deep end with API's is a thing i wish i never had done! However being said i have progressed further than expected. I am now having problems when trying to add custom fields to the add contact feature. Im trying to get the code to add the hidden form input fields when the user hits my thankyou page. I dont want to use Getresponses own Form builder for my main page so it was better to use the API. I have the code running perfectly when it comes to just adding the contact however when i add the set_contact_customs the code does not execute and fails with the following error: (Request have return error: Array) So i understand its to do with the set_contact_customs array however im clueless as to what it is i have done wrong.. Any advice and help is greatly appreciated as i am still learning the basics so picking up on what you experts say is a great learning curve. Thanks.

    --- Below is the working version without the set_contact_customs ----

    <?php
    // Add contact to selected campaign id
    try{
    $result_contact = $client->add_contact(
    $api_key,
    array (
    'campaign' => 'My-Camp-ID',
    'name' => $fullname,
    'email' => $emailaddress
    )
    );
    
    echo "<p style='color: blue; font-size:24px;'>No Errors, Contact and Custom Fields have been added...</p>";
    }
    
    catch (Exception $e) {
    
    echo $e->getMessage();
    }
    
    ?>
    

    --- Here is the code that causes the problems (with set_contact_customs) ----

        <?php
    // Add contact to selected campaign id
    try{
    $result_contact = $client->add_contact(
    $api_key,
    array (
    'campaign' => 'My-Camp-ID',
    'name' => $fullname,
    'email' => $emailaddress
    )
    );
    $result_contact = $client->set_contact_customs(
            $api_key,
                array(
                    'Survey Type' => $surveytype,
                    'Survey Cost' => $surveycost
                    )
    );
    echo "<p style='color: blue; font-size:24px;'> Contact Added </p>";
    }
    
    catch (Exception $e) {
    
    echo $e->getMessage();
    }
    
    ?>
    

    解决方案

    1. API 2 doesn't really exist: in GetResponse they say version "1.5.0 - this is last JSON/RPC version of our API", especially if you were speaking 10 months ago. Now they are preparing to beta-test v3. So I will assume you were speaking about 1.5 and answer about it (I'm not familiar with v3, maybe there it's different).

    2. You must send contact id with set_contact_customs, and you didn't.

    3. When it says, "request error: array", it doesn't relate to your array (even though the problem is in your array, because you don't send in it contact id), they are sending an array as a response with error messages.

    4. I'd love to tell you, where to get the contact id in order to send it, but I'm looking for it myself now. :)

    UPDATE:

    Ok, I combined it from pieces all over the internet, and now here's the working format.

    1. You don't need to add_contact and then update it, you can do it in one go, adding the 'customs' parameter to the add_contact call (GR say, that we shouldn't expect for the contact to be added immediately, so you might not even get whom to update, if you call that function right away).

      The fields for add_contact are described here.

    2. The 'customs' parameter should look differently. Instead of:

      array(
          'Survey Type' => $surveytype,
          'Survey Cost' => $surveycost
          )
      

      it should be:

      array(
          array( 'name' => 'Survey Type', 'content' => $surveytype ),
          array( 'name' => 'Survey Cost', 'content' => $surveycost )
          )
      

      By the way, from what I tested, - blessedly, you don't need to define in GR UI those custom fields first, whatever you send, will be added or updated (in their limits for the custom field names and values).

      I got error, when tried to send one custom field with empty content, when calling add_contact. When I sent it with set_contact_customs, I didn't get any error; I wanted to see, if it would delete the field or field value - it didn't do a thing.

    3. If you still wish to update the existing contact, here's how to send the contact id with the update call:

      $result = $client->set_contact_customs(
         $api_key, array(
            'contact' => $contact_id,
            'customs' => $custom_fields_array
          )
      );
      

    4. To first find contact id, you should call get_contacts. And since it's been said (I haven't tested it), that in different campaigns contacts with the same email address have different contact id, you should pass both the campaign, and the email with it.

      As you can see, campaign can be sent in 'campaigns' parameter (then campaign id, that you got for add_contact, should be used), or in 'get_campaigns' (then the campaign name or even prefix can be used).

      Here's the call with campaign id, for your code:

      $result = $client->get_contacts(
          $api_key, array(
             'campaigns' => array( 'My-Camp-ID' ),
             'email' => array( 'EQUALS' => $emailaddress )
          )
      );
      

    5. To retrieve contact id from get_contacts, do the same as recommended for retrieving campaign id:

      $contact_id = array_pop( array_keys( $result ) );
      if ( empty( $contact_id ) ) {
          //still not ok
      }
      else {
          //you can call set_contact_customs
      }
      

    6. In order for that error message to be more descriptive, instead of just 'Request have return error: Array', open your jsonRPCClient.php, which you most surely include in your file with these GR function calls, and look for the following line:

      !is_null($response['error']) => 'Request have return error: ' . $response['error'],
      

      and replace it with the following, at least:

      !is_null($response['error']) => 'Request have returned error: ' . var_export($response['error'], true),
      

      Now your code will use the beloved var_export function and if you make a mistake, you will see in your error log something like:

      Request have returned error: array (
        'message' => 'Invalid params',
        'code' => -32602,
      )
      

    I dedicate this thorough answer to all those, who helped me endlessly here on StackOverflow, just giving their answers to someone else's questions, sometimes years ago. Thank you! Hopefully my answer will save someone time, efforts, and mood, too. :)

    这篇关于GETRESPONSE API 2(添加自定义字段和使用PHP触点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆