REST API and curl to add a user to a site

cancel
Showing results for 
Search instead for 
Did you mean: 
wssupport
Member II

REST API and curl to add a user to a site

Hi everyone, so trying to programatically add a user to a site and failing currently. Saw some examples of using the REST API and trying to post with curl. I get no response back from the command. If I change the URL in the command I get a 404 back though, so it's as if the URL is correct.

From the alfresco box itself (Community version 6.1.2 in docker on Ubuntu 18.04)

curl -X POST -uadmin:mypass "http://localhost:8080/share/alfresco/service/api/sites/testsite/memberships" -H"content-type: application/json" -d "{"role":"SiteManager","person":{"userName" : "usernametoadd"}}"

 

Can anyone spot what I am doing wrong please? Or advise me of an alternative way to programatically add a user to a site? I have over 1000 sites to modify so I need to do it in code thanks.

10 Replies
cristinamr
Advanced

Re: REST API and curl to add a user to a site

Hi!

I'm more comfortable doing this kind of task through javascript console.

If you consider use that, the script should be something like this:

var group = people.getGroup("GROUP_site_testsite_SiteCollaborator");
var authority = people.getPerson("user.name"); 
people.addAuthority(group,authority);

You can play with Javascript api to get reports about this kind of actions.

Cheers!

--
VenziaIT: helping companies since 2005! Our ECM products: AQuA & Seidoc
wssupport
Member II

Re: REST API and curl to add a user to a site

Thanks, this javascript console looks great but I'm using a dockerised Alfresco which seems like a nightmare to install amps onto, I've read around about this but I cannot find any simple clear instruction on how to add these two amps to my docker instance for Alfresco.

 

This is partly why I am trying to do this without installing any addons. It would be could if I could use your example above and submit this javascript with curl.

wssupport
Member II

Re: REST API and curl to add a user to a site

 

ok I think my URL is incorrect below. Basically I cannot access http://localhost:8080/alfresco so it seems I cannot use any API calls. Alfresco is working perfectly though (on /share). What have I missed?

 

curl -X POST -uadmin:mypass "http://localhost:8080/share/alfresco/service/api/sites/testsite/memberships" -H"content-type: application/json" -d "{"role":"SiteManager","person":{"userName" : "usernametoadd"}}"

 

I try this below but I get a 404! So it seems I cannot access the API URL, how do I know what this should be on my install?

 

curl -X POST -uadmin:mypass "http://localhost:8080/alfresco/service/api/sites/testsite/memberships" -H"content-type: application/json" -d "{"role":"SiteManager","person":{"userName" : "usernametoadd"}}"

  

EddieMay
Community Manager
Community Manager

Re: REST API and curl to add a user to a site

Hi @wssupport 

Have you had a look at the ReST API tutorials? These have Postman examples that you can use to test against your repository. Postman will also give code examples in various languages. Might be worth looking at?

HTH,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!
wssupport
Member II

Re: REST API and curl to add a user to a site

Hi thanks yes I have been looking at that, the problem I have right now is that my /alfresco URL is not working on this install. I have another install which /alfresco works on though so it must be something not right with my install.

 

I am using docker which is the main difference on the non-working one. So basically I need help on getting the /alfresco URL working on a dockerised Alfresco. Searching all day not yet finding any answers. I think once I get the API URL working I can do what I need.

jpotts
Professional

Re: REST API and curl to add a user to a site

When you say "Share is working perfectly" what do you mean? Can you log in to Share and create content? If so, that means Alfresco is up, which means you might just have some sort of networking issue. If you go to http://localhost:8180/share and you see the Share login but you cannot log in, that just means the Share container and app is up but tells you nothing about the state of Alfresco.

What do you see when you run docker ps?

Do you have any other Tomcat instances running on your host machine that might be conflicting with the 8080 port the Alfresco container is trying to bind to?

Is there anything in the logs that indicates that the ACS container did not start or that Tomcat had a problem?

wssupport
Member II

Re: REST API and curl to add a user to a site

Hi I mean alfresco is working nicely and in constant use as I write this by over 1000 users adding content Smiley Happy

There is no other conflicting tomcat instance.  I basically cannot use the /alfresco URL so I cannot use the API like I can on other installs I have (not docker ones). I feel like this might be some misconfiguration or something extra I need to run in docker? - here is the output of docker ps

 

CONTAINER ID        IMAGE                                                     COMMAND                  CREATED             STATUS              PORTS                                                                                                NAMES
854fc0f3db10        alfresco/alfresco-search-services:1.4.3.3                 "/bin/sh -c '$DIST_D…"   8 months ago        Up 23 hours         10001/tcp, 0.0.0.0:8083->8983/tcp                                                                    docker-compose_solr6_1
c44c0a57ebc9        alfresco/alfresco-content-repository-community:6.1.2-ga   "catalina.sh run -se…"   8 months ago        Up 23 hours         0.0.0.0:8100->8100/tcp, 0.0.0.0:8082->8080/tcp                                                       docker-compose_alfresco_1
ea8b5edd624f        alfresco/alfresco-activemq:5.15.6                         "/bin/sh -c './init.…"   9 months ago        Up 23 hours         0.0.0.0:5672->5672/tcp, 0.0.0.0:8161->8161/tcp, 0.0.0.0:61613->61613/tcp, 0.0.0.0:61616->61616/tcp   docker-compose_activemq_1
c269125e3867        postgres:10.1                                             "docker-entrypoint.s…"   9 months ago        Up 20 hours         0.0.0.0:5432->5432/tcp                                                                               docker-compose_postgres_1
0be38de24f78        alfresco/alfresco-share:6.2.2                             "/usr/local/tomcat/s…"   9 months ago        Up 23 hours         8000/tcp, 0.0.0.0:8080->8080/tcp                                                                     docker-compose_share_1
wssupport
Member II

Re: REST API and curl to add a user to a site

Hi, there is no conflicing tomcat, and alfresco itself is working nicely with many users using it as I write this and adding content (for years).

 

docker ps shows these images (i tried to post this 3 times and it gets deleted so I will just list)

 

alfresco/alfresco-search-services:1.4.3.3
alfresco/alfresco-content-repository-community:6.1.2-ga
alfresco/alfresco-activemq:5.15.6
postgres:10.1
alfresco/alfresco-share:6.2.2

all are runnning. 

 

Is there something special I need to do on docker to make the /alfresco URL work? It works on my non-docker other installs fine.

 

On a working install /alfresco shows a screen with version number of alfresco and some links. On this docker one it says 404.

 

cristinamr
Advanced

Re: REST API and curl to add a user to a site

Could you please verify which ports have you configured for /alfresco ? If you are using docker you may have on your docker-compose.yml. If you don't  mind, you can share with us its content, so we can see if there is any error (related to /alfresco config).

Cheers!

--
VenziaIT: helping companies since 2005! Our ECM products: AQuA & Seidoc