0

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.

1 Answer 1

0

The problem was solved simply. It is necessary to connect the application with the restresource apex class and pass the post - request to it. https://www.greytrix.com/blogs/salesforce/2018/06/04/creating-an-endpoint-in-salesforce-and-using-rest-api-to-externally-access-it/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .