I'm trying to save an AuraDefinition from within a native Visualforce app. Therefore I following @MartyC. suggestion here: Lightning ToolingAPI BETA Documentation
As an unfortunate PATCH requests seems not to be possible from APEX according to this: How can I make a PATCH HTTP Callout from Apex?
So I'm trying to go with JavaScript but having issues with the endpoint URL. Assume 0Ad20000000PAw7CAG is an valid Id for an AuraDefinition TestApp.css
of the Bundle TestApp
and app.session.idMergeField contains a valid session-Id.
saveAura = function() {
var binding = new XMLHttpRequest();
var request = ' { "Source" : ".THIS { color: red; }" } ';
binding.open('PATCH', 'https://elfcodefusion.eu0.visual.force.com/sobjects/AuraDefinition/0Ad20000000PAw7CAG/');
//binding.open('PATCH', ' https://emea.salesforce.com/sobjects/AuraDefinition/0Ad20000000PAw7CAG/');
binding.setRequestHeader('Authorization', 'Bearer ' + app.session.idMergeField );
binding.setRequestHeader('Content-Type', 'application/json');
binding.onreadystatechange = function() {
if(this.readyState==4) { console.log(this.response); }
}
binding.send(request);
}
No matter what URL I try, I got one of the following errors:
https://elfcodefusion.eu0.visual.force.com
==> 302 Found (it seems that it tries to reroute tohttps://emea.salesforce.com/sobjects/AuraDefinition/
but fails)https://emea.salesforce.com
==>Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://emea.salesforce.com/sobjects/AuraDefinition/0Ad20000000PAw7CAG/
Any ideas on how to make that PATCH work? Is it possible at all? If not, what would be the next best approach to try? SOAP Tooling flavor? Or only MetadataAPI?