Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

9
Trouble with REST API Call
Post Flair (click to view more posts with a particular flair)
Post Body

I am brand new to PowerShell, but I can already tell it will be a powerful tool and worth my time to learn. Unfortunately I am also new to using web API's, so this has been a tough project for me. After many hours of searching, I am waving the white flag and asking for help.

I am trying to download a CSV from Teamwork Projects that shows time entries. Here is what I have so far:

$pair = "username:pass"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$headers = @{ Authorization = $basicAuthValue }

$resource = "https://[myURL].teamwork.com/time_entries.json"

$json = Invoke-RestMethod -Uri $resource -Method Get -Headers $headers 

$json

Up until this point, everything works. I get a response that looks right. However, when I try to export to CSV or parse it to something useful, I either get failures or just the "Status" header record.

Adding this gives me a CSV with the status information:

$json | Export-csv -delimiter ',' -Path C:\Test.csv 

I emailed support and this is what they told me:

It looks like you're connecting to the API and getting an OK status response. You should also be getting your time entries in the time-entries object.

I checked your account and there are time entries there so it should be fine.

It seems like you're parsing the 'status' object and getting its value of 'ok', are you parsing the 'time_entries' object too?

I don't know how to specify which object to parse. I have tried several variations of ConvertFrom-JSON and I always get an error about "invalid json primitive" which I suspect is because it is receiving two objects instead of the expected one.

Here is the product specific API info

Any suggestions would be much appreciated!

Author
Account Strength
100%
Account Age
13 years
Verified Email
Yes
Verified Flair
No
Total Karma
46,076
Link Karma
3,043
Comment Karma
42,944
Profile updated: 1 week ago
Posts updated: 8 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
8 years ago