如何在java中使用xml rpc服务在infusionsoft中创建联系人?

时间:2016-05-10 05:46:02

标签: java infusionsoft

我正在尝试用输入软件中的java应用程序创建联系人,但未能得到响应。有时我得到连接超时错误,有时会得到错误596.

我的示例代码属于同事:

public static void addContact() {
try {
//Sets up the java client, including the api url
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setEnabledForExtensions(true);
config.setConnectionTimeout(60 * 1000);
config.setReplyTimeout(60 * 1000);
config.setServerURL(new URL(\"https://api.infusionsoft.com/\"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);

//The secure encryption key
String key = \"sdfsdfsdfsdfs34534534534534\";

/**
* ***********************************************
* *
* ADD CONTACT TO DATABASE *
* ***********************************************
*/
List parameters = new ArrayList();
Map contactData = new HashMap();
contactData.put(\"FirstName\", \"Java John\");
contactData.put(\"LastName\", \"Doe\");
contactData.put(\"Email\", \"john@doe.com\");

parameters.add(key); //The secure key
//parameters.add(\"Contact\"); //The table we will be adding to
parameters.add(contactData); //The data to be added

//Make the call
Integer contactId = (Integer) client.execute(\"ContactService.add\", parameters);
System.out.println(\"Contact added was \" + contactId);
} catch (MalformedURLException ex) {
System.out.println(ex);
} catch (XmlRpcException ex) {
System.out.println(ex);
}
}

如何在java中使用XMLRPC服务在输入软件中创建联系人?我可以有示例代码吗?

1 个答案:

答案 0 :(得分:0)

这是在输液软件中创建联系人的完整代码。

键:键参数是创建帐户时输液软件提供的密钥

网址:" https://myApp.infusionsoft.com:443/api/xmlrpc",需要在' myApp'。

的地方写下您应用的名称。

public static void addContact() {
        try {
            //Sets up the java client, including the api url
            XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
            config.setServerURL(new URL("https://myApp.infusionsoft.com:443/api/xmlrpc"));
            XmlRpcClient client = new XmlRpcClient();
            client.setConfig(config);

            //The secure encryption key
            String key = "34534k34h5k34hj34k5hhk";

            /**
             * ***********************************************
             *                                               *
             * ADD CONTACT TO DATABASE *
             * ***********************************************
             */
            List parameters = new ArrayList();
            Map contactData = new HashMap();
            contactData.put("FirstName", "Java John");
            contactData.put("LastName", "Doe");
            contactData.put("Email", "john@doe.com");

            parameters.add(key); //The secure key
            //parameters.add("Contact"); //The table we will be adding to
            parameters.add(contactData); //The data to be added

            //Make the call
            Integer contactId = (Integer) client.execute("ContactService.add", parameters);
            System.out.println("Contact added was " + contactId);
        } catch (MalformedURLException ex) {
            System.out.println(ex);
        } catch (XmlRpcException ex) {
            System.out.println(ex);
        }
    }

这是完整的工作代码,花了3天后我才能得到解决方案。