how to use os.listdir() in smartsheet? - smartsheet-api

I would like to get all the folder that are in a specific folder in smartsheet
I wanted to use os.listdir but I am not sure on how to use it on smartsheet
any idea ?
any idea on how to implement that without os.listdir ?

To get a list of objects within a specified Smartsheet folder, you'll need to use the Smartsheet API -- specifically the Get Folder operation.
To issue a GET Folder request, you'll need to know the ID of the folder that you want to get. The easiest way to determine a folder's ID is by (manually) logging into Smartsheet, navigating to the location where the folder resides, then right click on the folder name and choose Properties. The following screenshot shows where you'll find the folder's ID in the Properties dialog window.
To retrieve the contents of this folder, the GET Folder API request would be:
GET https://api.smartsheet.com/2.0/folders/1589169626605444
The response will specify the folder properties, including collections of objects that the folder contains such as sheets, folders, reports, sights, etc. Note that the response will only contain the items that exist at the top-level of the specified folder -- i.e., it won't contain any items that exist within subfolders of that folder.
For example, let's say the folder I want to get the contents of contains the following items (2 folders, 2 dashboards (sights), 2 reports, and 2 sheets).
The GET Folder response for the parent folder shown in the screenshot above is:
{
"id": 1589169626605444,
"name": "Parent Folder",
"permalink": "https://app.smartsheet.com/folders/XvFv8qxCG5R3VqmCX5CG5PxC6PRp9C336Hj2mwv1",
"sheets": [
{
"id": 8573752976926596,
"name": "Sheet 1",
"accessLevel": "OWNER",
"permalink": "https://app.smartsheet.com/sheets/6CcCwJhJPRCGGR536F7wQ8QR8G5Rwwp2v69wP831",
"createdAt": "2022-09-07T21:09:26Z",
"modifiedAt": "2022-09-07T21:09:26Z"
},
{
"id": 3942867698771844,
"name": "Sheet 2",
"accessLevel": "OWNER",
"permalink": "https://app.smartsheet.com/sheets/r8j3PRx33gfH2rvmw77QWQ4GH64Vx73cjH794xw1",
"createdAt": "2022-09-07T21:09:31Z",
"modifiedAt": "2022-09-07T21:09:31Z"
}
],
"folders": [
{
"id": 304940045363076,
"name": "Subfolder 1",
"permalink": "https://app.smartsheet.com/folders/HQhfCrwwrcj858qxCjf8j3gV43R97gp2CQjqv6q1"
},
{
"id": 797521254606724,
"name": "Subfolder 2",
"permalink": "https://app.smartsheet.com/folders/M8fpH7wcJmHrWr7RQV7pqr5xWfcqCcjjRvjfMX81"
}
],
"reports": [
{
"id": 3321248492087172,
"name": "Report 1",
"accessLevel": "OWNER",
"permalink": "https://app.smartsheet.com/reports/7v96G7r9Q7GJXq8R7Xg9pFCRM83MvmhHVW7RqXV1",
"createdAt": "2022-09-07T21:09:12Z",
"modifiedAt": "2022-09-07T21:09:12Z"
},
{
"id": 7235389627885444,
"name": "Report 2",
"accessLevel": "OWNER",
"permalink": "https://app.smartsheet.com/reports/hGP5pFVhW65QC3whQW9p8HQ75HmWRXFrHm9F4MW1",
"createdAt": "2022-09-07T21:09:20Z",
"modifiedAt": "2022-09-07T21:09:20Z"
}
],
"sights": [
{
"id": 8871794707851140,
"name": "Dashboard 1",
"accessLevel": "OWNER",
"permalink": "https://app.smartsheet.com/dashboards/fccJ8V54x3jhPr2gxxC96C2rVjV72fH9wCJWvp81",
"createdAt": "2022-09-07T21:09:48Z",
"modifiedAt": "2022-09-07T21:09:48Z"
},
{
"id": 2327501499328388,
"name": "Dashboard 2",
"accessLevel": "OWNER",
"permalink": "https://app.smartsheet.com/dashboards/X8VmpVvWPhHHfPPFWhGMcJpPXJvPPMg6FWwpwhX1",
"createdAt": "2022-09-07T21:09:58Z",
"modifiedAt": "2022-09-07T21:09:58Z"
}
]
}
(This is just an example. See the API docs I've listed to above for full details about the GET Folder response.)
If you're using the Smartsheet Python SDK to issue the GET Folder request, then the following code may be helpful. It issues a GET Folder request and then iterates through objects in the response to print info about the contents of the folder.
folderId = 1589169626605444
# get the parent folder
parent_folder = smartsheet_client.Folders.get_folder(folderId)
# print sheet info
print('----')
print('Number of sheets: ' + str(len(parent_folder.sheets)))
for sheet in parent_folder.sheets:
print('Sheet: ' + sheet.name)
# print folder info
print('----')
print('Number of folders: ' + str(len(parent_folder.folders)))
for folder in parent_folder.folders:
print('Folder: ' + folder.name)
# print report info
print('----')
print('Number of reports: ' + str(len(parent_folder.reports)))
for report in parent_folder.reports:
print('Report: ' + report.name)
# print dashboard info
print('----')
print('Number of dashboards: ' + str(len(parent_folder.sights)))
for sight in parent_folder.sights:
print('Dashboard: ' + sight.name)
print('----')
For the parent folder described above, this code prints the following output to the console:
----
Number of sheets: 2
Sheet: Sheet 1
Sheet: Sheet 2
----
Number of folders: 2
Folder: Subfolder 1
Folder: Subfolder 2
----
Number of reports: 2
Report: Report 1
Report: Report 2
----
Number of dashboards: 2
Dashboard: Dashboard 1
Dashboard: Dashboard 2

Related

Create task in TFS via PowerShell

I need to create a task in TFS with PowerShell
I used the VSTeam (A PowerShell module for many features in TFS / Azure DevOps). The item is created. I have a template for the description but i don't know how to insert it to -Description that gets a string
Here is an example of the template:
The build is an hyper link and also the tfs item (patch XXXX)
How can I built the string like this? How to create a link for items?
How to set a bold string?
Can I copy a link from TFS?
There is a new build. The build location:
\\XXXXX\global\QA\
The patches that were added:
Patch 1269263: "Title"
Patch 1271540: "Title"
Have you looked into VSTeam? A PowerShell module for many features in TFS / Azure DevOps.
Set-VSTeamAccount -Account http://localtfs:8080/tfs/DefaultCollection -UseWindowsAuthentication
Set-VSTeamDefaultProject Demo
$additionalFields = #{"System.Tags"= "TestTag"; "System.AreaPath" = "Project\\MyPath"}
Add-VSTeamWorkItem -Title "New Work Item" -WorkItemType Task -AdditionalFields $additionalFields
ID Title Status
-- ----- ------
6 New Work Item To Do
The description field in TFS/Azure DevOps contains HTML text. Any formatting can be done using standard HTML constructs. <i> for italic, <b> for bold <a href="https://....."> for links.
To get the links you may need to invoke other REST APIs to get the build details. Most APE results have a links collection with a web link you can use to direct people to the web page for that thing.
Example from a Build/GET API call:
GET https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/builds/2817
{
"_links": {
"self": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/Builds/2817"
},
"web": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_build/results?buildId=2817"
},
"sourceVersionDisplayUri": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/builds/2817/sources"
},
"timeline": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/builds/2817/Timeline"
},
"badge": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/status/36"
}
},
...
...
}
In this case self is the link that retrieved this document. web is the equivalent in the WebUI, etc.
You'll find that other elements returned by the API carry a url property. By folliwing that URL, you'll get the _links collection for that object as well:
...
...
"project": {
"id": "a88536a2-a889-45a3-a955-ddf1af8aeba1",
"name": "azure-devops-extensions",
"description": "This projects hosts the pipelines for all my Azure DevOps marketplace extensions.",
"url": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1",
"state": "wellFormed",
"revision": 414360082,
"visibility": "public",
"lastUpdateTime": "2019-06-28T09:48:16.943Z"
},
Following:
GET https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1
{
"id": "a88536a2-a889-45a3-a955-ddf1af8aeba1",
"name": "azure-devops-extensions",
"description": "This projects hosts the pipelines for all my Azure DevOps marketplace extensions.",
"url": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1",
"state": "wellFormed",
"revision": 414360082,
"_links": {
"self": {
"href": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1"
},
"collection": {
"href": "https://dev.azure.com/jessehouwing/_apis/projectCollections/6ac92044-9ce2-40d0-b882-f6b6648dff8b"
},
"web": {
"href": "https://dev.azure.com/jessehouwing/azure-devops-extensions"
}
},
"visibility": "public",
"defaultTeam": {
"id": "7edc4d0a-3d22-44ee-a6cd-96a3dbf0690f",
"name": "azure-devops-extensions Team",
"url": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1/teams/7edc4d0a-3d22-44ee-a6cd-96a3dbf0690f"
},
"lastUpdateTime": "2019-06-28T09:48:16.943Z"
}
This way you can collect the links to the appropriate UI pages to direct your users to.

Add files to Salesforce CMS channel folder via Connect API?

I'm developing an integration that will programmatically create product entries in Salesforce, and part of that process needs to be the addition of product images. I'm using the Connect API and am able to make a GET call to the right folder like this (I've scrambled the IDs and what not for this example):
https://example.salesforce.com/services/data/v52.0/connect/cms/delivery/channels/0591G0000000006/contents/query?folderId=9Pu1M000000fxUMSYI
That returns a payload like this:
{
"currentPageUrl": "/services/data/v52.0/connect/cms/delivery/channels/0ap1G0000000006/contents/query?page=0&pageSize=250",
"items": [
{
"contentKey": "MCZ2YVCGLNSBETNIG5P5QMIS4KNA",
"contentNodes": {
"source": {
"fileName": "PET Round.jpg",
"isExternal": false,
"mediaType": "Image",
"mimeType": "image/jpeg",
"nodeType": "MediaSource",
"referenceId": "05T0R000005MthL",
"resourceUrl": "/services/data/v52.0/connect/cms/delivery/channels/0ap1G0000000007/media/MCY2YVCGLNSBETNIG5P4QMIS4KNA/content",
"unauthenticatedUrl": "/cms/delivery/media/MCZ2YVCGLNSBETNIG5P4QMIS4KNA",
"url": "/cms/delivery/media/MCY2YVCGLNSBETNIG5P4QMIS4KNA"
},
"title": {
"nodeType": "NameField",
"value": "844333"
}
},
"contentUrlName": "844333",
"language": "en_US",
"managedContentId": "20T0R0000008U9qUAE",
"publishedDate": "2021-08-18T16:20:57.000Z",
"title": "844333",
"type": "cms_image",
"typeLabel": "Image",
"unauthenticatedUrl": "/cms/delivery/v52.0/0DB1G0000008tfOWAU/contents/20Y0R0000008y9qUAE?oid=00D0R000000OI7GUAW"
}
]
}
I am also able to retrieve images by contentKey with a GET call like this:
https://example.salesforce.com/services/data/v52.0/connect/cms/delivery/channels/0ap1G0000000007/media/MCZ2ZVCGLNSBETMIG5P4QMIS4KNA/content
Anyone know what the endpoint should look like and what parameters etc it should have? I'm having trouble finding anything for this specific scenario in the docs but surely there's a way.
Thanks!

Where can I find System.TeamProjectId for a project in Azure Devops

I need this Id upfront but I can't seem to find it anywhere online?
The documentation only refers to it as a system variable.
Context:
I have multiple projects and I want to identify a project during CI so it can run a powershell script hosted in another repository.
You can get the all team projects id with REST Api:
https://dev.azure.com/{organization}/_apis/projects?api-version=5.0-preview.3
Results:
{
"count": 3,
"value": [
{
"id": "eb6e4656-77fc-42a1-9181-4c6d8e9da5d1",
"name": "Fabrikam-Fiber-TFVC",
"description": "Team Foundation Version Control projects.",
"url": "https://dev.azure.com/fabrikam/_apis/projects/eb6e4656-77fc-42a1-9181-4c6d8e9da5d1",
"state": "wellFormed"
},
{
"id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
"name": "Fabrikam-Fiber-Git",
"description": "Git projects",
"url": "https://dev.azure.com/fabrikam/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
"state": "wellFormed"
},
{
"id": "281f9a5b-af0d-49b4-a1df-fe6f5e5f84d0",
"name": "TestGit",
"url": "https://dev.azure.com/fabrikam/_apis/projects/281f9a5b-af0d-49b4-a1df-fe6f5e5f84d0",
"state": "wellFormed"
}
]
}
You don't even need use Postman or create Http request, just enter the API url above in the browser.
You can examine the HTML in the UI of the dashboard on your organisation projects page:

Access OData services from two different system in SAP Web IDE

I have two OData services on two different systems, for which I have added destinations in HCP and entries in neo-aap.json file.
{
"path": "/sap/opu/odata",
"target": {
"type": "destination",
"name": "ABC",
"entryPath": "/sap/opu/odata"
},
"description": "ABC"
}, {
"path": "/sap/opu/odata",
"target": {
"type": "destination",
"name": "XYZ",
"entryPath": "/sap/opu/odata"
},
"description": "XYZ"
}
With this, I'm able to access only one system's service i.e. OData service which is on ABC. When app loads app tries to load hit metadata for 2nd OData service as well in ABC which is obviously not there, hence fails.
How do I access the OData service on XYZ system?
If the 'path' is the same, only the first one will be matched. Set different paths for your destinations.
The 'path' property in the neo-app.json is just an alias for your destinations. With your config, this means, whenever in your app, you request something from '/sap/opu/odata/... ' the application will overwrite this part of the path with the URL you configured in the Destination.
Just make something like this:
{
"path": "/ABC/sap/opu/odata",
"target": {
"type": "destination",
"name": "ABC",
"entryPath": "/sap/opu/odata"
},
"description": "ABC"
}, {
"path": "/XYZ/sap/opu/odata",
"target": {
"type": "destination",
"name": "XYZ",
"entryPath": "/sap/opu/odata"
},
"description": "XYZ"
}
And then make sure you use "/ABC/sap/opu/odata" or "/XYZ/sap/opu/odata" whenever you set your model data sources.
This, from my perspective, is a bug.
The key used for locating the destination is the "path" value so you will always hit the first destination.
You can resolve this by changing the path from /sap/opu/odata to /sap/opu/odata1
You then edit your dataSources in your manifest.json: adjust the "uri" with the adjusted path on any models you are trying to point to the 2nd path.
I have written on this here and am busy trying to get SAP to change this behaviour.

Rally - Create User Story with tags using REST (non-API)

How do I add/attach tags while creating/updating user stories in Rally? I'm using the below JSON script and I'm getting a error "cannot find referenced object". What am I missing?
{
"HierarchicalRequirement": {
"Description": "As a developer to create a user story",
"Name": "User story to be created",
"Notes": "Created via REST Client",
"Project": {
"_ref": "https://rally1.rallydev.com/slm/webservice/v2.0/project/1302421049",
"_refObjectName": "Sample Project",
"_type": "Project"
},
"Tags": {
"_type": "Tag",
"_tagsNameArray": [{
"Name": "My Tag"
}],
"Count": 1
}
}
}
Thanks in advance,
Leo.
You just need to encode your tags a little differently and you'll have it. Tags (and all collections) expect to be specified as an array of objects with _ref properties like so:
"Tags": [
{
"_ref": "/tag/12345"
},
{
"_ref": "/tag/23456"
}
]