0

I am trying to consumer item level REST API for VSTS. Below is the code I am using,

const headerDict = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Allow-Headers': 'Content-Type',
'Authorization': 'TOKEN'
}

const requestOptions = {
headers: new Headers(headerDict),
};
// use token to get repos
var repoPromise = $http({
method: "GET",
url: "{account}.visualstudio.com/DefaultCollection/{Repository}/_apis/git/repositories/{Project}/items?api-version=1.0&scopePath=/src&recursionLevel=Full&includeContentMetadata=true&api-version=1.0"
});

repoPromise
.success(function (payload) {
    $scope.repos = payload;
})
.error(function () {
    alert("No Data");
    // Should display some sort of error, or notify via email
});

Error in payload variable

"

        Visual Studio Team Services | Sign In

<link data-bundlelength="429694" data-bundlename="commoncss" data-highcontrast="/_static/tfs/20180717T222723/_cssbundles/HighContrast/vss-bundle-commoncss-vdwT_y4rJPrx1EvfBKuardD9WZfa_S2Fgu6fzmWqzy7I=" data-includedstyles="jQueryUI-Modified;Core;Splitter;PivotView" href="/_static/tfs/20180717T222723/_cssbundles/Default/vss-bundle-commoncss-vA_iLS2BjrujGcPg4oPm14Y4M6Y9Nv3iBASCZ4Eu1k80=" rel="stylesheet" />

<!--UxServices customizations -->

<link href="/_static/tfs/20180717T222723/_content/Authentication.css" type="text/css" rel="stylesheet" />

<script type="text/javascript"> var __vssPageContext = {"webContext":{"user":{"id":"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa","name":"Anonymous","email":"","uniqueName":"TEAM FOUNDATION\\Anonymous"},"host":{"id":"a5ca35eb-148e-4ccd-bbb3-d31576d75958","name":"TEAM FOUNDATION","uri":"https://app.vssps.visualstudio.com/","relativeUri":"/","hostType":"deployment","scheme":"https","authority":"app.vssps.visualstudio.com"}},"moduleLoaderConfig":{"baseUrl":"/_static/tfs/20180717T222723/_scripts/TFS/min/","paths":{"UserManagement/Scripts/Resources":"en-US","VSS/Resources":"en-US","Profile/Scripts/Resources":"en-US","Account/Scripts/Resources":"en-US","Authentication/Scripts/Resources":"en-US"},"map":{},"contributionPaths":{"VSS":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/VSS","pathType":"default"},"VSS/Resources":{"value":"en-US","pathType":"resource"},"q":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/q","pathType":"default"},"knockout":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/knockout","pathType":"default"},"mousetrap":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/mousetrap","pathType":"default"},"mustache":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/mustache","pathType":"default"},"react":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/react.15.3","pathType":"default"},"react-dom":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/react-dom.15.3","pathType":"default"},"react-transition-group":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/react-transition-group.15.3","pathType":"default"},"jQueryUI":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/jQueryUI","pathType":"default"},"jquery":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/jquery","pathType":"default"},"OfficeFabric":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/OfficeFabric","pathType":"default"},"@uifabric":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/@uifabric","pathType":"default"},"VSSUI":{"value":"/_static/tfs/20180717T222723/_scripts/TFS/min/VSSUI","pathType":"default"}},"shim":{"jquery":{"deps":[],"exports":"jQuery"}},"waitSeconds":30},"coreReferences":{"stylesheets":[{"url":"/_static/tfs/20180717T222723/_cssbundles/Default/vss-bundle-ext-core-css-vA_iLS2BjrujGcPg4oPm14Y4M6Y9Nv3iBASCZ4Eu1k80=","highContrastUrl":null,"isCoreStylesheet":true}],"scripts":[{"identifier":"JQuery","url":"/_static/3rdParty/_scripts/jquery-2.1.1.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"JQueryXDomain","url":"/_static/3rdParty/_scripts/jquery.xdomainrequest.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"Promise","url":"/_static/tfs/20180717T222723/_scripts/TFS/min/promise.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"LoaderFixes","url":"/_static/tfs/20180717T222723/_scripts/TFS/pre-loader-shim.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":false},{"identifier":"AMDLoader","url":"/_static/3rdParty/_scripts/require.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"LoaderFixes","url":"/_static/tfs/20180717T222723/_scripts/TFS/post-loader-shim.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":false}],"coreScriptsBundle":{"identifier":"CoreBundle","url":"/_public/_Bundling/Content?bundle=vss-bundle-basejs-vI1IxAQ10AVWwEoAF6E9t0idR3ZSaZnasnpanuPQzGJ0=","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},"extensionCoreReferences":{"identifier":"CoreBundle","url":"/_public/_Bundling/Content?bundle=vss-bundle-ext-core-v8yVCNgrkJUM2YVbhKUwiOsIG8Wf-U30prsNBUIjUO4Y=","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true}},"webAccessConfiguration":{"isHosted":true,"paths":{"rootPath":"/","staticContentRootPath":"/","staticContentVersion":"20180717T222723","resourcesPath":"/_static/tfs/20180717T222723/_content/","staticRootTfs":"/_static/tfs/20180717T222723/","cdnFallbackStaticRootTfs":"/_static/tfs/20180717T222723/","staticRoot3rdParty":"/_static/3rdParty/"},"api":{"webApiVersion":"1","areaPrefix":"_","controllerPrefix":""},"mailSettings":{"enabled":false}},"microsoftAjaxConfig":{"cultureInfo":{"name":"en-US","numberFormat":{"CurrencyDecimalDigits":2,"CurrencyDecimalSeparator":".","IsReadOnly":true,"CurrencyGroupSizes":[3],"NumberGroupSizes":[3],"PercentGroupSizes":[3],"CurrencyGroupSeparator":",","CurrencySymbol":"$","NaNSymbol":"NaN","CurrencyNegativePattern":0,"NumberNegativePattern":1,"PercentPositivePattern":0,"PercentNegativePattern":0,"NegativeInfinitySymbol":"-∞","NegativeSign":"-","NumberDecimalDigits":2,"NumberDecimalSeparator":".","NumberGroupSeparator":",","CurrencyPositivePattern":0,"PositiveInfinitySymbol":"∞","PositiveSign":"+","PercentDecimalDigits":2,"PercentDecimalSeparator":".","PercentGroupSeparator":",","PercentSymbol":"%","PerMilleSymbol":"‰","NativeDigits":["0","1","2","3","4","5","6","7","8","9"],"DigitSubstitution":1},"dateTimeFormat":{"AMDesignator":"AM","Calendar":{"MinSupportedDateTime":"0001-01-01T00:00:00","MaxSupportedDateTime":"9999-12-31T23:59:59.9999999","AlgorithmType":1,"CalendarType":1,"Eras":[1],"TwoDigitYearMax":2029,"IsReadOnly":true},"DateSeparator":"/","FirstDayOfWeek":0,"CalendarWeekRule":0,"FullDateTimePattern":"dddd, MMMM d, yyyy h:mm:ss tt","LongDatePattern":"dddd, MMMM d, yyyy","LongTimePattern":"h:mm:ss tt","MonthDayPattern":"MMMM d","PMDesignator":"PM","RFC1123Pattern":"ddd, dd MMM yyyy HH':'mm':'ss 'GMT'","ShortDatePattern":"M/d/yyyy","ShortTimePattern":"h:mm tt","SortableDateTimePattern":"yyyy'-'MM'-'dd'T'HH':'mm':'ss","TimeSeparator":":","UniversalSortableDateTimePattern":"yyyy'-'MM'-'dd HH':'mm':'ss'Z'","YearMonthPattern":"MMMM yyyy","AbbreviatedDayNames":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"ShortestDayNames":["Su","Mo","Tu","We","Th","Fr","Sa"],"DayNames":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"AbbreviatedMonthNames":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",""],"MonthNames":["January","February","March","April","May","June","July","August","September","October","November","December",""],"IsReadOnly":true,"NativeCalendarName":"Gregorian Calendar","AbbreviatedMonthGenitiveNames":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",""],"MonthGenitiveNames":["January","February","March","April","May","June","July","August","September","October","November","December",""]},"numberShortForm":{"QuantitySymbols":["K","M","B"],"NumberGroupSize":1000,"ThousandSymbol":"K"},"eras":null}},"timeZonesConfiguration":{},"featureAvailability":{"featureStates":{"VisualStudio.Services.Contribution.EnableOnPremUnsecureBrowsers":false,"VisualStudio.Service.WebPlatform.ClientErrorReporting":false,"Microsoft.VisualStudio.Services.Gallery.Client.UseCdnAssetUri":false,"VisualStudio.Services.ExtensionManagement.QueryContributionNodes":true,"VisualStudio.Services.WebAccess.SubresourceIntegrity":false,"VisualStudio.Services.IdentityPicker.ReactProfileCard":true}},"appInsightsConfiguration":{"enabled":false,"instrumentationKey":"00000000-0000-0000-0000-000000000000","insightsScriptUrl":null},"diagnostics":{"sessionId":"3c1ede01-1940-4d24-819f-b45098e4a399","activityId":"3c1ede01-1940-4d24-819f-b45098e4a399","bundlingEnabled":true,"webPlatformVersion":"M137"},"navigation":{"topMostLevel":"deployment","area":"","currentController":"Signin","currentAction":"Index","routeId":"LegacyWebAccessRoute","routeValues":{"controller":"Signin","action":"Index"}},"globalization":{"explicitTheme":"","theme":"Default","culture":"en-US","timezoneOffset":0,"timeZoneId":"UTC"},"serviceInstanceId":"951917ac-a960-4999-8464-e3f0aa25b381","hubsContext":{},"serviceLocations":{"locations":{"951917ac-a960-4999-8464-e3f0aa25b381":{"Application":"https://app.vssps.visualstudio.com/","Deployment":"https://app.vssps.visualstudio.com/"}}}};</script><script type="text/javascript"> var __cultureInfo = __vssPageContext.microsoftAjaxConfig.cultureInfo;</script>
if (window.performance && window.performance.mark) { window.performance.mark('startLoadBundleOuter-basejs'); } if (window.performance && window.performance.mark) { window.performance.mark('endLoadBundleOuter-basejs'); } require.config(__vssPageContext.moduleLoaderConfig);
<input name="__RequestVerificationToken" type="hidden" value="000hygqafWwecRcK8Kn1BpliFMKR184hSyqvTStwI70rYAM-UqxK51moCbVaTg01Jr8j-PEgrHNYKqR05_4mIYh6tPM1" /><input name="__RequestVerificationToken2" type="hidden" value="__RequestVerificationToken24e01d3bd-fd2e-4d32-8f81-dc4501e64a7c" />






<div class="account signin main-container hide">


        <div class="page-content">
            <div class="header-section" role="banner">


            </div>
            <div class="content-section" role="main">


        <div class="signin-main-content">
            <noscript>
                <span class="error">Microsoft Internet Explorer&#39;s Enhanced Security Configuration is currently enabled on your environment. This enhanced level of security prevents our web integration experiences from displaying or performing correctly. To continue with your operation please disable this configuration or contact your administrator.</span>
            </noscript>
            <div class="provider-control">                    
                <script class="options" defer="defer" type="application/json">{"providerOptions":{"force":false,"orgIdAuthUrl":"https://login.microsoftonline.com/9516b679-4458-4fde-9b67-3b7e4ecd2d2d/oauth2/authorize?client_id=499b84ac-1321-427f-aa17-267ca6975798\u0026site_id=501454\u0026response_mode=form_post\u0026response_type=code+id_token\u0026redirect_uri=https%3A%2F%2Fapp.vssps.visualstudio.com%2F_signedin\u0026nonce=27d0f9bf-9f64-4894-b2c6-719be66bb846\u0026state=realm%3D{account}.visualstudio.com%26reply_to%3Dhttps%253A%252F%252F{account}.visualstudio.com%252F_apis%252Fgit%252Frepositories%253Fapi-version%253D1.0%26ht%3D2%26nonce%3D27d0f9bf-9f64-4894-b2c6-719be66bb846\u0026resource=https%3A%2F%2Fmanagement.core.windows.net%2F\u0026cid=27d0f9bf-9f64-4894-b2c6-719be66bb846\u0026wsucxt=1","user":null,"signInContext":"eyJodCI6MiwiaGlkIjoiZGEwM2VhN2ItMDcwOC00MTJjLWExMzctMGZiZTQyNGY4MjI3IiwicXMiOnsicmVhbG0iOiJhcHByaXNzcmV0YWlsLnZpc3VhbHN0dWRpby5jb20iLCJyZXBseV90byI6Imh0dHBzOi8vYXBwcmlzc3JldGFpbC52aXN1YWxzdHVkaW8uY29tL19hcGlzL2dpdC9yZXBvc2l0b3JpZXM_YXBpLXZlcnNpb249MS4wIiwiaHQiOiIyIiwibm9uY2UiOiIyN2QwZjliZi05ZjY0LTQ4OTQtYjJjNi03MTliZTY2YmI4NDYifSwicnIiOiIiLCJ2aCI6IiIsImN2IjoiIiwiY3MiOiIifQ2"}}</script>
            </div>
        </div>


            </div>

                 <div>

                 </div>

        </div>


</div>





<script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('startLoadBundleOuter-common'); }</script>
if (window.performance && window.performance.mark) { window.performance.mark('endLoadBundleOuter-common'); } if (window.performance && window.performance.mark) { window.performance.mark('startLoadBundleOuter-view'); } if (window.performance && window.performance.mark) { window.performance.mark('endLoadBundleOuter-view'); } if (window.performance && window.performance.mark) { window.performance.mark('requireStart'); } require(["Authentication/Scripts/SPS.Authentication.Controls","Authentication/Scripts/SPS.Authentication"], function(){ if (window.performance && window.performance.mark) { window.performance.mark('requireEnd'); } window.requiredModulesLoaded=true; });

I am unable to get a response. Am I constructing the request wrong? OR is there anything wrong with the code?

Community
  • 1
  • 1
tRuEsAtM
  • 3,517
  • 6
  • 43
  • 83

1 Answers1

1

The reason is that the authentication is failed, so it redirects to the login page, that's why you get the 302 response code.

Just try to add Authorization to header like below format, then check if that works:

const headerDict = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Allow-Headers': 'Content-Type',
"Authorization": "Bearer " + accessToken
}

More information about the Authorization please see Choosing the right authentication mechanism.

And this related thread for your reference: Access TFS and visualstudio online REST Api in Electron/angularjs app

Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55