RestApi to get attachment details for a testcase in VSTS - azure-devops

I want to fetch the attachment details and attachment of testcase from VSTS using restapi.
Which restapi from 5.0 to be used to retrieve attachment details?
https://learn.microsoft.com/en-us/rest/api/vsts/?view=vsts-rest-5.0
I have created a PBI added 2 tasks and 2 tests to it as below:
Is the ID field the WORKITEMID?
Figure 1:
Figure 2:

Test Case is a work item type, so you can use the Attachments - Get REST API.
Downloads an attachment:
GET https://dev.azure.com/{organization}/{project}/_apis/wit/attachments/{id}?api-version=5.0-preview.3
To get the attachment id you can use the Get Work Item API with $expand=al:
https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{workItemID}?api-version=5.0&$expand=all
You will get in the results the ID (in the url in the relations section):
"relations":[
{
"rel":"AttachedFile",
"url":"https://shaykia.visualstudio.com/_apis/wit/attachments/xxxxx-4453-40b0-acaf-ace14902484c",
So now you have the attachment id: xxxxx-4453-40b0-acaf-ace14902484c, to download the attachment use the API above (instaed ):
https://dev.azure.com/{organization}/{project}/_apis/wit/attachments/xxxxx-4453-40b0-acaf-ace14902484c?api-version=5.0-preview.3

Related

Need to Automate the copying of an attachment in order to push to Splunk

I'm trying to figure out a way to copy an attachment from a specific Mailbox to a folder on our exchange server so it can then be pushed to splunk.
The attachment in question is a log file generated by a cloud based application - our auditors gave us the surprise requirement that this log file now needs to be automatically uploaded into splunk (previously automated email reports were adequate).
The Exchange server is a on-prem 2013, the Splunk is on prem also. I've dabeled in VBA for an outlook script, but I dont want to corner myself into making sure I have a dedicated outlook install for it - I would like it to just be an automated task or scheduled script that runs on the exchange server.
I'm currently playing with the search-mailbox feature in exchange shell - but haven't found any functionality that looks like it can help me.
I already have the local hot-folder for splunk configured, that was the easy part.
Thanks!
You may consider using EWS, see Explore the EWS Managed API, EWS, and web services in Exchange for more information.
The following code example shows how to get an EmailMessage object by using the Bind method, then iterate through the attachment collection and call the FileAttachment.Load or ItemAttachment.Load method on each attachment as appropriate. Each file attachment is saved to the C:\temp\ folder, and each item attachment is loaded into memory. For information about how to save an item attachment, see Save an attached email by using the EWS Managed API.
public static void GetAttachmentsFromEmail(ExchangeService service, ItemId itemId)
{
// Bind to an existing message item and retrieve the attachments collection.
// This method results in an GetItem call to EWS.
EmailMessage message = EmailMessage.Bind(service, itemId, new PropertySet(ItemSchema.Attachments));
// Iterate through the attachments collection and load each attachment.
foreach (Attachment attachment in message.Attachments)
{
if (attachment is FileAttachment)
{
FileAttachment fileAttachment = attachment as FileAttachment;
// Load the attachment into a file.
// This call results in a GetAttachment call to EWS.
fileAttachment.Load("C:\\temp\\" + fileAttachment.Name);
Console.WriteLine("File attachment name: " + fileAttachment.Name);
}
else // Attachment is an item attachment.
{
ItemAttachment itemAttachment = attachment as ItemAttachment;
// Load attachment into memory and write out the subject.
// This does not save the file like it does with a file attachment.
// This call results in a GetAttachment call to EWS.
itemAttachment.Load();
Console.WriteLine("Item attachment name: " + itemAttachment.Name);
}
}
}
As for PowerShell, you may find the Exchange Server PowerShell (Exchange Management Shell) section in MSDN helpful.

RESTFul Service API POST CSV file

We are using a student management system/CRM (axcelerate) which doesn't have bulk import tools for contacts. but they do provide API for this.
I have tested on a coldbox module which allows me to test with single sets of parameter names and values.
It is confirmed the URL and API headers I am using are correct, the single parameter data was sent and shows up correctly in the CRM.
Now I am trying to send thousands of contacts. I guess to do this with a CSV file and I have tried with Postman.
I have put API headers into the Headers section, and I have put api.contact as a key, and for the value, I have uploaded a CSV file that has FIELDNAMES same as CRM advised: I used givenName and surname.
I created Elvis and Presley as values and this is the error:
{
"DATA": "",
"ERROR": true,
"MESSAGES": "Validation Error.",
"CODE": 412,
"FIELDNAMES": "givenName,surname",
"DETAILS": "Required field givenName is undefined in the request collection.,Required field surname is undefined in the request collection."
}
Any advice to execute this task successfully?
Thank you.
Looking at the API docs for the /contact route it requires you to add the givenName and surname to the URL as params
You could use your data file in the Collection Runner and reference these using the {{...}} placeholder syntax in the URL.
<basePath>/contact?givenName={{givenName}}&surname={{surname}}
The Postman docs will explain how to add the data file to the Collection Runner but once added, when you run the collection, it will populate the placeholders in the URL and hopefully create the new contacts for you in the CRM tool.

Cannot pass value to SalesForce from Docusign Document, SOAP API, MergeFieldXml

Good day everyone,
I need to pass the value of a write-back field from docusign document to Salesforce.
Can you kindly provide an example of a string specifying the properties of MergeFieldXml like configuration type, path, etc.
According to Docusign SOAP API (https://www.docusign.net/api/3.0/dsapi.asmx?op=RequestEnvelopeWithDocumentFields) the MergeField property is passed as string:
<MergeFieldXml>string</MergeFieldXml>
At the same time the string should contain properties like:
Configuration type: salesforce (always)
path: objetc.field
row: record id
writeback: true if the data should be posted to salesforce.
My try does not work showing 'Web service callout failed: WebService returned a SOAP Fault: A Mergefield value for a Tab could not be retrieved. faultcode=soap:Client faultactor=missing in Web.Config
Row Number: 1196'
tab19.MergeFieldXml = '<configurationType>salesforce</configurationType><path>contact.Question_1_Agreement__c</path><writeback>true</writeback><allowSenderToEdit>false</allowSenderToEdit>';
If using REST API this would look as follows:
"mergeField": {
"configurationType":"Salesforce",
"path":"contact.Question_1_Agreement__c",
"writeback":"true",
"allowSenderToEdit":"true",
}
According to SOAP API documentation (https://www.docusign.com/p/APIGuide/APIGuide.htm#Sending Group/Tab.htm%3FTocPath%3DDocuSign%2520Service%2520API%2520Information%7CSending%2520Function%2520Group%7CCreateAndSendEnvelope%2520and%2520CreateEnvelope%7CTab%7C_____0)
MergeFieldXml is 'reserved for future'.
Does it mean it is not implemented yet?
how do we pass values back to salesforce using SOAP MergeFieldXml?
Or there may be some other way to accomplish this?
Thank you for any advise.

MS project server update resources for timesheets

Since some SOAP operations were removed in Project Server 2016,
we are trying to replace the obsolete SOAP Statusing/UpdateStatus API call with the REST API call /Draft/Assignments('assignmentid') in order to assign resources and set the 'actualWork' property. The MSDN documentation says that we can send a MERGE or a PUT request to that URL but it doesn't mention what the request payload should look like.
Can you let me know what the JSON payload for this call should be?
MERGE _api/ProjectServer/Projects('projectid')/Draft/Assignments('assignmentid')
API documentation: https://msdn.microsoft.com/en-us/library/office/jj668054.aspx
replace things in < > with appropriate values for your data
1) CheckOut the project
POST <pwaUrl>/_api/projectserver/projects('<projectId>')/checkout
2) Add enterprise resource to project team
POST <pwaUrl>/_api/projectserver/projects('<projectId>')/draft/projectresources/addenterpriseresourcebyid('<enterpriseResourceId>')
3) Create the assignment to an existing task
POST <pwaUrl>/_api/projectserver/projects('<projectId>')/draft/assignments/add()
{ "parameters":{
"ResourceId":"<enterpriseResourceId>",
"TaskId":"<taskId>"
}
}
4) edit 1 or more assignment properties
PATCH <pwaUrl>/_api/projectserver/projects('<projectId>')/draft/assignments('<draftAssigmentId>')
{ "ActualWorkTimeSpan":"PT24H" }
5a) Publish & check-in:
POST <pwaUrl>/_api/projectserver/projects('<projectId>')/draft/publish(true)
5b) Or just Check-in (if you don’t want to publish):
POST <pwaUrl>/_api/projectserver/projects('<projectId>')/draft/checkin(false)

Unable to get RQM Test case by testcase title using REST API

I am using java RQM Rest API to fetch data from RQM tool
I have a test case in project CLM Test (Quality Management).
The test case title is
Pre-Paid Residential Customer to Post-Paid Consumer (Qatari-National) Customer Migration.(Existing Customer having only prepaid subscription)
Internal Id is 3271
I am trying to fetch test case details from Test Suite.
While fetching the test case details from TestSuite, I am getting the test case href as
<testcase href= "https://clm.techmahindra.com:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/CLM+Test+%28Quality+Management%29/testcase/Pre-Paid_Residential Customer_to_Post-Paid_Consumer_(Qatari-National)_Customer_Migration.(Existing_Customer_having_only_prepaid_subscription).xml" />
If you observe the test case href, it contains a space after 'Paid_Residential'
so when querying the server with this href, I am getting URISyntaxException due to the space in string.
One more strange thing is:
When I query server using RestClient(FireFox plugin) this query says 400 Error - Bad request. But when i click on testcase href as recieved in TestSuite record, I am able to get the testcase record.
Please help me to get this data.
It seems the title contains some special characters that throws URISyntaxException when we try to convert href to URI percentage encoding format. I initially used URI java class for conversion and it failed to convert the string (href= "https://clm.techmahindra.com:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/CLM+Test+%28Quality+Management%29/testcase/Pre-Paid_Residential Customer_to_Post-Paid_Consumer_(Qatari-National)_Customer_Migration.(Existing_Customer_having_only_prepaid_subscription).xml")
But when I tried with URLEncoder class, it worked. Now I able to get record even for test cases having special characters in it.
snippet:
String strURI = URLEncoder.encode(href, "UTF-8");