Documentation

onCrmContactUpdate

The event is called when contact is updated.

Event parameters:

Parameter Description
FIELDS Array contain ID field with updated contact identifier.

Example

  1. Controller, receiving the query:
    @PostMapping("/onCrmContactUpdate")
    public ResponseEntity onCrmContactUpdate(@RequestParam("data[FIELDS][ID]") Long contactId) {
        // get contact from Bitrix24
        BitrixContactDto bitrixContactDto = deserializationBitrixUtil.deserializeContactForMethodGet(bitrixService.getContactById(contactId));
        // do something
        return new ResponseEntity(HttpStatus.OK);
    }
  2. Method for getting contact by ID from Bitrix24:
    public String getContactById(Long id) {
        MultiValueMap paramsMap = new LinkedMultiValueMap<>();
        paramsMap.add("id", id.toString());
        String response = null;
        try {
            response = callApiGet("crm.contact.get", paramsMap);
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
        return response;
    }
  3. Bitrix24 response deserialization:
    public BitrixContactDto deserializeContactForMethodGet(String contactJsonString) {    
        BitrixContactDto contact = null;
        if (contactJsonString != null) {
            JsonNode jsonNode = null;
            try {
                jsonNode = (JsonNode) objectMapper.readTree(contactJsonString).get("result");
            } catch (IOException e) {
                e.printStackTrace();
            }
            contact = deserializeBitrixContactDto(jsonNode);
        }
        return contact;
    }
  4. Object BitrixContactDto:
    public class BitrixContactDto { 
        private Long id;
        private String name;
        private String lastName;
        private String typeId;
        private String comments;
        private Set email;
    
        public BitrixContactDto() {}
    
        public BitrixContactDto(Long id, String name, String lastName, String typeId, String comments) {
            this.id = id;
            this.name = name;
            this.lastName = lastName;
            this.typeId = typeId;
            this.comments = comments;
        }
    }


© «Bitrix24», 2001-2022
Up