Trying to use self client to query contact by email address.
I tried following
aaaserver.profile.ALL,ZohoCRM.modules.ALL,ZohoCRM.bulk.ALL,ZohoCRM.settings.ALL,ZohoCRM.settings.fields.ALL
OR
aaaserver.profile.all,ZohoCRM.modules.all,ZohoCRM.bulk.ALL,ZohoCRM.settings.all,ZohoCRM.settings.fields.all
but I can not get it work, I keep getting error "invalid oauth scope to access this URL"
<?php
define('ROOT_HOME', '');
require_once ROOT_HOME . 'vendor/autoload.php';
use com\zoho\api\authenticator\OAuthBuilder;
use com\zoho\api\authenticator\store\FileStore;
use com\zoho\crm\api\dc\USDataCenter;
use com\zoho\crm\api\InitializeBuilder;
use com\zoho\crm\api\query\APIException;
use com\zoho\crm\api\query\BodyWrapper;
use com\zoho\crm\api\query\QueryOperations;
use com\zoho\crm\api\query\ResponseWrapper;
use com\zoho\crm\api\SDKConfigBuilder;
use com\zoho\crm\api\UserSignature;
use com\zoho\crm\api\util\Choice;
//use com\zoho\crm\api\query\Query;
$environment = USDataCenter::PRODUCTION();
$token = (new OAuthBuilder())
->clientId("1000.CLIENT_ID")
->clientSecret("secr")
->grantToken('1000.portal_token')
->build();
$tokenstore = new FileStore("/tokens/data/token.txt");
$autoRefreshFields = false;
$pickListValidation = false;
$connectionTimeout = 10;
$timeout = 10;
$enableSSLVerification = false;
$configInstance = (new SDKConfigBuilder())
->autoRefreshFields($autoRefreshFields)
->pickListValidation($pickListValidation)
->sslVerification($enableSSLVerification)
->connectionTimeout($connectionTimeout)
->timeout($timeout)->build();
$sdk = (new InitializeBuilder());
$sdk->environment($environment)
->token($token)
->store($tokenstore)
->user($user)
->SDKConfig($configInstance)
->initialize();
//$token->refreshAccessToken($user, $tokenstore);
$queryOperations = new QueryOperations();
// Create a new BodyWrapper instance to set the query
$bodyWrapper = new BodyWrapper();
// Set the select query in the body wrapper
$bodyWrapper->setSelectQuery($query);
// Execute the query and get the response
$response = $queryOperations->getRecords($bodyWrapper);
if ($response != null) {
echo("Status Code: XXX" . $response->getStatusCode() . "\n");
if ($response->isExpected()) {
$responseHandler = $response->getObject();
if ($responseHandler instanceof ResponseWrapper) {
$responseWrapper = $responseHandler;
$records = $responseWrapper->getData();
foreach ($records as $record) {
echo("Record ID: " . $record->getId() . "\n");
$createdBy = $record->getCreatedBy();
if ($createdBy != null) {
echo("Record Created By User-ID: " . $createdBy->getId() . "\n");
echo("Record Created By User-Name: " . $createdBy->getName() . "\n");
echo("Record Created By User-Email: " . $createdBy->getEmail() . "\n");
}
echo("Record CreatedTime: " . $record->getCreatedTime() . "\n");
$modifiedBy = $record->getModifiedBy();
if ($modifiedBy != null) {
echo("Record Modified By User-ID: " . $modifiedBy->getId() . "\n");
echo("Record Modified By User-Name: " . $modifiedBy->getName() . "\n");
echo("Record Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
}
echo("Record ModifiedTime: " . $record->getModifiedTime() . "\n");
echo("Record Field Value: " . $record->getKeyValue("Last_Name") . "\n"); // FieldApiName
echo("Record KeyValues: \n");
foreach ($record->getKeyValues() as $keyName => $value) {
if ($value != null) {
if ((is_array($value) && sizeof($value) > 0) && isset($value[0])) {
echo("Record KeyName : " . $keyName . "\n");
$dataList = $value;
foreach ($dataList as $data) {
if (is_array($data)) {
echo("Record KeyName : " . $keyName . " - Value : \n");
foreach ($data as $key => $arrayValue) {
echo($key . " : " . $arrayValue);
}
} else {
print_r($data);
echo("\n");
}
}
} else {
echo("Record KeyName : " . $keyName . " - Value : " . print_r($value));
echo("\n");
}
}
}
}
$info = $responseWrapper->getInfo();
if ($info != null) {
if ($info->getCount() != null) {
echo("Record Info Count: " . $info->getCount() . "\n");
}
if ($info->getMoreRecords() != null) {
echo("Record Info MoreRecords: " . $info->getMoreRecords() . "\n");
}
}
} else if ($responseHandler instanceof APIException) {
$exception = $responseHandler;
echo("Status: " . $exception->getStatus()->getValue() . "\n");
echo("Code: " . $exception->getCode()->getValue() . "\n");
echo("Details: ");
if ($exception->getDetails() != null) {
echo("Details: \n");
foreach ($exception->getDetails() as $keyName => $keyValue) {
echo($keyName . ": " . $keyValue . "\n");
}
}
echo("Message : " . ($exception->getMessage() instanceof Choice ? $exception->getMessage()->getValue() : $exception->getMessage()) . "\n");
var_dump($exception);
}
} else {
print_r($response);
}
}
?>