Skip to content

Instantly share code, notes, and snippets.

@apucacao
Last active March 3, 2016 19:02
Show Gist options
  • Save apucacao/0842c03771018d3ee506 to your computer and use it in GitHub Desktop.
Save apucacao/0842c03771018d3ee506 to your computer and use it in GitHub Desktop.
POST /DefaultCollection/ee82e73e-0f24-4f32-8b17-e02ce99adce8/_apis/distributedtask/serviceendpointproxy HTTP/1.1
Host: launchdarkly.visualstudio.com
Connection: keep-alive
Content-Length: 78
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Im9PdmN6NU1fN3AtSGpJS2xGWHo5M3VfVjBabyJ9.eyJuYW1laWQiOiJlMmE2ZTE0MC03NGQyLTQyMDktYTNkNy03MzRjNjM0MjdiOTAiLCJzY3AiOiJ2c28uZXh0ZW5zaW9uLmRlZmF1bHQgdnNvLnByb2ZpbGUgdnNvLnNlcnZpY2VlbmRwb2ludF9xdWVyeSB2c28ud29yayIsImF1aSI6IjdiZTk0NTE4LTEwNTMtNDMyYS1hODNmLTY2YmFhZDg4N2E3YiIsImhhaSI6IjFjNjA2NjU4LTFlZWItNGMwNS1iNjUzLWE3NDA1OWU2YTMyMiIsInNpZCI6ImNhZTJkYjRkLWNjNTAtNDhiOC1iYzJlLWJmZGUxNDg2MmQ2MSIsImlzcyI6ImFwcC52c3Nwcy52aXN1YWxzdHVkaW8uY29tIiwiYXVkIjoiYXBwLnZzc3BzLnZpc3VhbHN0dWRpby5jb218dnNvOjQ2M2E3ZDcyLWM5MmUtNGJiNi05NTViLWNkN2UwMzk5YTcxMSIsIm5iZiI6MTQ1NzAzMDk5MSwiZXhwIjoxNDU3MDM0NTkwfQ.toSXzLP8P_vHfDWRIu_v8zTukf2yejxktQ-XBcTqNI9e_NQYOBmUGaY0ue9W8SBlQRikKt50vN42ikiG-vH3nTRITNs-CgOALVl9YSj5Evl4lMurcVEZ5E_8JqeO8weSIDqcTHAZne15LURYi985J6oSQXqvdFnVU0BiMEM1jgFQZEBOphYA_Pe04CMnjS3MLH1b9gClOdaMcAhldVKkNZLWspa_LCLWJO3o8uXVIVrOt3SZ7lppdU-fpCg6w7nSvkgpGz31NLujls5Yj-gBZSWmjNFqQzzzyGpzf220awaJRyj-ZvpejQekmDWB5_VhYBmIVpHv0ZMM_YMiDYowQg
X-TFS-FedAuthRedirect: Suppress
Origin: https://ld-vsts.herokuapp.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36
Content-Type: application/json
Accept: application/json;api-version=2.2-preview.1
Referer: https://ld-vsts.herokuapp.com/static/workItemPage.html
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,da;q=0.6
{
"name": "TFS.WebApi.Exception",
"status": 400,
"responseText": "{\"$id\":\"1\",\"innerException\":null,\"message\":\"Failed to query service endpoint api: https://app.launchdarkly.com/api/features\",\"typeName\":\"Microsoft.TeamFoundation.DistributedTask.WebApi.ServiceEndpointQueryFailedException, Microsoft.TeamFoundation.DistributedTask.WebApi, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\",\"typeKey\":\"ServiceEndpointQueryFailedException\",\"errorCode\":0,\"eventId\":3000}",
"serverError": {
"$id": "1",
"innerException": null,
"message": "Failed to query service endpoint api: https://app.launchdarkly.com/api/features",
"typeName": "Microsoft.TeamFoundation.DistributedTask.WebApi.ServiceEndpointQueryFailedException, Microsoft.TeamFoundation.DistributedTask.WebApi, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"typeKey": "ServiceEndpointQueryFailedException",
"errorCode": 0,
"eventId": 3000
}
}
{
"manifestVersion": 1,
"id": "launchdarkly-extension",
"version": "0.2.8",
"name": "LaunchDarkly VSTS Extension",
"description": "LaunchDarkly Visual Studio Team Services extension",
"publisher": "launchdarkly",
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"icons": {
"default": "static/images/launchdarkly_hd_whitebg.jpg"
},
"categories": [
"Build and release"
],
"contributions": [
{
"id": "LaunchDarkly.HelloWorld",
"type": "ms.vss-web.hub",
"description": "Adds a 'Hello' hub to the Work hub group.",
"targets": [
"ms.vss-work-web.work-hub-group"
],
"properties": {
"name": "Hello",
"order": 99,
"uri": "static/hello-world.html"
}
},
{
"id": "LaunchDarkly.WorkItemPage",
"type": "ms.vss-work-web.work-item-form-page",
"description": "LaunchDarkly Work Item Page",
"targets": [
"ms.vss-work-web.work-item-form"
],
"properties": {
"name": "LaunchDarkly",
"uri": "static/workItemPage.html"
}
},
{
"id": "LaunchDarkly.Endpoint",
"description": "LaunchDarkly provides feature flags as a service.",
"type": "ms.vss-endpoint.service-endpoint-type",
"targets": [
"ms.vss-endpoint.endpoint-types"
],
"properties": {
"name": "launchdarkly",
"displayName": "LaunchDarkly",
"url": "https://app.launchdarkly.com/api",
"inputDescriptors": [],
"authenticationSchemes": [
{
"type": "ms.vss-endpoint.endpoint-auth-scheme-token",
"inputDescriptors": [
{
"id": "apitoken",
"name": "API Key",
"description": "API key for connection to LaunchDarkly",
"inputMode": "textbox",
"isConfidential": false,
"validation": {
"isRequired": true,
"dataType": "string"
}
}
],
"headers": [
{
"name": "Authentication",
"value": "api_key {{endpoint.apitoken}}"
}
]
}
],
"dataSources": [
{
"name": "Flags",
"endpointUrl": "https://app.launchdarkly.com/api/features",
"resultSelector": "jsonpath:$.items"
}
]
}
}
],
"scopes": [
"vso.profile",
"vso.serviceendpoint_query",
"vso.work"
],
"baseUri": "https://ld-vsts.herokuapp.com"
}
VSS.require([
"TFS/DistributedTask/TaskAgentRestClient",
"TFS/WorkItemTracking/Services"
], function (RestClient, _WorkItemServices) {
// Get the WorkItemFormService. This service allows you to get/set fields/links on the 'active' work item (the work item
// that currently is displayed in the UI).
function getWorkItemFormService() {
return _WorkItemServices.WorkItemFormService.getService();
}
var webContext = VSS.getWebContext();
var client = RestClient.getClient();
// Find LD service endpoint (which defines which resources we can query)
client.getServiceEndpoints(webContext.project.id).then(
function(endpoints) {
// There should only be one registered LD service endpoint
var ld = endpoints.filter(function(endpoint) {
return endpoint.type === 'launchdarkly';
})[0];
if (!ld) {
console.error('Could not find LaunchDarkly service endpoint.');
return;
}
console.log('LaunchDarkly endpoint:', ld);
// Call LD via the service endpoint (auth header is automatically set)
client.queryServiceEndpoint({
dataSourceName: 'Flags',
endpointId: ld.id
}, webContext.project.id).then(
function(res) {
console.log(res);
},
function(error) {
console.error(error);
}
);
},
function(error) {
console.error(error);
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment