You need to sign in to do that
Don't have an account?
Pinkey
Session expired or invalid on ajax POST
anyone know why below code errors out with a message "Session expired or invalid"
.ajax({
url: '/services/data/v28.0/sobjects/Attachment/',
type: 'POST',
data: '{"ContentType": "image/tiff", "Name" : "REST_API_Application", "ParentId": "'+self.model.get('Id')+'", "Body": "'+responseData.data+'"}',
contentType: 'application/json',
processData: false,
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer '+sessionId);
}
session id is defined in VF page
var sessionId = '{!$Api.Session_ID}';
.ajax({
url: '/services/data/v28.0/sobjects/Attachment/',
type: 'POST',
data: '{"ContentType": "image/tiff", "Name" : "REST_API_Application", "ParentId": "'+self.model.get('Id')+'", "Body": "'+responseData.data+'"}',
contentType: 'application/json',
processData: false,
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer '+sessionId);
}
session id is defined in VF page
var sessionId = '{!$Api.Session_ID}';
A SessionId requested from a Visualforce page on the domain c.podInstance.visual.force.com won't be a "first class" citizen in the way that on from podinstance.salesforce.com or an OAuth flow would be. There are restrictions on what API calls it can be used for.