Bitrix调用api休息java

时间:2017-09-28 06:55:18

标签: bitrix

大家好!您好。

我是使用bitrix24的新手。现在,我正在开发通过调用rest api将数据从第三个应用程序发送到bitrix CRM。

那么,你能帮忙知道:bitrix支持使用java代码调用rest api吗?如果是,请帮我举几个例子。

非常感谢你。

3 个答案:

答案 0 :(得分:1)

此示例将新的自定义字段添加到公司对象

HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("https://xxxx.bitrix24.de/rest/1/xxxxx/crm.company.userfield.add/");

//@see bitrix documentation for more details https://training.bitrix24.com/rest_help/crm/contacts/crm_contact_userfield_add.php
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("fields[FIELD_NAME": "MY_STRING" };
params.add(new BasicNameValuePair("fields[EDIT_FORM_LABEL": "My string" };
params.add(new BasicNameValuePair("fields[LIST_COLUMN_LABEL": "My string" };
params.add(new BasicNameValuePair("fields[USER_TYPE_ID": "string" };
params.add(new BasicNameValuePair("fields[XML_ID": "MY_STRING" };

httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

//Execute and get the response.
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();

if (entity != null) {
    InputStream instream = entity.getContent();
    try {
        // do something useful
    } finally {
        instream.close();
    }
}

答案 1 :(得分:0)

Bitrix接受休息请求,你将从那里开始并不重要。

他们有这个文档显示所有被接受的“操作”: https://training.bitrix24.com/rest_help/index.php

并且bitrix有一个你可以轻松设置的wehbook,在这个链接下你会看到如何,但是例子是在PHP中,但是你可以使用java和一些库来创建相同类型的请求(java.net ssl的.HttpURLConnection或javax.net.ssl.HttpsURLConnection:

https://www.bitrix24.com/about/blogs/updates/fast-bitrix24-integration-webhook-street-magic.php

答案 2 :(得分:0)

您可以使用bitrix24-java-api。在github上查找此库的最新版本。

添加Maven依赖项

<repositories>
  <repository>
     <id>bitrix24-java-api-mvn-repo</id>
         <url>https://raw.github.com/JavaStream/bitrix24-java-api/mvn-repo/</url>
         <snapshots>
             <enabled>true</enabled>
             <updatePolicy>always</updatePolicy>
         </snapshots>
   </repository>
</repositories>

<dependency>
    <groupId>com.javastream</groupId>
    <artifactId>java-bitrix24-api</artifactId>
    <version>0.8-SNAPSHOT</version>
 </dependency>

项目中的Init Client。您需要插入您的Webhook令牌和bitrix帐户。

客户端客户端=新客户端(“令牌”,“ your-account.bitrix24.ru”,rest_id);

For example, working with Lead entity:

    // Create and save new Lead
    Lead lead = new Lead();         
    lead.add_title("Torrentino");
    client.getLeadService().addNewLead(lead); 

   // Get lead by ID = 4 
   Lead lead = client.getLeadService().getLeadById(4);

   // Delete lead by ID = 4
   client.getLeadService().deleteLeadById(4);

   // Update Lead 
   Lead lead = client.getLeadService().getLeadById(4);

  // Set new values for Simple fields (like String) 
  lead.setNAME("Albert");
  lead.setLAST_NAME("Shtein");
  lead.setADDRESS("West Olympic Boulevard Apt. 100");
  lead.setCOMMENTS("Interested in price");
  lead.setSTATUS_ID(StatusID_type.NEW.getCode());
  lead.setCURRENCY_ID(CurrencyID_type.EUR.getCode());
  lead.setSOURCE_ID(SourceID_type.RECOMMENDATION.getCode());

  // In multiple fields containing lists, the data is entered differently (for example, Phone, Email, Website, IM). For example, I change the first website
  Website website = lead.getWEB().get(0);
  website.setVALUE("www.albert-best.org");
  website.setVALUE_TYPE(Website_type.OTHER.getCode());
  List<Website> websitList = new ArrayList<>();
  websitList.add(website);
  lead.setWEB(websitList);
  client.getLeadService().updateLead(lead);