Alfresco REST API: How do I list folders in the site? - alfresco

Given this URL
http://localhost:8080/alfresco/service/api/sites/test-3
I get back:
{
"url": "\/alfresco\/service\/api\/sites\/test-3",
"sitePreset": "site-dashboard",
"shortName": "test-3",
"title": "Test 3",
"description": "",
"node": "\/alfresco\/service\/api\/node\/workspace\/SpacesStore\/0352afea-797f-4b9e-be27-3bf37e54a2f1",
"tagScope": "\/alfresco\/service\/api\/tagscopes\/workspace\/SpacesStore\/0352afea-797f-4b9e-be27-3bf37e54a2f1",
"siteManagers":
[
"admin"
],
"isPublic": true,
"visibility": "PUBLIC"
}
How to I use that info to get the list of folders in the site?

You need to use a different API. Look at this shell session:
$ curl -u admin:admin -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d "{'shortName':{'values':['test'], 'match':'foo'}}" http://localhost:8080/alfresco/service/api/sites/query
{
"url" : "\/alfresco\/service\/api\/sites\/test",
"sitePreset" : "wcmqs-site-dashboard",
"shortName" : "test",
"title" : "test",
"description" : "",
"node" : "\/alfresco\/service\/api\/node\/workspace\/SpacesStore\/e597e4c2-d307-46e3-ba4d-b911262e7261",
"tagScope" : "\/alfresco\/service\/api\/tagscopes\/workspace\/SpacesStore\/e597e4c2-d307-46e3-ba4d-b911262e7261",
"isPublic" : false,
"visibility" : "PRIVATE",
"siteManagers" :
[
"admin"
]
}
// see the 'node' property up there
$ curl -u admin:admin http://p01:8080/alfresco/service/api/node/workspace/SpacesStore/e597e4c2-d307-46e3-ba4d-b911262e7261/children
[..cmis response here..]

One option is to use CMIS. Depending on your exact needs though, you can use some built in webscripts to do the listings too
Within the root of a site, you have Containers, such as documentLibrary and wiki. You can get a list of the containers for a site from the container.get webscript. Take a look at org/alfresco/slingshot/documentlibrary/container.get.desc.xml for the details. The URL pattern for it, as shown in that file, is /slingshot/doclib/containers/{site}
curl -u admin:admin http://localhost:8080/alfresco/service/slingshot/doclib/containers/test
{
"containers":
[
{
"name": "documentLibrary",
"description": "Document Library",
"nodeRef": "workspace://SpacesStore/973338a0-db39-458e-a10d-396f00cb16a3",
"type": "cm:folder"
}
]
}
Next, when you know what container or folder within a container you want to use, the treenode.get webscript can let you list that, eg
curl -u admin:admin http://localhost:8080/alfresco/service/slingshot/doclib/treenode/site/test/documentLibary
{
"totalResults": 0,
"resultsTrimmed": false,
"parent":
{
"nodeRef": "workspace://SpacesStore/92e4f8de-b919-4540-a27a-16c4e53a57bc",
"userAccess":
{
"create": true,
"edit": true,
"delete": true
}
},
"items":
[
]
}
I can also recommend you use http://localhost:8080/alfresco/service/index to view what webscripts are present in your system, and get information on them, it helps a lot for situations like this

Load a site: http://localhost:8080/alfresco/service/api/sites/test-3
{
"url": "\/alfresco\/service\/api\/sites\/test-3",
"sitePreset": "site-dashboard",
"shortName": "test-3",
"title": "test 3",
"description": "",
"node": "\/alfresco\/service\/api\/node\/workspace\/SpacesStore\/0352afea-797f-4b9e-be27-3bf37e54a2f1",
"tagScope": "\/alfresco\/service\/api\/tagscopes\/workspace\/SpacesStore\/0352afea-797f-4b9e-be27-3bf37e54a2f1",
"siteManagers":
[
"admin"
],
"isPublic": true,
"visibility": "PUBLIC"
}
Get the site contents using the ID extracted from the node property: http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/0352afea-797f-4b9e-be27-3bf37e54a2f1/children
Inside that is a node with the title "documentLibrary". Using its ID GUID, you can fetch some more children
http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/b68db1eb-547d-4b2c-b5eb-ba207a275789/children
If you have custom properties, they will appear on the child items using this API call.
Using the ID of the child item, you can get its content.
http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/2d53f464-bea0-46f3-aa0c-10b3302e661c/content

Use this url to get folder list.
http://localhost:8080/alfresco/service/api/node/workspace:SpacesStore/store_id/b0697dd1-ae94-4bf6-81c8-5e2fa098ddfa/children

Related

LinkedIn UGC Posts API with projection returns invalid paging URL

I would like to retrieve UGC posts from organization's profile using the ugcPosts API. I would also like to receive links to video streams with the response, so I use the following projection (based on this answer):
(paging,elements*(id,created,specificContent(com.linkedin.ugc.ShareContent(shareMediaCategory,shareCommentary,media(*(media~:playableStreams,originalUrl,description,title,thumbnails))))))
My whole request looks like this (retrieving the posts of the official test organization):
curl --request GET \
--url 'https://api.linkedin.com/v2/ugcPosts?q=authors&sortBy=LAST_MODIFIED&projection=(paging%2Celements*(id%2Ccreated%2ClastModified%2Cauthor%2CspecificContent(com.linkedin.ugc.ShareContent(shareMediaCategory%2CshareCommentary%2Cmedia(*(media~%3AplayableStreams%2CoriginalUrl%2Cdescription%2Ctitle%2Cthumbnails))))))&authors=List(urn%3Ali%3Aorganization%3A2414183)' \
--header 'Authorization: Bearer <ACCESS_TOKEN>' \
--header 'X-Restli-Protocol-Version: 2.0.0'
The request works as fine. But I run into an issue if I want to follow to the next page using the provided URL in paging; this is the relevant response:
{
"paging": {
"total": 284243,
"count": 10,
"start": 0,
"links": [
{
"rel": "next",
"type": "application/json",
"href": "/v2/ugcPosts?q=authors&start=10&count=10&sortBy=LAST_MODIFIED&projection=%28paging%2Celements*%28id%2Ccreated%2ClastModified%2Cauthor%2CspecificContent%28com.linkedin.ugc.ShareContent%28shareMediaCategory%2CshareCommentary%2Cmedia%28*%28media~%3AplayableStreams%2CoriginalUrl%2Cdescription%2Ctitle%2Cthumbnails%29%29%29%29%29%29&authors=List(urn%3Ali%3Aorganization%3A2414183)"
}
]
}
}
On the first page, you can see that parentheses in the projection parameter got URL encoded, while authors parameter remains the same. This request still works, but if I follow the URL one more time, I recieve the following paging data:
{
"paging": {
"total": 284243,
"count": 10,
"start": 10,
"links": [
{
"rel": "prev",
"type": "application/json",
"href": "/v2/ugcPosts?q=authors&start=0&count=10&sortBy=LAST_MODIFIED&projection=%2528paging%252Celements*%2528id%252Ccreated%252ClastModified%252Cauthor%252CspecificContent%2528com.linkedin.ugc.ShareContent%2528shareMediaCategory%252CshareCommentary%252Cmedia%2528*%2528media~%253AplayableStreams%252CoriginalUrl%252Cdescription%252Ctitle%252Cthumbnails%2529%2529%2529%2529%2529%2529&authors=List(urn%3Ali%3Aorganization%3A2414183)"
},
{
"rel": "next",
"type": "application/json",
"href": "/v2/ugcPosts?q=authors&start=20&count=10&sortBy=LAST_MODIFIED&projection=%2528paging%252Celements*%2528id%252Ccreated%252ClastModified%252Cauthor%252CspecificContent%2528com.linkedin.ugc.ShareContent%2528shareMediaCategory%252CshareCommentary%252Cmedia%2528*%2528media~%253AplayableStreams%252CoriginalUrl%252Cdescription%252Ctitle%252Cthumbnails%2529%2529%2529%2529%2529%2529&authors=List(urn%3Ali%3Aorganization%3A2414183)"
}
]
}
}
You can see here that the projection parameter got URL-encoded again (having %252C for parens) and following that URL returns error 400.
I think this is a bug in the API, but since LinkedIn recommends to use Stack Overflow for support, I just wrote this up here, hopeful someone notices. Perhaps could you suggest another way of contacting LinkedIn about this bug in their API?
Meanwhile I resorted to constructing the pagination URL manually.

issues while posting data from curl to Firestore throw curl

I am very beginner to Google Firestore (also to Firebase). I am doing a simple POC and I am suffering a bit to interact with FireStore. Well, reading the data from Angular worked as a charm so easy. Nevertheless, simple actions like add a new data from curl or deleting the collection from FireBase Cli has taken me the whole day without progress . Just to stress how dummy I am in FireStore, I have used ElasticSearch local installed so I am trying similar behaviours/tools/functionalities like posting/creating fields from curl/postman (it is not part of this question compare one another, just exposing my limitations) but I just can't move forward.
This is how I connected successfully from Angular:
firebaseConfig : {
apiKey: "*** removed ***",
authDomain: "transfer-status-realtime.firebaseapp.com",
databaseURL: "https://transfer-status-realtime.firebaseio.com",
projectId: "transfer-status-realtime",
storageBucket: "transfer-status-realtime.appspot.com",
messagingSenderId: "143612370857",
appId: "1:143612370857:web:a9d0b21e3a58520ed02eb8",
measurementId: "G-WT5C346D7T"
}
I have based mainly my tentatives in Making Rest Calls and other stack overflow question
My last and recent tried:
c:\temp>curl -X POST -H "Content-Type: application/json" -d'{"fields": {"status": "success"}}' "https://firestore.googleapis.com/v1beta1/projects/transfer-status-realtime/databases/(default)/documents/transfers?&key=***removed***"
curl: (3) [globbing] unmatched brace in column 1
curl: (3) [globbing] unmatched close brace/bracket in column 8
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Closing quote expected in string.\n\n^",
"status": "INVALID_ARGUMENT"
}
}
So my main issue: how add data to FireStore from curl?
In case it matter, here is my database console:
Other tentatives probably in wrong direction I have tried are:
According to https://firebase.google.com/docs/database/rest/save-data, I can save fields by using PUT so I tried write a curl command and I got stuck because I don't know what would be the "fireblog" in my case?
curl -X PUT -d '{
"transfers": {
"id": "idfromPut",
"status": 1
}
}' 'https://transfer-status-realtime.firebaseio.com/rest/saving-data/fireblog/users.json'
I also tried but what would be message_list in my case?
curl -X POST -d '{"status" : 2}' 'https://transfer-status-realtime.firebaseio.com/message_list.json'
*** edited
c:\temp>curl -X POST -H "Content-Type: application/json" -d "{\"fields\": {\"status\": \"success\"}}" "https://firestore.googleapis.com/v1/projects/transfer-status-realtime/databases/(default)/documents/transfers?&key=*** removed ***"
{
"error": {
"code": 400,
"message": "Invalid value at 'document.fields[0].value' (type.googleapis.com/google.firestore.v1.Value), \"success\"",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document.fields[0].value",
"description": "Invalid value at 'document.fields[0].value' (type.googleapis.com/google.firestore.v1.Value), \"success\""
}
]
}
]
}
}
In case it is relevant, same issue using external json file
C:\WSs\reactive-stack\reactive-front\src>curl -X POST -H "Content-Type: application/json" -d #load-data-tofirestore.json "https://firestore.googleapis.com/v1/projects/transfer-status-realtime/databases/(default)/documents/transfers?&key=***removed"
{
"error": {
"code": 400,
"message": "Invalid value at 'document.fields[0].value' (type.googleapis.com/google.firestore.v1.Value), \"success\"",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document.fields[0].value",
"description": "Invalid value at 'document.fields[0].value' (type.googleapis.com/google.firestore.v1.Value), \"success\""
}
]
}
]
}
}
And here is the json file
{"fields": {"status": "success"}}
* SOLUTION *
from cUrl
C:\WSs\reactive-stack\reactive-front\src>curl -H "Content-Type: application/json" -X POST https://firestore.googleapis.com/v1/projects/transfer-status-realtime/databases/(default)/documents/transfers -d "{\"fields\": { \"status\": { \"stringValue\": \"outro status\" } }}"
{
"name": "projects/transfer-status-realtime/databases/(default)/documents/transfers/ddwHxjy7eQV3640pW0Xx",
"fields": {
"status": {
"stringValue": "outro status"
}
},
"createTime": "2020-04-06T16:21:16.453553Z",
"updateTime": "2020-04-06T16:21:16.453553Z"
}
from PowerShell
PS C:\Users> $body = #"
>> {
>> "fields": {
>> "status": {
>> "stringValue": "fracasso"
>> }
>> }
>> }
>> "#
>>
PS C:\Users\Cast> $params = #{
>> Uri = 'https://firestore.googleapis.com/v1/projects/transfer-status-realtime/databases/(default)/documents/transfers'
>> Method = 'POST'
>> Body = $body
>> ContentType = 'application/json'
>> }
>>
PS C:\Users\Cast> Invoke-RestMethod #params
name fields createTime
---- ------ ----------
projects/transfer-status-realtime/databases/(default)/documents/transfers/z4TB6gzcgXMRUGR8ecek #{status=} 2020-04-06...
PS C:\Users>
I believe the root cause of your issue is due to cURL on a windows system. As seen in this other question, there are limitations on how the command line arguments are parsed in a windows shell.
Instead of using this:
-d'{"fields": {"status": "success"}}'
You should state your payload as:
-d "{\"fields\": {\"status\": \"success\"}}"
Another solution could be writing the JSON in a file and using its path in the cURL query. I believe you could keep the right JSON format this way, but you would be forced to use a file, which is far from optimal if you don't intend to send the same payload multiple times:
-d #file_with_data.json

How to use Optional Headers in Artifactory REST API?

I'm able to search using
GET /api/search/prop?[p1=v1,v2][&p2=v3][&repos=x[,y]]
as per the documentation. But how to use optional headers to get extra information for the found artifacts?
You need to set the HTTP header X-Result-Detail to properties. Using a curl command it would look something like this
curl -uUSERNAME:PASSWORD --request GET \
--url 'http://jfrog.local/artifactory/api/search/prop?build.number=1&repos=generic-prod' \
--header 'X-Result-Detail: properties'
This will look in my repository called generic-prod for all artifacts that have build.number = 1 as a property.
That would return with the results you're looking for
{
"results" : [ {
"properties" : {
"build.name" : [ "docker-jenkins-build" ],
"build.number" : [ "1" ],
"build.timestamp" : [ "1556557591780" ]
},
"uri" : "http://jfrog.local:80/artifactory/api/storage/generic-prod/jenkins.zip"
} ]
}
This lists the properties I have for my artifact.

How to I prevent Microsoft.Automation/automationAccounts/Compilationjobs to always run in ARM deployment?

My ARM template is below which is nested template in bigger ARM template. For some reason DSC Compilation job always run on each deployment. I expected it not be run if it was already run before. How do I control this behavior? I tried using "incrementNodeConfigurationBuild": "false" but it did not do the trick.
{
"name": "WorkerNodeDscConfiguration",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"resourceGroup": "[parameters('automationAccountRGName')]",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.1",
"resources": [
{
"apiversion": "2015-10-31",
"location": "[reference(variables('automationAccountResourceId'), '2018-01-15','Full').location]",
"name": "[parameters('automationAccountName')]",
"type": "Microsoft.Automation/automationAccounts",
"properties": {
"sku": {
"name": "Basic"
}
},
"tags": {},
"resources": [
{
"name": "workernode",
"type": "configurations",
"apiVersion": "2018-01-15",
"location": "[reference(variables('automationAccountResourceId'), '2018-01-15','Full').location]",
"dependsOn": [
"[concat('Microsoft.Automation/automationAccounts/', parameters('AutomationAccountName'))]"
],
"properties": {
"state": "Published",
"overwrite": "false",
"incrementNodeConfigurationBuild": "false",
"Source": {
"Version": "1.2",
"type": "uri",
"value": "[parameters('WorkerNodeDSCConfigURL')]"
}
}
},
{
"name": "[guid(resourceGroup().id, deployment().name)]",
"type": "Compilationjobs",
"apiVersion": "2018-01-15",
"tags": {},
"dependsOn": [
"[concat('Microsoft.Automation/automationAccounts/', parameters('AutomationAccountName'))]",
"[concat('Microsoft.Automation/automationAccounts/', parameters('AutomationAccountName'),'/Configurations/workernode')]"
],
"properties": {
"configuration": {
"name": "workernode"
},
"incrementNodeConfigurationBuild": "false",
"parameters": {
"WebServerContentURL": "[parameters('WebServerContentURL')]"
}
}
}
]
}
]
}
}
}
In short, AFAIK you should be able to control this behaviour with 'condition'.
To explain it in detail, the DSC compilation jobs resource always run on each deployment because when we use the DSC compilation jobs resource (i.e., Microsoft.Automation/automationAccounts/compilationjobs) in the ARM template, IMHO what it does in the behind is, basically clicks on 'Compile' button of the DSC configuration.
If you click on that 'Compile' button, the compilation of job happens for sure even if it already compiled the job. You may check the same part manually as well.
So AFAIK that was the reason for compilation job always running on each deployment.
What you could do is, update your ARM template with 'condition' (For more information, refer https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-resources#condition and https://learn.microsoft.com/en-us/azure/architecture/building-blocks/extending-templates/conditional-deploy) and then wrap your template with below sample piece of PowerShell code that would determine if the Compilation of job for particular DSC configuration is done already and then deploy the template by passing inline parameter value or by updating condition parameter in parameters template file with new or existing value accordingly. (For more information, refer https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-deploy#pass-parameter-values)
$DscCompilationJob = Get-AzAutomationDscCompilationJob -AutomationAccountName AUTOMATIONACCOUNTNAME -ResourceGroupName RESOURCEGROUPNAME|Sort-Object -Descending -Property CreationTime|Select -First 1| Select Status
$DscCompilationJobStatus = $DscCompilationJob.Status
if ($DscCompilationJobStatus -ne "Completed"){
$DscCompilationJobStatusInlineParameter = "new"
New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName testgroup -TemplateFile TEMPLATEFILEPATH\demotemplate.json -exampleString $DscCompilationJobStatusInlineParameter
#or update condition parameter in parameters template file with new value accordingly and use below command to deploy the template
New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile TEMPLATEFILEPATH\demotemplate.json -TemplateParameterFile TEMPLATEFILEPATH\demotemplate.parameters.json
}else{
$DscCompilationJobStatusInlineParameter = "existing"
New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName testgroup -TemplateFile TEMPLATEFILEPATH\demotemplate.json -exampleString $DscCompilationJobStatusInlineParameter
#or update condition parameter in parameters template file with existing value accordingly and use below command to deploy the template
New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile TEMPLATEFILEPATH\demotemplate.json -TemplateParameterFile TEMPLATEFILEPATH\demotemplate.parameters.json
}
And regarding incrementNodeConfigurationBuild property, IMHO this property is just with regards to creation of a new build version of Node Configuration is required or not i.e., when incremental node configuration build is set to false, it does not override the earlier existing Node Configuration by creating a new Node Configuration with the name CONFIGNAME[<2>] (the version number is incremented based on the existing version number already present).
Hope this helps!! Cheers!! :)

Bitbucket API adding branch restriction - malformed groups

Trying to add branch restriction to a repository, I was successful in adding a rule, however, I cannot get a group added to the rule.
curl -XPOST --user user:password -H "Content-Type: application/json" -d '{"kind": "push", "pattern": "testing*", "groups": {"name": "testleads"}}' $URL/api/2.0/repositories/team/repo/branch-restrictions
Result:
{"error": {"message": "malformed groups"}}
I have tried different combinations in the groups using full_slug, slug and also changing the inheritance types.
-d '{"kind": "push", "pattern": "testing*", "groups":["name": "devleads"]}'
-d '{"kind": "push", "pattern": "testing*", "groups": {"name": "devleads"}}'
Has anyone tried this?
After a lot of tries, I narrowed it down to this JSON input to be able to add branch restrictions
-d '{"kind": "push", "pattern": "test*", "value": null, "groups": [{"name": "devLeads", "account_privilege": null, "full_slug": "team-name:devleads", "owner": {"username": "team-name", "display_name": "Team Name ", "type": "team"}, "type": "group", "slug": "devleads"}]}'
I'm late to the game but figured my answer might be useful for anyone who is struggling with this like I was just now. I found the minimum syntax for a group specification is as follows:
'groups': [{'name': 'development_team'}]
So, in my context (using python) the following could be posted to the BitBucket API successfully:
request_json = {
"kind": "push",
"branch_match_kind": "glob",
"pattern": "*_bugfix",
'groups': [{'name': 'development_team'}]
}
lock_response = requests.post(api_url, json=request_json, auth=bb_creds)

Resources