public BulkAPIResponse <ZCRMTag> CreateTags(List <ZCRMTag> tags) { if (tags.Count > 50) { throw new ZCRMException(APIConstants.API_MAX_TAGS_MSG); } try { requestMethod = APIConstants.RequestMethod.POST; urlPath = "settings/tags?module=" + module.ApiName; JObject requestBodyObject = new JObject(); JArray dataArray = new JArray(); foreach (ZCRMTag tag in tags) { if (tag.Id == null) { dataArray.Add(GetZCRMTagAsJSON(tag)); } else { throw new ZCRMException("Tag ID MUST be null for CreateTags operation."); } } requestBodyObject.Add(APIConstants.TAGS, dataArray); requestBody = requestBodyObject; BulkAPIResponse <ZCRMTag> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMTag>(); List <ZCRMTag> createtags = new List <ZCRMTag>(); List <EntityResponse> responses = response.BulkEntitiesResponse; int responseSize = responses.Count; for (int i = 0; i < responseSize; i++) { EntityResponse entityResponse = responses[i]; if (entityResponse.Status.Equals(APIConstants.CODE_SUCCESS)) { JObject responseData = entityResponse.ResponseJSON; JObject tagDetails = (JObject)responseData[APIConstants.DETAILS]; ZCRMTag newTag = tags[i]; SetTagProperties(newTag, tagDetails); createtags.Add(newTag); entityResponse.Data = newTag; } else { entityResponse.Data = null; } } response.BulkData = createtags; return(response); } catch (Exception e) when((e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
public BulkAPIResponse <ZCRMRecord> CreateRecords(List <ZCRMRecord> records) { if (records.Count > 100) { throw new ZCRMException(APIConstants.API_MAX_RECORDS_MSG); } requestMethod = APIConstants.RequestMethod.POST; urlPath = module.ApiName; JObject requestBodyObject = new JObject(); JArray dataArray = new JArray(); foreach (ZCRMRecord record in records) { if (record.EntityId == null) { dataArray.Add(EntityAPIHandler.GetInstance(record).GetZCRMRecordAsJSON()); } else { throw new ZCRMException("Entity ID Must be null/empty for CreateRecords operation."); } } requestBodyObject.Add(APIConstants.DATA, dataArray); requestBody = requestBodyObject; BulkAPIResponse <ZCRMRecord> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMRecord>(); List <ZCRMRecord> createdRecords = new List <ZCRMRecord>(); List <EntityResponse> responses = response.BulkEntitiesResponse; int responseSize = responses.Count; for (int i = 0; i < responseSize; i++) { EntityResponse entityResponse = responses[i]; if (entityResponse.Status.Equals(APIConstants.CODE_SUCCESS)) { JObject responseData = entityResponse.ResponseJSON; JObject recordDetails = (JObject)responseData[APIConstants.DETAILS]; ZCRMRecord newRecord = records[i]; EntityAPIHandler.GetInstance(newRecord).SetRecordProperties(recordDetails); createdRecords.Add(newRecord); entityResponse.Data = newRecord; } else { entityResponse.Data = null; } } response.BulkData = createdRecords; return(response); }
protected override void ProcessDataResponse() { BulkEntitiesResponse = new List <EntityResponse>(); JArray recordsArray = new JArray(); if (ResponseJSON.ContainsKey(APIConstants.DATA)) { recordsArray = (JArray)ResponseJSON[APIConstants.DATA]; foreach (JObject recordJSON in recordsArray) { if (recordJSON.ContainsKey(APIConstants.STATUS)) { EntityResponse individualResponse = new EntityResponse(recordJSON); BulkEntitiesResponse.Add(individualResponse); } } } else if (ResponseJSON.ContainsKey(APIConstants.TAGS)) { recordsArray = (JArray)ResponseJSON[APIConstants.TAGS]; foreach (JObject recordJSON in recordsArray) { if (recordJSON.ContainsKey(APIConstants.STATUS)) { EntityResponse individualResponse = new EntityResponse(recordJSON); BulkEntitiesResponse.Add(individualResponse); } } } else if (ResponseJSON.ContainsKey(APIConstants.TAXES)) { recordsArray = (JArray)ResponseJSON[APIConstants.TAXES]; foreach (JObject recordJSON in recordsArray) { if (recordJSON.ContainsKey(APIConstants.STATUS)) { EntityResponse individualResponse = new EntityResponse(recordJSON); BulkEntitiesResponse.Add(individualResponse); } } } }