Skip to content

Commit 75d5b65

Browse files
Fix API endpoint structure and add version flexibility to HR Cloud component
1 parent e74215a commit 75d5b65

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

components/hr_cloud/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ To use this integration, you'll need an HR Cloud account and an API key. To get
99
1. Log in to your HR Cloud account
1010
2. Navigate to Settings > API Settings
1111
3. Create a new API key or use an existing one
12+
13+
# API URL Structure
14+
15+
This integration uses the HR Cloud API. If you encounter 404 errors, please confirm the correct API URL structure with your HR Cloud documentation, as it may vary depending on your account setup. The integration supports the following formats:
16+
17+
- https://api.hrcloud.com/api/... (default)
18+
- https://api.hrcloud.com/v1/api/... (older accounts)
19+
- https://api.hrcloud.com/v2/api/... (newer accounts)
20+
21+
If you continue to encounter 404 errors, please contact HR Cloud support to confirm your API URL structure.

components/hr_cloud/hr_cloud.app.mjs

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ export default {
44
type: "app",
55
app: "hr_cloud",
66
propDefinitions: {
7+
apiVersion: {
8+
type: "string",
9+
label: "API Version",
10+
description: "The HR Cloud API version to use. Leave empty to use the default version.",
11+
default: "",
12+
optional: true,
13+
},
714
departmentId: {
815
type: "string",
916
label: "Department",
@@ -147,7 +154,15 @@ export default {
147154
},
148155
methods: {
149156
_baseUrl() {
150-
return "https://api.hrcloud.com/v1";
157+
// Default to base URL without version
158+
const baseUrl = "https://api.hrcloud.com";
159+
160+
// If a version is specified in the app props, use it
161+
if (this.$auth.apiVersion) {
162+
return `${baseUrl}/${this.$auth.apiVersion}`;
163+
}
164+
165+
return baseUrl;
151166
},
152167
_authHeaders() {
153168
return {
@@ -169,14 +184,25 @@ export default {
169184
params,
170185
data,
171186
};
172-
return axios($, config);
187+
188+
try {
189+
console.log(`Making request to: ${config.url}`);
190+
const response = await axios($, config);
191+
return response;
192+
} catch (error) {
193+
console.error(`Error with request to ${path}: ${error.message}`);
194+
if (error.response?.status === 404) {
195+
throw new Error(`API endpoint not found (404): ${path}. Please verify the API URL structure in the HR Cloud documentation.`);
196+
}
197+
throw error;
198+
}
173199
},
174200
async createWebhook({
175201
eventType, endpoint, metadata,
176202
}) {
177203
return this._makeRequest({
178204
method: "POST",
179-
path: "/webhooks",
205+
path: "/api/webhooks",
180206
data: {
181207
event_type: eventType,
182208
endpoint,
@@ -187,83 +213,83 @@ export default {
187213
async deleteWebhook(webhookId) {
188214
return this._makeRequest({
189215
method: "DELETE",
190-
path: `/webhooks/${webhookId}`,
216+
path: `/api/webhooks/${webhookId}`,
191217
});
192218
},
193219
async getEmployees(args = {}) {
194220
const response = await this._makeRequest({
195-
path: "/employees",
221+
path: "/api/employees",
196222
...args,
197223
});
198224
return response.employees || [];
199225
},
200226
async getEmployee(employeeId, args = {}) {
201227
const response = await this._makeRequest({
202-
path: `/employees/${employeeId}`,
228+
path: `/api/employees/${employeeId}`,
203229
...args,
204230
});
205231
return response.employee;
206232
},
207233
async createEmployee(args = {}) {
208234
return this._makeRequest({
209235
method: "POST",
210-
path: "/employees",
236+
path: "/api/employees",
211237
...args,
212238
});
213239
},
214240
async getDepartments(args = {}) {
215241
const response = await this._makeRequest({
216-
path: "/departments",
242+
path: "/api/departments",
217243
...args,
218244
});
219245
return response.departments || [];
220246
},
221247
async getJobTitles(args = {}) {
222248
const response = await this._makeRequest({
223-
path: "/job-titles",
249+
path: "/api/job-titles",
224250
...args,
225251
});
226252
return response.job_titles || [];
227253
},
228254
async getLeaveRequests(args = {}) {
229255
const response = await this._makeRequest({
230-
path: "/leave-requests",
256+
path: "/api/leave-requests",
231257
...args,
232258
});
233259
return response.leave_requests || [];
234260
},
235261
async getLeaveTypes(args = {}) {
236262
const response = await this._makeRequest({
237-
path: "/leave-types",
263+
path: "/api/leave-types",
238264
...args,
239265
});
240266
return response.leave_types || [];
241267
},
242268
async approveLeaveRequest(requestId, args = {}) {
243269
return this._makeRequest({
244270
method: "PUT",
245-
path: `/leave-requests/${requestId}/approve`,
271+
path: `/api/leave-requests/${requestId}/approve`,
246272
...args,
247273
});
248274
},
249275
async getProjects(args = {}) {
250276
const response = await this._makeRequest({
251-
path: "/projects",
277+
path: "/api/projects",
252278
...args,
253279
});
254280
return response.projects || [];
255281
},
256282
async getTimesheetEntries(args = {}) {
257283
const response = await this._makeRequest({
258-
path: "/timesheet-entries",
284+
path: "/api/timesheet-entries",
259285
...args,
260286
});
261287
return response.timesheet_entries || [];
262288
},
263289
async createTimesheetEntry(args = {}) {
264290
return this._makeRequest({
265291
method: "POST",
266-
path: "/timesheet-entries",
292+
path: "/api/timesheet-entries",
267293
...args,
268294
});
269295
},

0 commit comments

Comments
 (0)