github.com/schmorrison/Zoho@v1.1.4/recruit/records.go (about) 1 package recruit 2 3 import ( 4 "fmt" 5 "time" 6 7 zoho "github.com/schmorrison/Zoho" 8 ) 9 10 // https://www.zoho.com/recruit/developer-guide/apiv2/search-records.html 11 func (c *API) SearchRecords( 12 request interface{}, 13 module Module, 14 params map[string]zoho.Parameter, 15 ) (data interface{}, err error) { 16 endpoint := zoho.Endpoint{ 17 Name: "SearchRecords", 18 URL: fmt.Sprintf( 19 "https://recruit.zoho.%s/recruit/v2/%s/search", 20 c.ZohoTLD, 21 module, 22 ), 23 Method: zoho.HTTPGet, 24 ResponseData: request, 25 URLParameters: map[string]zoho.Parameter{ 26 "criteria": "", // optional 27 "email": "", // optional 28 "phone": "", // optional 29 "word": "", // optional 30 "converted": "", // optional 31 "approved": "", // optional 32 "page": "1", // optional 33 "per_page": "200", // optional 34 }, 35 } 36 37 for k, v := range params { 38 endpoint.URLParameters[k] = v 39 } 40 41 err = c.Zoho.HTTPRequest(&endpoint) 42 if err != nil { 43 return nil, fmt.Errorf("failed to retrieve records of %s: %s", module, err) 44 } 45 46 if endpoint.ResponseData != nil { 47 return endpoint.ResponseData, nil 48 } 49 50 return nil, fmt.Errorf("data returned was nil") 51 } 52 53 // https://www.zoho.com/recruit/developer-guide/apiv2/insert-records.html 54 func (c *API) InsertRecords( 55 request InsertRecords, 56 module Module, 57 ) (data InsertRecordsResponse, err error) { 58 endpoint := zoho.Endpoint{ 59 Name: "InsertRecords", 60 URL: fmt.Sprintf("https://recruit.zoho.%s/recruit/v2/%s", c.ZohoTLD, module), 61 Method: zoho.HTTPPost, 62 ResponseData: &InsertRecordsResponse{}, 63 RequestBody: request, 64 } 65 66 err = c.Zoho.HTTPRequest(&endpoint) 67 if err != nil { 68 return InsertRecordsResponse{}, fmt.Errorf( 69 "failed to insert records of %s: %s", 70 module, 71 err, 72 ) 73 } 74 75 if v, ok := endpoint.ResponseData.(*InsertRecordsResponse); ok { 76 return *v, nil 77 } 78 79 return InsertRecordsResponse{}, fmt.Errorf("data returned was nil") 80 } 81 82 type UpdateRecordsResponseData struct { 83 Message string `json:"message,omitempty"` 84 Details struct { 85 ExpectedDataType string `json:"expected_data_type,omitempty"` 86 APIName string `json:"api_name"` 87 } `json:"details,omitempty"` 88 Status string `json:"status,omitempty"` 89 Code string `json:"code,omitempty"` 90 } 91 92 type InsertRecords struct { 93 Data interface{} `json:"data,omitempty"` 94 Trigger []string `json:"trigger,omitempty"` 95 } 96 type InsertRecordsResponseData struct { 97 Message string `json:"message,omitempty"` 98 Details struct { 99 CreatedBy struct { 100 ID string `json:"id,omitempty"` 101 Name string `json:"name,omitempty"` 102 } `json:"created_by,omitempty"` 103 ID string `json:"id,omitempty"` 104 ModifiedBy struct { 105 ID string `json:"id,omitempty"` 106 Name string `json:"name,omitempty"` 107 } `json:"modified_by,omitempty"` 108 ModifiedTime time.Time `json:"modified_time,omitempty"` 109 CreatedTime time.Time `json:"created_time,omitempty"` 110 } `json:"details,omitempty"` 111 Status string `json:"status,omitempty"` 112 Code string `json:"code,omitempty"` 113 } 114 115 type InsertRecordsResponse struct { 116 Data []InsertRecordsResponseData `json:"data,omitempty"` 117 } 118 119 // UpsertRecords will insert the provided records in the request, if they already exist it will be updated 120 // https://www.zoho.com/recruit/developer-guide/apiv2/upsert-records.html 121 // 122 // When performing an upsert, because the natural state of the records fields in this package is to 'omitempty' when encoding json, 123 // if you want to empty the fields contents in zoho you will need to embed the records type in a struct in your own package, 124 // and override the field with a field that has a json tag that does not contain 'omitempty'. 125 // eg. 126 // type struct Candidate { 127 // zohorecruit.Candidate 128 // CustomField string `json:"Custom_Field"` 129 // } 130 func (c *API) UpsertRecords( 131 request UpsertRecords, 132 module Module, 133 ) (data InsertRecordsResponse, err error) { 134 endpoint := zoho.Endpoint{ 135 Name: "UpsertRecords", 136 URL: fmt.Sprintf( 137 "https://recruit.zoho.%s/recruit/v2/%s/upsert", 138 c.ZohoTLD, 139 module, 140 ), 141 Method: zoho.HTTPPost, 142 ResponseData: &InsertRecordsResponse{}, 143 RequestBody: request, 144 } 145 146 err = c.Zoho.HTTPRequest(&endpoint) 147 if err != nil { 148 return InsertRecordsResponse{}, fmt.Errorf( 149 "failed to insert records of %s: %s", 150 module, 151 err, 152 ) 153 } 154 155 if v, ok := endpoint.ResponseData.(*InsertRecordsResponse); ok { 156 return *v, nil 157 } 158 159 return InsertRecordsResponse{}, fmt.Errorf("data returned was nil") 160 } 161 162 type UpsertRecords struct { 163 Data interface{} `json:"data,omitempty"` 164 DuplicateCheckFields []string `json:"duplicate_check_fields,omitempty"` 165 Trigger []string `json:"trigger,omitempty"` 166 } 167 168 // https://www.zoho.com/recruit/developer-guide/apiv2/get-associated-records.html 169 func (c *API) GetAssociatedRecords( 170 module Module, 171 recordId string, 172 ) (data AssociateRecordsResponse, err error) { 173 endpoint := zoho.Endpoint{ 174 Name: "GetAssociatedRecords", 175 URL: fmt.Sprintf( 176 "https://recruit.zoho.%s/recruit/v2/%s/%s/associate", 177 c.ZohoTLD, 178 module, 179 recordId, 180 ), 181 Method: zoho.HTTPGet, 182 ResponseData: &AssociateRecordsResponse{}, 183 URLParameters: map[string]zoho.Parameter{ 184 "posting_title": "", // optional 185 "candidate_statuses": "", // optional 186 "page": "1", // optional 187 "per_page": "200", // optional 188 }, 189 } 190 191 err = c.Zoho.HTTPRequest(&endpoint) 192 if err != nil { 193 return AssociateRecordsResponse{}, fmt.Errorf( 194 "failed to insert records of %s: %s", 195 module, 196 err, 197 ) 198 } 199 200 if v, ok := endpoint.ResponseData.(*AssociateRecordsResponse); ok { 201 return *v, nil 202 } 203 204 return AssociateRecordsResponse{}, fmt.Errorf("data returned was nil") 205 } 206 207 type AssociateRecordsResponse struct { 208 Data []struct { 209 Salary interface{} `json:"Salary"` 210 CurrencySymbol string `json:"$currency_symbol"` 211 AccountManager struct { 212 Name string `json:"name"` 213 ID string `json:"id"` 214 } `json:"Account_Manager"` 215 NoOfCandidatesHired int `json:"No_of_Candidates_Hired"` 216 TargetDate string `json:"Target_Date"` 217 LastActivityTime time.Time `json:"Last_Activity_Time"` 218 Industry string `json:"Industry"` 219 ModifiedBy struct { 220 Name string `json:"name"` 221 ID string `json:"id"` 222 } `json:"Modified_By"` 223 ProcessFlow bool `json:"$process_flow"` 224 ExpectedRevenue interface{} `json:"Expected_Revenue"` 225 IsHotJobOpening bool `json:"Is_Hot_Job_Opening"` 226 AccountName struct { 227 Name string `json:"name"` 228 ID string `json:"id"` 229 } `json:"Account_Name"` 230 ZipCode interface{} `json:"Zip_Code"` 231 ID string `json:"id"` 232 Skillset string `json:"Skillset"` 233 Approved bool `json:"$approved"` 234 Publish bool `json:"Publish"` 235 DateOpened string `json:"Date_Opened"` 236 PotentialName string `json:"Potential_Name"` 237 Approval struct { 238 Delegate bool `json:"delegate"` 239 Approve bool `json:"approve"` 240 Reject bool `json:"reject"` 241 Resubmit bool `json:"resubmit"` 242 } `json:"$approval"` 243 ModifiedTime time.Time `json:"Modified_Time"` 244 ActualRevenue interface{} `json:"Actual_Revenue"` 245 CreatedTime time.Time `json:"Created_Time"` 246 Followed bool `json:"$followed"` 247 NoOfCandidatesAssociated int `json:"No_of_Candidates_Associated"` 248 Editable bool `json:"$editable"` 249 IsLocked bool `json:"Is_Locked"` 250 City interface{} `json:"City"` 251 JobOpeningStatus string `json:"Job_Opening_Status"` 252 RevenuePerPosition int `json:"Revenue_per_Position"` 253 ContactName interface{} `json:"Contact_Name"` 254 AssociatedTags []interface{} `json:"Associated_Tags"` 255 AssignedRecruiter []interface{} `json:"Assigned_Recruiter"` 256 MissedRevenue interface{} `json:"Missed_Revenue"` 257 JobOpeningID string `json:"Job_Opening_ID"` 258 JobDescription string `json:"Job_Description"` 259 WorkExperience interface{} `json:"Work_Experience"` 260 JobType string `json:"Job_Type"` 261 State interface{} `json:"State"` 262 NumberOfPositions string `json:"Number_of_Positions"` 263 Country interface{} `json:"Country"` 264 CreatedBy struct { 265 Name string `json:"name"` 266 ID string `json:"id"` 267 } `json:"Created_By"` 268 IsAttachmentPresent bool `json:"Is_Attachment_Present"` 269 } `json:"data"` 270 Info PageInfo `json:"info,omitempty"` 271 }