cancel
Showing results for 
Search instead for 
Did you mean: 

update website problem

yosrioh
Confirmed Champ
Confirmed Champ
hello,
i am trying to update a website using the webscript but im getting a 405 response statut
what im i missing ?

<code>
def update_site (name,login,password,url_backend,url_alfresco):
       
        s = requests.Session()
        data = {'username':login, 'password'Smiley Tongueassword}
        url = url_backend+"/share/page/dologin"
        r = s.post(url, data=data)
        if (r.status_code != 200) :
            print "Incorrect login or password "
    
        url1='http://127.0.0.1:8080/alfresco/service/api/sites/'
        print url_alfresco
       
       
        jsonString = JSONEncoder().encode({
          "shortName": url_alfresco,
       
          "title" : name,
    
          })
       
        headers = {'content-type': 'application/json',"Accept":"application/json"}
        site = s.post(url1,headers=headers,data=jsonString)
        if (site.status_code != 200) :
            print " Error while creating site"
            print site.status_code
          
     
       
       
        return True;

<code>
6 REPLIES 6

niketapatel
Star Contributor
Star Contributor
Hi, Your URL is wrong. Remove last forward slash from url1.

Use this: url1='http://127.0.0.1:8080/alfresco/service/api/sites'

Not sure if your creating a site or updating. Check this OOB scripts for details - http://127.0.0.1:8080/alfresco/service/index/uri/api/sites

thx for your answer, i made some change to the code folowing the link but i still have a 405 statut responce from server.
this is the new code


update_site (name,login,password,url_backend,url_alfresco):
       
        s = requests.Session()
        data = {'username':login, 'password':password}
        url = url_backend+"/share/page/dologin"
        r = s.post(url, data=data)
        if (r.status_code != 200) :
            print "Incorrect login or password "
    
        url1='http://127.0.0.1:8080/alfresco/service/api/sites'
        print url_alfresco
       
       
        jsonString = JSONEncoder().encode({
          "shortName": url_alfresco,
       
          "title" : name
    
          })
       
        headers = {'content-type': 'application/json',"Accept":"application/json"}
        site = s.put(url1,headers=headers,data=jsonString)
        if (site.status_code != 200) :
            print " Error while creating site"
            print site.status_code
          
     
       
       
        return True;


maybe the problem is with the data because the get request works fine .

niketapatel
Star Contributor
Star Contributor
Yes, Preset is mandatory one. and description also needs to be provided so try by adding preset and description in json body.

Please make note script which you are using is to create a new site and that only creates folder structure at repository level. Its NOT fully functioned site for that you need to have surf preset object creation too! Reference: http://docs.alfresco.com/5.1/concepts/dev-extensions-share-surf-web-scripts.html

here I have provided java example to create fully functional site. You may take reference from it - http://niketa-alfresco3.blogspot.in/2016/04/create-alfresco-share-sites-through.html

hello and thx for your answer
what i want to do is to update the title of an existing website not create a new one
what webscript do i need to use instead of this one ?
and how do i use it becaus i tried many scripts and i still getting a 401 error and i folowed the same way as creation un log then i post the script

niketapatel
Star Contributor
Star Contributor
Hi, To update site detail please check this script - http://localhost:8080/alfresco/service/script/org/alfresco/repository/site/site.put

Its a PUT script and you can only update site's title, description and its visibility

URL - PUT script: http://localhost:8080/alfresco/service/api/sites/{shortname}

For your 401 error - Its authentication issue. Pleae check your Uid, and pwd.

thx again for your replies but i still have the same problem


        s = requests.Session()
        data = {'username':"admin", 'password':"admin"}
        url = "http://127.0.0.1:8080/share/page/dologin"
        r = s.post(url, data=data)
        if (r.status_code != 200) :
            print "Incorrect login or password "
    
        url1="http://127.0.0.1:8080/alfresco/service/api/sites/OdooSite50"
        print url_alfresco
       
       
        jsonString = JSONEncoder().encode({
         
       
          "title" : name
    
          })
       
        headers = {'content-type': 'application/json',"Accept":"application/json"}
        site = s.put(url1,headers=headers,data=data)
        if (site.status_code != 200) :
            print " Error while creating site"
            print site.status_code
          
     
       
       


the first part works fine i got a 200 responce so the connection is ok but in the 2cd part when i execute the put i get a 401 responce i dont understand the reason