I am trying to access the service endpoint setup in my extension code.
The extension is as follows:
{
"manifestVersion": 1,
"id": "vsts-extensions-myExtensions",
"version": "0.5.1",
"name": "xxx Projects Time Entry",
"description": "Record time spent in xxx Projects",
"publisher": "xxx",
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"icons": {
"default": "img/logo.png"
},
"contributions":
[
{
"id": "xxTimeEntry",
"type": "ms.vss-dashboards-web.widget",
...
},
{
"id": "service-endpoint",
"description": "Service Endpoint type for xx connections",
"type": "ms.vss-endpoint.service-endpoint-type",
"targets": [ "ms.vss-endpoint.endpoint-types" ],
"properties": {
"name": "xxxyyy",
"displayName": "xx server connection",
"url": {
"displayName": "Server Url",
"helpText": "Url for the xxx server to connect to."
},
"dataSources": [
{
"name": "xxx Projects",
"endpointUrl": "{{endpoint.url}}api/timesheetwidgetprojects",
"resultSelector": "jsonpath:$[*].nm"
}
],
"authenticationSchemes": [
{
"type": "ms.vss-endpoint.endpoint-auth-scheme-basic",
"inputDescriptors": [
{
"id": "username",
"name": "Username",
"description": "Username",
"inputMode": "textbox",
"validation": {
"isRequired": false,
"dataType": "string"
}
},
{
"id": "password",
"name": "Password",
"description": "Password",
"inputMode": "passwordbox",
"isConfidential": true,
"validation": {
"isRequired": false,
"dataType": "string"
}
}
]
}
]
}
}
],
...
The code to access the service endpoint is something like :
VSS.require(["VSS/Service", "VSS/WebApi/RestClient"],
function (VSS_Service, RestClient) {
var webContext = VSS.getWebContext();
var client = VSS_Service.getCollectionClient(DistributedTask.TaskAgentRestClient);
client.getServiceEndpoints(webContext.project.id).then(
function (endpoints) {
alert('endpoints')
}
);
}
);
however I am not using a task and just have my endpoint in the main vss-extension.json.
Any ideas?
Thanks
Martin
Based on the supported scopes, there isn’t the scope for service endpoint, so you can’t do it.
I submit a user voice here: VSTS extension service endpoint scope, you can vote and follow up.
The workaround is that you can call REST API by using JS code with Personal Access Token in your extension.
Simple code to call REST API:
$.ajax({
url: 'https://fabrikam.visualstudio.com/defaultcollection/_apis/projects?api-version=1.0',
dataType: 'json',
headers: {
'Authorization': 'Basic ' + btoa("" + ":" + myPatToken)
}
}).done(function( results ) {
console.log( results.value[0].id + " " + results.value[0].name );
});
The scope has been added now and it is "vso.serviceendpoint"
Related
I met an issue when I call the create issue API in my code, the error is It is not on the appropriate screen, or unknown.' But when trying the test API with the same parameters in postman, it succeeds, is there anyone who knows the reason for this error?
This is my code:
create_url = "https://myjira/rest/api/2/issue/"
jira_hash =
{
"fields": {
"project": {
"id": "51606"
},
"issuetype": {
"name": "SOAK EVENT"
},
"priority": {
"name": "Critical"
},
"labels": ["Chandler"],
"customfield_10012": {
"id": "10006"
},
"fixVersions": [{
"name": "2019-05-r1"
}],
"summary": "10297",
"description": "description"
}
}
HTTParty.post(create_url,
:body => jira_hash.to_json,
:headers => {'Content-Type' => 'application/json', 'Authorization'
=> auth})
I'm develop an chrome extension for jira which get a data from a DIV element of another website and use the data to raise a jira ticket by my chrome extension automatically.
the issue is when I call below jira api in my code I faced below error
content.js:107 POST http://myjira.com:9090/rest/api/2/issue/ 403 (Forbidden)
but as I checked my request in Post Man app everything is fine and new ticket raise in Jira.
I'm really appreciated if someone can help me to fix the issue.
moreover, I used my personal computer and the jira is on another server.
totally I want to have a extension to integrate a ticketing system with jira, without access to that site.
please have following code.
content.js
$(document).ready(function () {
var key = '';
var summary = 'undefined';
var description = '';
var comment = '';
window.setInterval(function () {
/// call your function here
console.log($('Div1').html());
console.log($('Div2').html());
console.log($('#Div3').html());
console.log($('Div4').html());
key = $('.a span:first').html();
summary = $('#b').html();
description = $('#r'')').html();
comment = $('#u').html();
if (summary == 'undefined') {
return;
}
var data = JSON.stringify({
"fields": {
"project": {
"key": "RTF"
},
"summary": "" + summary + "",
"description": "" + description + "",
"issuetype": {
"self": "http://myjira.com/rest/api/2/issuetype/10111",
"id": "10111",
"description": "Service Request",
"iconUrl": "http:/myjira.com/secure/viewavatar?size=xsmall&avatarId=10720&avatarType=issuetype",
"name": "MS Task (SR)",
"subtask": false,
"avatarId": 10720
},
"customfield_10106": {
"self": "http://myjira.com/rest/api/2/customFieldOption/10476",
"value": "EMAIL",
"id": "10476"
},
"customfield_10129": [
{
"self": "http://myjira.com/rest/api/2/customFieldOption/10450",
"value": "TEST",
"id": "10450"
}
],
"customfield_10188": [
{
"self": "http://myjira.com/rest/api/2/customFieldOption/10469",
"value": "Billing",
"id": "10469"
}
],
"customfield_10180": {
"self": "http://myjira.com/rest/api/2/customFieldOption/11000",
"value": "Support",
"id": "11000"
},
"assignee": {
"self": "http://myjira.com/rest/api/2/user?username=e.pirjahandideh",
"name": "e.jj",
"key": "e.jj",
"emailAddress": "e.jj#jj.com",
"avatarUrls": {
"48x48": "http://www.gravatar.com/avatar/68e54d1c135e85b994eb12cb9a3b7b9b?d=mm&s=48",
"24x24": "http://www.gravatar.com/avatar/68e54d1c135e85b994eb12cb9a3b7b9b?d=mm&s=24",
"16x16": "http://www.gravatar.com/avatar/68e54d1c135e85b994eb12cb9a3b7b9b?d=mm&s=16",
"32x32": "http://www.gravatar.com/avatar/68e54d1c135e85b994eb12cb9a3b7b9b?d=mm&s=32"
},
"displayName": "Emil jj",
"active": true,
"timeZone": "Asia/Tehran"
},
"components": [
{
"self": "http://myjira.com/rest/api/2/component/10071",
"id": "10071",
"name": "RR",
"description": "Managed RR"
}
],
"customfield_10189": {
"self": "http://myjira.com/rest/api/2/customFieldOption/10489",
"value": "RR/IT",
"id": "10489"
}
}
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "myjira.com/rest/api/2/issue/");
xhr.setRequestHeader("authorization", "Basic dasfasegsdfgsdfgsdfg");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.setRequestHeader("postman-token", "c6475a5e-6741-6894-5b8e-2350c7c5a176");
xhr.send(data);
}, 10000);
});
manifest.json
{
"manifest_version": 2,
"name": "Name",
"description": "Description",
"browser_action": {
"default_popup": "popup.html"
},
"background": {
"page": "background.html"
},
"version": "1.0",
"permissions": [
"http://myjira.com/",
"http://ticketing2.com"
],
"content_scripts": [
{
"matches": [ "http://*/*", "https://*/*"],
"js": [
"jquery.js",
"jquery-ui.min.js",
"content.js"
],
"run_at": "document_end",
"all_frames": true
}
]
}
So far I'm able to do swagger validation if the parameters are from "in": "body" or if the input expected is in a json format.
However, I can't find how to validate a simple string entered as formData.
Below is my swagger script (in json format)
v1swag = {
"cancels_post": {
"tags": ["/api/v1"],
"parameters": [
{
"name": "token",
"in": "formData",
"type": "string",
"required": True,
"description": "Cancels the provided token.",
}
],
"responses": {
"200": {
"description": "Success!",
}
}
}
}
I removed the schema as it seems to only work for "in": "body"
I've been searching the net but can't seem to find the light.
Though I will still be searching... Any hints would be greatly appreciated.
Thank you very much in advance.
A different source media type has to be consumed here. Specify "consumes" member to include media type of application/x-www-form-urlencoded.
v1swag = {
"cancels_post": {
"tags": ["/api/v1"],
"consumes": [
"application/x-www-form-urlencoded"
],
"parameters": [
{
"name": "token",
"in": "formData",
"type": "string",
"required": True,
"description": "Cancels the provided token.",
}
],
"responses": {
"200": {
"description": "Success!",
}
}
}
}
Here's my Parse Cloud Code call:
Mandrill.sendTemplate({
"template_name": "start-conversation",
"template_content": [{
"name": "example name",
"content": "example content" //Those are required but they are ignored
}],
"message": {
"to": [{
"email": request.params.toUserEmail,
"name": request.params.toUserName
}],
"important": true,
"merge": true,
"global_merge_vars": [
{
"rcpt": request.params.toUserEmail,
"vars": [
{
"name": "TOUSERNAME",
"content": request.params.toUserName
},
{
"name": "FROMUSERNAME",
"content": request.params.fromUserName
},
{
"name": "TOPICNAME",
"content": request.params.topicName
},
{
"name": "LANGUAGE",
"content": request.params.language
}
]
}
],
},
"async": true
},{
success: function(httpResponse) {
console.log(httpResponse);
response.success("mandrillStartConvoRequest -- success -- Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("mandrillStartConvoRequest -- error -- Uh oh, something went wrong");
}
});
Here's the <span> with the tags in my Mandrill Template:
<span style="line-height:20.7999992370605px">
*|TOUSERNAME|*
<br><br>
*|FROMUSERNAME|* would like to start a conversation with you about *|TOPICNAME|* in *|LANGUAGE|* </span>
The e-mail sends fine but no merge =(:
as far as I know the built-in Mandrill.sendTemplate method does not work.
so you should try to call mandrill API yourself, just do a HTTP POST
https://parse.com/questions/send-mandrill-template-email-from-cloud-code-example-code-required
UPDATE:
what I am using in my project is something like this, notice that I am using merge_vars but you are using global_merge_vars
var params = {
key: "xxxxxxxxxxxx",
template_name: "$template_name",
template_content: [],
message: {
to: [
{
email: email
}
],
merge_vars : [{
rcpt: email,
vars:[
{
"name" : "from",
"content" : "Test"
}
]
}]
},
async: true
};
Parse.Cloud.httpRequest({
method: "POST",
headers: {
"Content-Type": "application/json",
},
url: "https://mandrillapp.com/api/1.0/messages/send-template.json",
body: params,
success: function(httpResponse) {
response.success("email sent");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
I used to be able to use the IBM SBT getContacts API from either a perl script (with authentication provided in the request) or an internet browser (authentication popup would appear) and it would return the data in JSON format as documented on the IBM Connections Developers API reference page:
http://www-10.lotus.com/ldd/appdevwiki.nsf/xpAPIViewer.xsp?lookupName=API+Reference#action=openDocument&res_title=Contacts_getContacts_API&content=apicontent&sa=true
Recently, however, the API call has been returning a 403 forbidden status. If I sign in to the IBM Connections Cloud before trying to use the API via a browser, it is converted to:
https://apps.na.collabserv.com/mycontacts/home.html
Does anyone know what I need to do to get the API to work again?
Thanks.
The best API to use are
https://apps.na.collabserv.com/lotuslive-shindig-server/social/rest/people/#me/#all?filterBy=type&filterOp=equals&filterValue=contacts&format=json
You'll get a list of the following entries back...
{
"photos":
[
],
"telephone": "",
"profileUrl": "",
"mobilephone": "",
"orgs":
[
{
"value": "CONTACTS",
"type": "Source"
},
{
"value": "Mentorship Expressway",
"type": "Org"
}
],
"website": "",
"id": "na.collabserv.com:contact:160000909070",
"fax": "",
"connectedToId": 201238541234,
"addresses":
[
],
"emailAddress": "asdfasdf#us.ibm.com",
"websites":
[
],
"objectId": 160000909070,
"type": "FRIEND",
"jobtitle": "",
"updated": "2014-07-01T16:44:21.000Z",
"ims":
[
],
"emails":
[
{
"value": "CONTACTS",
"type": "Source"
},
{
"title": "Primary Email",
"email": "asdfasdf#us.ibm.com"
}
],
"org":
{
"name": "Mentorship Expressway"
},
"displayName": "asdfasdf",
"address": "",
"companyId": 22285,
"phoneNumbers":
[
{
"value": "CONTACTS",
"type": "Source"
},
{
"title": "MOBILE",
"phone": "+ asdfasdf"
}
]
}