0

每个人!你好。

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

那么,您能否帮忙了解一下:bitrix 是否支持使用 java 代码调用 rest api?如果是,请帮我举一些例子。

太感谢了。

4

3 回答 3

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();
    }
}
于 2018-07-11T12:59:21.690 回答
0

Bitrix 接受休息请求,您将在哪里制作并不重要。

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

Bitrix 有一个你可以轻松设置的 webbook,在下面的这个链接中你会看到如何,但是示例代码是用 PHP 编写的,但是你可以使用 java 和一些库(java.net.HttpURLConnection 或用于 ssl 的 javax.net.ssl.HttpsURLConnection):

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

于 2017-10-19T16:21:10.393 回答
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>

在您的项目中初始化客户端。您需要插入您的 Webhook 令牌和 bitrix-account。

客户端client = new Client("token", "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); 
于 2020-01-08T05:18:22.590 回答