0

We want to get attachment BLOB data using the standard salesforce API. See the API Docs link below. ([https://developer.salesforce.com/docs/api-explorer/sobject/Attachment/get-attachment-id])

We are using salesforce as a backend and we have a requirement where we have to get the attachment body using community user login by calling Salesforce standard Sobject API (API Details are provided in the above link). We are passing authorization/access token of the community user to get the attachment data.The token is working for custom web services.

We tried through postman application also but we are getting 404 error. I am giving the complete details below which I have used for the Postman.

Salesforce URL - https://community_URL/services/data/v46.0/sobjects/Attachment/AttachmentId

Headers:

[{"key":"Content-Type","value":"application/json; charset=utf-8","description":""}]

[{"key":"crossDomain","value":"true","description":""}]

[{"key":"Authorization","value":"Bearer Generated_Access_Token","description":""}]

After calling the Salesforce API from Postman/JavaScript, we are getting following reponse.

[ { "errorCode": "NOT_FOUND", "message": "The requested resource does not exist" } ]

I have checked the community setting where we checked "Let customer users access notes and attachments" settings to allow community user to access.

We have Public read/write sharing setting for the object where we have added attachment.

If we call same (sObject) URL from workbench then we are getting the prorper response. Even, when we tried to call that API through postman using admin "Access Token" then it is returning the result.

There might be some security setting missing. Please help me to solve this. Thanks in advance

0

While it is true that some REST resources are available at either https://yourinstance.salesforce.com or https://mydomain.my.salesforce.com or https://mycommunity.<pod>.force.com, the canonical service endpoint for all out of the box platform REST resources is https://yourinstance.salesforce.com or https://mydomain.my.salesforce.com . The latter works if you have My Domain enabled in your org.

You can obtain the oAuth access token via your community user identity from either https://test.salesforce.com (all Sandboxes) or https://login.salesforce.com (Production) and then use this token with one of the two canonical service endpoints above. Your full REST resource URL becomes either

  • https://yourinstance.salesforce.com/services/data/<api version>/sobjects/Attachment/{Id} or
  • https://mydomain.my.salesforce.com/services/data/<api version>/sobjects/Attachment/{Id}

The other possibility is indeed related to permissions. Whatever user identity you're using to obtain the oAuth access token that you call the API with might not have access to a particular attachment. If this is the case, the error message returned by SF is

[ {
  "errorCode" : "NOT_FOUND",
  "message" : "Provided external ID field does not exist or is not accessible: 123"
} ]

...which is different from the error message in your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.