如何使用sugaronrest在Java中通过其API向SuiteCRM中的潜在客户添加电子邮件?
我正在尝试使用sugaronrest库,通过Java应用程序的API向SuiteCRM中的lead添加电子邮件地址 我可以成功创建Leads模块和EmailAddresses模块,但无法创建EmailAddrBeanRel模块如何使用sugaronrest在Java中通过其API向SuiteCRM中的潜在客户添加电子邮件?,java,suitecrm,Java,Suitecrm,我正在尝试使用sugaronrest库,通过Java应用程序的API向SuiteCRM中的lead添加电子邮件地址 我可以成功创建Leads模块和EmailAddresses模块,但无法创建EmailAddrBeanRel模块 public static void main(String[] args) { String email = "name@domain.com"; String referrer = "Testing"; String leadId = cr
public static void main(String[] args) {
String email = "name@domain.com";
String referrer = "Testing";
String leadId = createLead("Fake", "Lead", email, referrer, "Created by testing SuiteCRM Java");
LOGGER.info("leadId: "+leadId);
String emailId = createEmail(email);
LOGGER.info("emailId: "+emailId);
String relationshipId = createEmailAddrBeanRel(leadId, emailId);
LOGGER.info("relationshipId: "+relationshipId);
}
private static String createModule(String moduleName, Object crmModule, List<String> selectFields) {
String moduleId = null;
try {
SugarRestClient client = new SugarRestClient(crmUrl, crmUsername, crmPwd);
SugarRestRequest request = new SugarRestRequest(moduleName, RequestType.Create);
request.setParameter(crmModule);
request.getOptions().setSelectFields(selectFields);
SugarRestResponse response = client.execute(request);
if (response == null) throw new Exception("Null response");
String jsonRawResponse = response.getJsonRawResponse();
if (jsonRawResponse == null || jsonRawResponse.length() < 2) {
ErrorResponse errorResponse = response.getError();
Gson gson = new Gson();
throw new Exception(""
+" errorResponse: "+gson.toJson(errorResponse)
+" StatusCode: "+response.getStatusCode()
+" JsonRawResponse: "+response.getJsonRawResponse()
);
}
JSONObject requestJSONObject = (JSONObject) new JSONParser().parse(jsonRawResponse);
moduleId = (String) requestJSONObject.get("id");
}
catch (Exception e) {
LOGGER.error("createModule error: "+e.getMessage(), e);
}
return moduleId;
}
public static String createLead(String firstName,String lastName,String email,String referrer,String description) {
String leadId = null;
String leadSource = "Other";
String leadSourceDescription = "Added from API";
String status = "New";
String statusDescription = "Added from API";
Leads createLead = new Leads();
createLead.setFirstName(firstName);
createLead.setLastName(lastName);
createLead.setDescription(description);
createLead.setLeadSource(leadSource);
createLead.setLeadSourceDescription(leadSourceDescription);
createLead.setStatus(status);
createLead.setStatusDescription(statusDescription);
createLead.setAssignedUserId(assignedUserId);
List<String> selectFields = new ArrayList<String>();
selectFields.add(NameOf.Leads.FirstName);
selectFields.add(NameOf.Leads.LastName);
selectFields.add(NameOf.Leads.Description);
selectFields.add(NameOf.Leads.LeadSource);
selectFields.add(NameOf.Leads.LeadSourceDescription);
selectFields.add(NameOf.Leads.Status);
selectFields.add(NameOf.Leads.StatusDescription);
selectFields.add(NameOf.Leads.AssignedUserId);
leadId = createModule("Leads", createLead, selectFields);
return leadId;
}
public static String createEmail(String email) {
String emailId = null;
EmailAddresses newEmail = new EmailAddresses();
newEmail.setEmailAddress(email);
List<String> selectFields = new ArrayList<String>();
selectFields.add(NameOf.EmailAddresses.EmailAddress);
emailId = createModule("EmailAddresses", newEmail, selectFields);
return emailId;
}
public static String createEmailAddrBeanRel(String leadId, String emailId) {
String emailAddrBeanRelId = null;
EmailAddrBeanRel emailAddrBeanRel = new EmailAddrBeanRel();
emailAddrBeanRel.setEmailAddressId(emailId);
emailAddrBeanRel.setBeanModule("Leads");
emailAddrBeanRel.setBeanId(leadId);
emailAddrBeanRel.setPrimaryAddress(1);
List<String> selectFields = new ArrayList<String>();
selectFields.add(NameOf.EmailAddrBeanRel.EmailAddressId);
selectFields.add(NameOf.EmailAddrBeanRel.BeanModule);
selectFields.add(NameOf.EmailAddrBeanRel.BeanId);
selectFields.add(NameOf.EmailAddrBeanRel.PrimaryAddress);
emailAddrBeanRelId = createModule("EmailAddrBeanRel", emailAddrBeanRel, selectFields);
return emailAddrBeanRelId;
}
电子邮件地址和潜在客户创建得很好,但是电子邮件地址没有添加到潜在客户中,也没有记录添加到email\u addr\u bean\u rel
表中
我不是:
- 以正确的方式进行,但遗漏了一些重要的数据或流程,或者
- 完全走错了路
createModule error: errorResponse: {"statusCode":0,"number":0} StatusCode: 200 JsonRawResponse: