I have a process to interact with an API and write the data to a SQL table. Hitting the two endpoints separately and getting the data is no issue. I am stuck now on how to combine them so I can make one write to SQL as the loop processes. Endpoint #1 gets me all the data “/api/v1/employee/$($.eecode)" . I need to hit Endpoint #2 "/api/v1/employee/$($.eecode)/customfield”
with the same eecode from the first call. I want to keep them in the same object so I can write the row to SQL with data from both endpoints. I had to remove some code since the API for the system I am interacting with isn’t public.
Sam, I never would have thought of putting the call in the expression for ADID. I added CustomText04.value and by itself, it returns the value I would need. Now I am getting an error when the second call is being made and selecting the $params.
<!–StartFragment –>
Error:
<!--StartFragment -->
… -apiEndpoint "/api/v1/employee/$($_.eecode)" | Select-Object $params
| ~~~~~~~~~~~~~~~~~~~~~
| The "expression" key cannot have an empty string value.
Thanks! That helped out getting rid of that error. My text file I write out is still blank for the ADID. Running the expression by itself and getting the value of the custom field gets me what I want.
I can also grab the value directly and be left with a string.
If I load the expression into my shell. The array looks as if it isn’t executing the command?
PS C:\Users\E011891> $params
firstname
middlename
lastname
Name Value
---- -----
e (Connect-Api -apiEndpoint "/api/v1/employee/1891/customfield").CustomText04.value
n ADID
hire_date
I have the expression fixed with the extra {} to clear my error. When I take out the variable and hard code an employee code it will execute and stick the value into the $params array.
However, when I have the variable in the execution it comes out blank in my text file. I know the variable evaluates correctly as I can write the foreach-object and get all the values in my shell.
I updated the code with my final result. I refactored a bit, but have the result I need now to make the SQL table write. Thx for your input. It helped out a lot.