AnsweredAssumed Answered

Alfresco Service API

Question asked by marianandan on Jun 24, 2013
Latest reply on May 12, 2014 by aaron_bru
Hi All,

I am trying to update the Person property "emailFeedDisabled" using Alfresco Service API

call (Alfresco Version Alfresco Enterprise 4.0.2) , but It never allowed me to update the

property value.

I am using HttpWebRequest PUT method through a C# code, but the property always remains

unchanged.

Please find the below C# code:

AlfrescoAdmin.aspx.cs
———————-

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

public partial class AlfrescoAdmin : System.Web.UI.Page
{

protected void btnPost_Click(object sender, EventArgs e)
{
txtResponse.Text = "";
if (String.IsNullOrEmpty(txtAdminUser.Text))
{
lblError.Text = "Please enter a admin user name";
return;
}
else if (String.IsNullOrEmpty(txtPassword.Text))
{
lblError.Text = "Please enter a admin password";
return;
}
lblError.Text = "";
string adminUser = txtAdminUser.Text;
string adminPass = txtPassword.Text;
string userName = txtUser.Text;
string typeOfAPI = ddlAPI.SelectedValue;



string response = getResponse(typeOfAPI, adminUser, adminPass, userName);
txtResponse.Text = response;
}

protected string getResponse(string typeOfAPI, string adminUser, string adminPass, string

userName)
{
string url = "";
string postData = "";
bool chkBoxStatus = true;
if ("notification".Equals(typeOfAPI))
{
url = "http://youralfrescowebsite.com:8080/alfresco/service/api/people/" + userName;
postData = "{ \"emailFeedDisabled\": " + !chkOnOff.Checked + "}";

return postDataToServer("PUT", postData, url, adminUser, adminPass);

}
else
{
if ("sites".Equals(typeOfAPI))
{
url = "http://youralfrescowebsite.com:8080/alfresco/service/api/people/" + userName +

"/sites";
}
else if ("groups".Equals(typeOfAPI))
{
url = "http://youralfrescowebsite:8080/alfresco/service/api/groups/" + userName
+ "/children?authorityType=USER";
}
else if ("groupsearch".Equals(typeOfAPI))
{
url = "http://youralfrescowebsite:8080/alfresco/service/api/groups?shortNameFilter=" +

userName;
}
return postDataToServer("GET", "", url, adminUser, adminPass);
}
}

protected string postDataToServer(string method, string postData, string url,
string adminUser, string adminPass)
{
string _auth = string.Format("{0}:{1}", adminUser, adminPass);
string _enc = Convert.ToBase64String(Encoding.ASCII.GetBytes(_auth));
string _cred = string.Format("{0} {1}", "Basic", _enc);

/* WebProxy proxyObject = new WebProxy("http://youralfrescowebsite:8080/',true);*/
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
/* req.Proxy = proxyObject;*/

req.Timeout = 20 * 60 * 1000;
req.ReadWriteTimeout = 20 * 60 * 1000;
req.Method = method;
req.ContentType = "application/json;charset=UTF-8";
req.ContentLength = postData.Length;
req.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequired;
req.Headers[HttpRequestHeader.Authorization] = _cred;
string response = null;


Stream dataStream=null;
try
{
if ("POST".Equals(method) || "PUT".Equals(method))
{

using (StreamWriter sw = new StreamWriter(req.GetRequestStream(),

System.Text.Encoding.ASCII))
{

sw.Write(postData);
sw.Flush();

}



}
using (StreamReader sr = new StreamReader(req.GetResponse().GetResponseStream()))
{
response = sr.ReadToEnd();
}
req.GetResponse().Close();

}
catch (Exception e)
{
txtResponse.Text = e.Message;
response = "Exception: " + e.Message + "; " + e.ToString();
}

return response;
}

protected void ddlAPI_SelectedIndexChanged(object sender, EventArgs e)
{
txtUser.Text = "(case sensitive)";
txtResponse.Text = "";
lblError.Text = "";
chkOnOff.Visible = false;
if (ddlAPI.SelectedValue.Equals("groups"))
{
lblUser.Text = "Group Name:";
lblExample.Text = "(ex: site_OCP3MIntegration_SiteManager)";
}
else if (ddlAPI.SelectedValue.Equals("sites"))
{
lblUser.Text = "User Name:";
lblExample.Text = "(ex: Marianandan Arockias)";
}
else if (ddlAPI.SelectedValue.Equals("groupsearch"))
{
txtUser.Text = "";
lblUser.Text = "Group Name:";
lblExample.Text = "(ex: ocp)";
}
else if (ddlAPI.SelectedValue.Equals("notification"))
{
chkOnOff.Visible = true;
txtUser.Text = "";
lblUser.Text = "User Name:";
lblExample.Text = "(ex: Marianandan Arockias)";
}
}
}

Below is the API Result:

{
"url": "\/alfresco\/service\/api\/person\/marianandanarockiasamy",
"userName": "marianandanarockiasamy",
"enabled": true,
"firstName": "Marianandan",
"lastName": "Arockiasamy",
"jobtitle": "Consultant",
"organization": "",
"location": null,
"telephone": null,
"mobile": null,
"email": "marockiasamy@avery.com",
"companyaddress1": null,
"companyaddress2": null,
"companyaddress3": null,
"companypostcode": null,
"companytelephone": null,
"companyfax": null,
"companyemail": null,
"skype": null,
"instantmsg": null,
"userStatus": null,
"userStatusTime": null,
"googleusername": null,
"quota": -1,
"sizeCurrent": 0,
"emailFeedDisabled": false,
"persondescription": null
}

In the above result,

"emailFeedDisabled": false is the property I am trying to change from false to true. But

it is not working.

Please help me to fix this issue.

Regards
-Mari

Outcomes