Employee Updater API, Using PowerShell

Hey all, I posted this question in a somewhat relevant thread but hadn't received a response, possibly because the thread was a bit old. Anyway, I am working on automating new user creation with my onboarding script, which is written in PowerShell. I've pieced together quite a bit just from reading questions in this community, but I'm now stuck trying to figure out how to properly translate the "send the CSV" portion of the curl. Here's how I'm writing the JSON, but if anyone has any experience with the "data" portion that would be terrific.
$json = [ordered]@{
"requestJobDescription" = @{
"type" = "update";
"credentials" = @{
"partnerUserID" = $expensify_id;
"partnerUserSecret" = $expensify_secret;
}
"inputSettings" = @{
"type" = "employees";
"policyID" = "$policy_ID";
"fileType" = "csv";
}
};
"data" = "C:\expensify.csv";
} | ConvertTo-Json -Depth 5
Best Answer
-
This was solved with some help from StackOverflow. See the link below, but basically the problem was due to the kinda unique request format that Expensify requires (the two -F flags). This isn't native to Invoke-RestMethod so you have to write it yourself. Big thanks to the dude who helped me solve this.
https://stackoverflow.com/questions/58564314/invoke-restmethod-to-send-a-csv
Answers
-
Just bumping this request. I would love it if anyone has had any experience using the Employee Updated API with PowerShell.
-
Hey @derekritchison , make sure you select 'No' under your response for 'Does this answer your question?'. This will make sure it isn't closed incorrectly as answered. I'm curious about any resolution you might reach because we are having issues with our API as well. I doubt they're directly related, but hoping the extra visibility leads to them uncovering some root issues (Also answer 'no' for my response as well).
-
Thank you for the tip! And yes, would love to learn how to send this CSV to the API via PowerShell / Invoke-WebRequest! I feel like I'm so close. Happy to share my entire code if anyone familiar with Invoke-WebRequest wants to take a look.
-
Hi @derekritchison! One of our other users, @DMuncy, shared this great example of a successful request using PowerShell. Check it out and don't hesitate to ping other users that you know have experience based on other threads. Our community is always happy to help!
-
I unfortunately never tried this feature set, it felt lacking in details for our use.
Looks like you may need to use "-infile" to define the path to the file to upload
However perhaps this is of use?
or:
-
Sorry for the delay here. Our HQ relocated this week and I've been slammed with that project for a while. Anyway... no, I still cannot get this to work, and -InFile did not do the trick either. I'm still seeing one of two errors, depending on how I "musical chairs" some of this. I'm either getting the "requestJobDescription not found" error, or using the code below an "Internal Server Error" response. I would REALLY like to figure this out, and I'm quite surprised that nobody on the boards has used the API to automate provisioning for new hires as it seems like such an obvious time save. I'd even be willing to look at doing this in PHP or Ruby if anyone has successfully written this in either of those languages.
Re-submitting my current code that is giving me the internal server error response.
$expensify_url = "https://integrations.expensify.com/Integration-Server/ExpensifyIntegrations"
$expensify_id = "REMOVED"
$expensify_secret = "REMOVED"
$dept = "IT"
if ($dept -eq "FP&A" -or $dept -eq "IT") {
$expensify_admin = "TRUE"
} else {
$expensify_admin = "FALSE"
}
$email = "[email protected]"
$mngr_email = "[email protected]"
$fwd_email = "[email protected]"
$expensify_csv = @(
[pscustomobject]@{
EmployeeEmail = $email
ManagerEmail = $mngr_email
Admin = $expensify_admin
ForwardManagerEmail = $fwd_email
}
)
$expensify_csv | Export-Csv -Path C:\expensify.csv -NoTypeInformation
$upload = Get-Item -Path C:\expensify.csv
$csv = "EmployeeEmail,ManagerEmail,Admin,ForwardManagerEmail`r`[email protected],[email protected],TRUE,[email protected]`r`n"
Write-Host $csv
$json = [ordered]@{
"requestJobDescription" = @{
"type" = "update";
"credentials" = @{
"partnerUserID" = $expensify_id;
"partnerUserSecret" = $expensify_secret;
}
"inputSettings" = @{
"type" = "employees";
"policyID" = "REMOVED";
"fileType" = "csv";
}
};
"data" = Get-Content($upload) -Raw
} | ConvertTo-Json -Depth 5
Write-Host $json
$check = Invoke-WebRequest `
-Method Post `
-Uri $expensify_url `
-Body $json `
-ContentType multipart/form-data
Write-Host $check
exit
-
Thanks a bunch for following up here with your solution, @derekritchison!