【问题标题】:Bitrix call api rest javaBitrix调用api rest java
【发布时间】:2017-09-28 06:55:18
【问题描述】:

大家!你好。

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

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

非常感谢。

【问题讨论】:

    标签: bitrix


    【解决方案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();
        }
    }
    

    【讨论】:

      【解决方案2】:

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

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

      bitrix 有一个可以轻松设置的 wehbook,在下面的这个链接中你会看到如何,但是示例代码是 PHP 的,但是你可以使用 java 和一些库(java.net)发出相同类型的请求.HttpURLConnection 或 javax.net.ssl.HttpsURLConnection for ssl):

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

      【讨论】:

        【解决方案3】:

        您可以使用 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 Token 和 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-09-05
          • 1970-01-01
          • 1970-01-01
          • 2018-01-24
          • 1970-01-01
          • 2021-11-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多