cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Service API

marianandan
Champ in-the-making
Champ in-the-making
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
4 REPLIES 4

aaron_bru
Champ in-the-making
Champ in-the-making
I am experiencing the same issue on 4.2c Community edition.
There are no error messages in the logs, I'm making the PUT request using curl, the other changes work fine except for the emailFeedDisabled:

curl –user "…" -X PUT –header "Content-Type: application/json" –data '{firstName: "Newfirstname", lastName: "Newlastname", emailFeedDisabled: false}' http://localhost:8080/alfresco/service/api/people/username

Is there any other alternative way to change this setting? I don't see any in the UI. Looks like I'm gonna have to resort to the database.

romschn
Star Collaborator
Star Collaborator
Login to alfresco share. Open the user menu on the toolbar and click My Profile and go to Notifications page.
Disable Email Notification Feed and click OK.
This would disable email updates such as recent site activities and site invitations.

Hope this helps.

aaron_bru
Champ in-the-making
Champ in-the-making
Thanks for replying. I'm trying to change the setting for another user. I am an admin, however the setting is not available in the Admin Console.

I haven't managed to find the setting in the database or the userStore, does anyone know where it is?
As a last resort I will copy their password hash, change their password, log in as the user and then change the password back.

aaron_bru
Champ in-the-making
Champ in-the-making
I later found a way to do this, You can actually access the notifications page from an admin accouint by manually generating the url, ie
localhost:8080/share/page/user/{username}/user-notifications
To do it programmatically, it would simply be a matter of generating the correct POST request.

[edit]
Turns out that wasn't quite correct, but you can do it like this (have tested):
curl –user '…' –header "Content-Type: application/json" –data '{"username": "user", "properties": {"cm:emailFeedDisabled": true}}' http://localhost:8080/alfresco/service/slingshot/profile/userprofile