I have been struggling for a couple of days creating an hybrid app with salesforce mobile sdk with the ability to change the avatar.
I tried using methods from force.js with networkPlugin(reqest):
var params = {
path: 'services/data/v46.0/connect/user-profiles/me/photo',
method: 'POST',
endPoint: '/',
data: <binary data>
};
force.request(
params,
function successHandler() {
alert('Success');
},
function errorHandler(error) {
console.log(error);
alert('errorUpdate' + JSON.stringify(error));
},
true,
false
);
And i get error :
[{"message":"The requested API is not available to portal users. You may need to specify a community for portal user access.","errorCode":"FUNCTIONALITY_NOT_ENABLED"}] I/chromium: [INFO:CONSOLE(168)] "[{"message":"The requested API is not available to portal users. You may need to specify a community for portal user access.","errorCode":"FUNCTIONALITY_NOT_ENABLED"}]", source: file:///android_asset/www/index.html (168)
Also i try send POST query with XMLHttpRequest:
var request = new XMLHttpRequest();
var url = 'https:[my-Salesforce-instance-name]/services/data/v47.0/connect/user-profiles/me/photo';
var boundaryString = 'a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq';
var boundary = '--' + boundaryString;
var body = '';
var binaryContent = exampleBinaryContent;
body += 'Authorization: OAuth [my-session-id]' + '\r\n';
body += 'Content-Type: multipart/form-data; boundary=' + boundaryString + '\r\n';
body += 'Accept: application/json' + '\r\n';
body += 'Host: [my-Salesforce-instance-name]' + '\r\n';
body += 'Expect: 100-continue';
body += '\r\n';
body += boundary + '\r\n';
body += 'Content-Disposition: form-data; name="json"' + '\r\n';
body += 'Content-Type: application/json; charset=UTF-8' + '\r\n';
body += '\r\n';
body += '{ "cropX" : "0", "cropY" : "0", "cropSize" : "200"}\r\n';
body += '\r\n';
body += boundary + '\r\n';
body += 'Content-Disposition: form-data; name="fileUpload"; filename="myPhoto.jpg"' + '\r\n';
body += 'Content-Type: application/octet-stream; charset=ISO-8859-1' + '\r\n';
body += 'Content-Transfer-Encoding: binary' + '\r\n';
body += '\r\n';
body += binaryContent + '\r\n';
body += '\r\n';
body += boundary + '--'
request.open("POST", url);
request.onload = function() {
console.log(request.status)
console.log(request.statusText)
console.log(request.responseText)
};
request.error = function() {
console.log(request.status)
console.log(request.statusText)
console.log(request.responseText)
};
request.send(body);
And i get error :
[{"message":"The Chatter Connect API is not enabled for this organization or user type.","errorCode":"API_DISABLED_FOR_ORG"}]
What am I missing? Is there another step I've missed? In case it isn't obvious,I'm brand new to Android SDK dev, so please ask any "obvious" questions. Perhaps a problem with user rights? How to turn on Chatter for community page? API Enable is checked.