Closed techlover11 closed 8 months ago
What was the actual error message you got? It could be that the OAuth is working fine, but you are using the API in some way that isn't compatible.
There is no actual error message, just a generic error page ""Sorry the page you have requested was not found"
The interesting thing: it is a Zoho CRM page and not a Zoho Recruit error page.
This is why one idea is that the request URL / endpoint is somehow using a CRM endpoint instead of Recruit endpoint
<html><head><title>Zoho CRM - Error</title><link rel="SHORTCUT ICON" href="https://static.zohocdn.com/crm/images/favicon_cbfca4856ba4bfb37be615b152f95251_.ico" /><link href="https://static.zohocdn.com/crm/CRMClient/css/default_theme_23524a7da62146af9811df20b1f50421_.css" rel="stylesheet" type="text/css"/><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="Pragma" content="no-cache">
<div class="crmErrorPgCont crmErrorHeight" data-zcqa="crm_error_page" data-errormessage="Sorry the page you have requested was not found"><div class="crmErrorPgBody"><div class="crmErrorPgImgContr"><!-- <span class="crmErrorPgImg"></span> -->
<img class="crmErrorPgImg" data-image-mode='true' src='https://static.zohocdn.com/crm/images/crm-iam-errorPage_lightmode_2eb563c9ea6d989a69e2be6276245761_.png'/></div><div class="crmErrorInfoSection"><p class="crmErrorPgErrText1">Invalid URL</p>
<p class="crmErrorPgErrText2">Unable to process your request as the URL <span class='crmErrorUrl'>/recruit/v2/org</span> is invalid.</p> <!-- No I18N -->
<a class="crmErrorPgHomeLink" href="/crm/ShowHomePage.do">
<button data-zcqa="home_errorPage" class = "primarybtn" >Go to Home page</button>
</a></div></div><div class="crmErrorPgfooter"><div class="crmErrorPgfooterCont"><img src="https://static.zohocdn.com/crm/CRMClient/images/crm_logo_04536e35e8162d631b95cf42593491cd_.svg" alt="CRM" class="crmLogoImg"></div><span class="crmErrorPgfooterTxt">© 2024 Zoho Corp.All rights reserved.</span></div></div></body></html>
Check out the these 3 calls (without being logged in) https://recruit.zoho.eu/recruit/v2/org (looks legit) https://crm.zoho.eu/recruit/v2/org (looks like the generic error page from above) ---> my assumption is that this call is somehow constructed https://crm.zoho.eu/crm/v2/org (looks legit)
(I expected the first one, but potentially get the second one - but cannot prove this)
(solved)
I kind of solved the issue myself.
Here is an explanation for everybody else:
My code / the boilerplate code calls api_domain + '/recruit/v2/org';
However, api_domain from bearer token ALWAYS seems to be https://www.zohoapis.eu
BUT https://www.zohoapis.eu/recruit/v2/org seems to result in a generic error So I had to call https://recruit.zoho.eu/recruit/v2/org explicitly in order to not get the error
---> For non Zoho CRM use cases, you cannot use the built in var url = apiServer + '/recruit/v2/org';
function recruitOrg() {
var service = getService_();
if (service.hasAccess()) {
var url = 'https://recruit.zoho.eu/recruit/v2/org';
var response = UrlFetchApp.fetch(url, {
method: 'get',
headers: {
'Authorization': 'Bearer ' + service.getAccessToken(),
'Content-Type': 'application/json'
},
muteHttpExceptions: true
});
// Log the status code and headers to understand the response better
Logger.log(response.getResponseCode());
Logger.log(response.getHeaders());
// Log the raw content of the response
Logger.log(response.getContentText());
// Attempt to parse the response as JSON, with error handling
var result;
try {
result = JSON.parse(response.getContentText());
// Log the parsed JSON response
Logger.log(JSON.stringify(result, null, 2));
} catch (e) {
Logger.log('Failed to parse response as JSON:');
Logger.log(response.getContentText());
// Optionally, handle the error as needed
}
} else {
var authorizationUrl = service.getAuthorizationUrl();
Logger.log('Open the following URL and re-run the script: %s', authorizationUrl);
}
}
Hello team,
I have successfully implemented OAuth2 authentication with ZohoCRM and have been able to retrieve data without issues using the following endpoint and scope:
/crm/v2/org
ZohoCRM.org.all
However, when attempting to use an identical script with a different endpoint and scope for ZohoRecruit, the script fails to work:
/recruit/v2/org
ZohoRecruit.modules.READ
The OAuth2 response seems to be successful, as I receive the following tokens and parameters:
To further investigate, I utilized Postman to authenticate with OAuth2 for the ZohoRecruit endpoint
/recruit/v2/org
with the scopeZohoRecruit.modules.READ
, and it worked as expected.In Postman, I used the following parameters, which may be relevant for troubleshooting:
https://recruit.zoho.eu/recruit/v2/org
https://accounts.zoho.eu/oauth/v2/auth?access_type=offline&prompt=consent
https://accounts.zoho.eu/oauth/v2/token
I am seeking guidance on the following:
I appreciate any insights or suggestions you can provide.
Thank you!
[Code used in the script]