Application JSON error

Jun 6, 2013 at 6:40 AM
When I ran the tfs drop downloader an exception was thrown "Unsupported Content Type"
The Request Uri was :
https://MYACCOUNT.visualstudio.com/DefaultCollection/_apis/resources/containers/15/drop/MYBUILDNUMBER.zip

Am I doing something wrong here ?
Developer
Jun 6, 2013 at 10:05 PM
Edited Jun 6, 2013 at 10:07 PM
Hi,

Do you mean you passed "https://MYACCOUNT.visualstudio.com/DefaultCollection/_apis/resources/containers/15/drop/MYBUILDNUMBER.zip" as value of collectionUri parameter ?

The TfsDropDownloader is not meant to download any random file from TFS server, it only downloads the drop produced by your build.

If you type TfsDropDownloader.exe /? from a CMD window, you can see a detailed usage information.

In your case, the collectionUri should be https://MYACCOUNT.visualstudio.com/DefaultCollection, and you need to specify other parameters like team project name, build definition name etc.

If this does not resolve your issue, please let us know.

Paste the help information from the command line tool for convenience:

Download a build drop published to the TFS server.

Usage:
TFSDropDownloader.exe /c:<collectionUrl> /t:<teamProject> /b:<buildDefinition>
/u:<username> /p:<password> [/n:buildNumber] [/o:outputFile] [/?]

Options:
/c The TFS project collection URL.

/t TFS team project name.

/b Build definition name.

/u TFS account user name.

/p TFS account password.

[/n] The build number of the target drop.
    If not specified, latest good drop will be downloaded.
[/o] Full file path to save the downloaded drop, e.g. C:\MyDrops\Foo.zip
    If not specified, the drop will be saved in the current working directory.
[/?] Display this message.

Thanks
Yanchen
Jun 12, 2013 at 9:03 AM
Hi Yanchen,

I get a similar error to melvinvermeer. Using the command line tool I do this:
TfsDropDownloader.exe /c:"https://MYPROJECTNAME.visualstudio.com/DefaultCollection" /t:"ProjectName" /b:"BuildDefinitionName" /u:username /p:password
...and get an empty zip file with the correct build label name of the last successful build e.g. BuildDefinitionName_20130611.1.zip

Running the source code in the debugger, this is because the URL that is generated for downloading:
https://tflonline.visualstudio.com/DefaultCollection/_apis/resources/containers/804/drop/BuildDefinitionName_20130611.1.zip
..returns a content type of application/json, which is unsupported. This exception is swallowed by the application, but not before the empty zip file is created.

Is it possible the REST API on Team Foundation Service has changed in some way so the generated URL is no longer correct?

Note that I am using the "alternate credentials" defined on my Team Foundation Service account (i.e. not my live ID) - using anything else gets me TF30063: not authorized.

Thanks

Tim
Developer
Jun 12, 2013 at 4:44 PM
Edited Jun 12, 2013 at 4:45 PM
Hi Tim,

Using the alternate credentials should be fine to download the drop.

I encountered the same issue when I created this tool, it is usually because the authentication failed.
At that time, the root cause for my problem is because my password contains a special character which needs to be escaped in command line window. I changed my password and it worked.

Is it by any chance you also have special characters in your password?

If this does not resolve the issue, can you paste the json message so we can see what the message is ?

Thanks
Yanchen
Jun 13, 2013 at 10:52 AM
Hi Yanchen,

I got it working by using alternate credentials, but I also had to access the REST API via a different path.

The current utility builds a URL that looks like this:
https://project.visualstudio.com/DefaultCollection/_apis/resources/containers/804/drop/BuildDefinitionName_20130611.1.zip
This returns empty JSON whenever I try to use it. I'm definitely authenticated, because if I tweak the URL to:
https://project.visualstudio.com/DefaultCollection/_apis/resources/containers/804/drop
I get a nice JSON listing of every single file in the drop, but no zip.

From spying on the SSL traffic to https://tfs.visualstudio.com with Fiddler I saw that clicking the "Download drop as zip" link I can see that there is another endpoint at:
https://project.visualstudio.com/DefaultCollection/ProjectName/_api/_build/ItemContent?buildUri=vstfs%3a%2f%2f%2fBuild%2fBuild%2f639&path=%2Fdrop
...which does give you a zip. The "vstfs%3a%2f%2f%2fBuild%2fBuild%2f639" portion is the URL encoded BuildUri.

So I've changed my version of GetServerPath to do this:
private static string GetServerPath(TfsConnection collection, IBuildDetail buildDetail)
{
    var downloadPath = string.Format("{0}{1}/_api/_build/ItemContent?buildUri={2}&path=%2Fdrop",
                                            collection.Uri, 
                                            HttpUtility.UrlPathEncode(buildDetail.TeamProject), 
                                            HttpUtility.UrlEncode(buildDetail.Uri.ToString()));

    return downloadPath;
}
This works for me for the time being. It's a bit concerning how the REST API is undocumented though. Are you sure your command line tool still works against the API since 30 May? I cannot get it to work, and reading the bottom of this forum post there may have been some changes to how drops are stored.

Thanks

Tim
Developer
Jun 19, 2013 at 8:19 PM
Hi Tim,

We've identified that the TFS online update indeed broke this tool.
We're in the progress of fixing this issue.
Should be able to update the tool sometime next week.

Tim, thank you for reporting the issue!

Regards,
Yanchen