Background: So our HR team puts a csv on a fileshare with a list of users that have left our organisation. I have a powershell script that checks that share every hour and will only run if there’s a new file. The PowerShell Script handles all the offboarding of use but we’re still required to log the ticket manually on Freshservice.
Unfortunately, my API knowledge is very limited and I have no idea how to even get started on this. I’ve had a look at the documentation but can’t see how to implement this into PowerShell.
Ideally, this should all be done in PowerShell with no 3rd party programs.
This is what I’ve done so far:
- Typed in the below on a command prompt in Windows
curl -v -u myapi:X -H "Content-Type: application/json" -X GET "https://mydomain.freshservice.com/api/v2/tickets/randomticketnumber"
- Grabbed the “ Authorization: Basic” value that came up in the output. I used this because for some reason, Postman doesn’t seem to work with the API key even if I set the value to X.
- Grabbed the below information from Postman as an example of an existing Leavers Service Request Item that i would want the script to create.
{
"requested_items": /
{
"custom_fields": {
"type": "Leaver List",
"prior_to_which_date": null,
"leavers_name": 12345678901,
"leave_date": "2022-05-30"
},
"id": 26001158185,
"created_at": "2022-05-24T10:50:22Z",
"updated_at": "2022-05-24T10:50:22Z",
"quantity": 1,
"stage": 1,
"loaned": false,
"cost_per_request": 0.0,
"remarks": null,
"delivery_time": null,
"is_parent": true,
"service_item_id": 86
}
]
}
- For what it’s worth, here’s the output of the ticket itself:
{
"ticket": {
"cc_emails": ],
"fwd_emails": ,],
"reply_cc_emails": /],
"bcc_emails": null,
"fr_escalated": true,
"spam": false,
"email_config_id": null,
"group_id": 10987654321,
"priority": 2,
"requester_id": 12345678901,
"requested_for_id": 12345678901,
"responder_id": 12345678901,
"source": 2,
"status": 2,
"subject": "Leaver - John Smith - 2022-05-30 00:00:00 Leaver List",
"to_emails": null,
"sla_policy_id": 26000004243,
"department_id": 26000071744,
"id": 12345,
"type": "Service Request",
"due_by": "2022-05-27T07:50:27Z",
"fr_due_by": "2022-05-25T09:50:27Z",
"is_escalated": true,
"description": "",
"description_text": "",
"custom_fields": {
"closing_subcategories": null,
"contact_number_not_required": null,
},
"created_at": "2022-05-24T10:50:22Z",
"updated_at": "2022-05-24T11:06:27Z",
"urgency": 1,
"impact": 1,
"category": "Service Requests (Don't use for Incidents)",
"sub_category": null,
"item_category": null,
"deleted": false,
"attachments": <],
"approval_status": 4,
"approval_status_name": "Not Requested"
}
}
Problem is, I have no idea how to even get started on sending the request from PowerShell. More to the matter, how do I use the UPN of the user (Fresh is linked to our Active Directory) to populate the “leavers_name” field or do I have to use the unique number for each person on Fresh?
Has anyone managed to implement something similar in their own environment?