You need to sign in to do that
Don't have an account?
How to invoke rest resource from another org
I have 2 orgs. I want to retrive particular account records from another org to my current org, using rest api
I'm using custom domain name on second org.
Its look like https://nara-narayana-dev-ed.my.salesforce.com/
On my current org code that respons for creating request looks like
Httprequest req=new httprequest(); String domainName='nara-narayana-dev-ed-c.eu6.visual.force.com'; String endPointURL='https://'+domainName+'/services/apexrest/Account/0015800000FvETO'; req.setendpoint(endPointURL); req.setHeader('Content-Type', 'application/xml; charset=utf-8'); req.setmethod('GET'); req.setHeader('Authorization','Bearer '+ UserInfo.getSessionId()); Http http = new Http(); HTTPResponse res = http.send(req); String response=res.getbody(); System.debug('****************res.getStatusCode();'+res.getStatusCode()); System.debug('****************res.getbody();'+res.getBody());
Rest resourse on second org looks like:(for simplicity, its now returns string 'hello')
@RestResource(urlMapping='/Account/*') global with sharing class AccountManager { @HttpGet global static String getAccountById() { RestRequest req = RestContext.request; /*String accId = req.requestURI.substring( req.requestURI.lastIndexOf('/') + 1); Account result = [ SELECT Name FROM Account WHERE Id = :accId ];*/ return 'hello'; } @HttpPost global static String createAccount(String name) { Account acc = new Account( Name = name); insert acc; return acc.Id; } }
As a result i'm getting [{"errorCode":"NOT_FOUND","message":"Could not find a match for URL /Account/0015800000FvETO"}]
in debug log and status code is 404. So I assume its something wrong with endpoint url. How to make it correct?
Also I have added this url https://nara-narayana-dev-ed.my.salesforce.com to Remote site settings
[1] http://blog.deadlypenguin.com/blog/2016/07/05/oauth-flow-for-service-users-in-salesforce/
Can you explain this more clearly please, what url should I use? What is login method?
[1] https://gist.github.com/pcon/54e8b0d7518d8fe42c79#file-bashrc_sfdc-sh-L55
https://newstechnologystuff.com/2020/05/27/test-salesforce-rest-api-using-postman/
If this answer helps you, please mark it as accepted.
Regards,
Tushar Sharma
https://newstechnologystuff.com/