PHP vTiger Issue creating tickets with vtwsclib - php

I am trying to figure out how to programmatically create a "HelpDesk" ticket in vTiger using its Web Services api. I am currently using the official vtwsclib v1.5 php library. The log in, appears to succeed and I can also successfully perform a doDescribe on the module, however doCreate returns 'false' no matter what I do. Sample below. Am I missing anything?
$url = 'http://vtiger.mydomain.com/';
$client = new Vtiger_WSClient($url);
$login = $client -> doLogin('systemuser', 'O8nFgnotrealkey');
if (!$login)
echo 'Login Failed';
else {
$module = "HelpDesk";
$record = $client -> doCreate($module, Array(
'assigned_user_id' => "21",
'parent_id' => "91",
'ticket_title' => "test",
'ticketstatus' => "Open"
));
if ($record) {
$recordid = $client -> getRecordId($record['id']);
}
}
Retruns:
$record: bool(false)

Found it:
Looks like if you leave 'assigned_user_id' blank, it will populate it with the correct 'assigned_user_id' for yourself. The 'assigned_user_id' can also be retrieved for your own account from the login response and it appears like this {module_id}x{user_id}. ie: "3x16".
All id's ('parent_id', 'assigned_user_id', 'related_to' etc etc etc) appear to be in a 'NxN' format.

Related

Outlook - OAuth 2 - Fail to retrieve access token, grant_type=password is unsupported, only authorization_code and refresh_token are

I'm currently trying to implement a way to synchronize my PHP App calendar with the Outlook calendar of my clients, using Azure API.
I use OAuth2 and the custom Microsoft provider by Steven Maguire.
I currently run in an issue where I get an error in my response :
{"error":"unsupported_grant_type","error_description":"The provided value for the input parameter 'grant_type' is not valid. Expected values are the following: 'authorization_code', 'refresh_token'."}
I'm having trouble understanding why the grant_type password is not supported, even though it says on the documentation of Azure that it is.
The request looks like this :
client_id=44bef79b-**********************&client_secret=H****************&redirect_uri=https%3A%2F%2F192.168.1.123%2Fmapeyral%2Fcalendarsync.php&grant_type=password&username=******************&password=***********&scope=openid%20profile%20offline_access%20Calendars.ReadWrite
The Authorize url used is : https://login.live.com/oauth20_token.srf
as defined in the Steven Maguire provider.
The header contains the content-type application/x-www-form-urlencoded (I've seen a lot of post where this was what caused the error).
Some of my code :
$this->provider = new Microsoft([
'clientId' => MicrosoftGraphConstants::CLIENT_ID,
'clientSecret' => MicrosoftGraphConstants::CLIENT_SECRET,
'redirectUri' => MicrosoftGraphConstants::REDIRECT_URI,
'urlAuthorize' => MicrosoftGraphConstants::AUTHORITY_URL . MicrosoftGraphConstants::AUTHORIZE_ENDPOINT,
'urlAccessToken' => MicrosoftGraphConstants::AUTHORITY_URL . MicrosoftGraphConstants::TOKEN_ENDPOINT,
'urlResourceOwnerDetails' => MicrosoftGraphConstants::RESOURCE_ID,
'scope' => MicrosoftGraphConstants::SCOPES
]);
if ($_SERVER['REQUEST_METHOD'] === 'GET' && !isset($_GET['code']))
{
// Try getting access token from Database
$workingAccount = $GLOBALS['AppUI']->getState('working_account');
if (isset($workingAccount))
{
// DB access
$DB = new DatabaseConnection();
$dbAccess = $DB->getConnection();
$contactData = DBUserUtils::getContactDataFromEmail($GLOBALS['AppUI']->getState('working_account'), $dbAccess);
// If at least one user contact found
if (!is_null($contactData))
{
// If has refresh token => fill session variables using refresh token
if (!is_null($contactData['contact_refreshToken']))
{
log_msg('debug.log', 'Has refresh token');
$GLOBALS['AppUI']->setState('preferred_username', $contactData['contact_email']);
$GLOBALS['AppUI']->setState('given_name', $contactData['contact_first_name']." ".$contactData['contact_last_name']);
// Get new tokens
$newAccessToken = $this->provider->getAccessToken('refresh_token', [
'refresh_token' => $contactData['contact_refreshToken']
]);
// Update tokens and DB
$GLOBALS['AppUI']->setState('refresh_token', $newAccessToken->getRefreshToken());
$GLOBALS['AppUI']->setState('access_token', $newAccessToken->getToken());
DBOAuthUtils::updateTokenForUser($contactData['contact_id'], $GLOBALS['AppUI']->getState('refresh_token'), $dbAccess);
$this->redirectTo($redirectURL);
}
else
{
$this->getAccessToken();
}
}
else
{
$this->getAccessToken();
}
}
else
{
$this->getAccessToken();
}
function getAccessToken(){
$accessToken = $this->provider->getAccessToken('password', [
'username' => '*************',
'password' => '********',
'scope' => MicrosoftGraphConstants::SCOPES
]);
}
During the first try it doesn't pass the if (isset($workingAccount)) condition (as expected) and go straight to the last else.
Code is a bit ugly for now but I don't think it has an impact on my problem.
Any help would be appreciated !
Thanks
Edit : added code
That helped me, the problem was that I need to use Azure Active Directory and not Azure AD 2.0.
Problem solved !

Brandbank API PHP Extract Data

I am working on a project that requires access to Brandbank API, however their documentation seems pretty limited as to how to access their information.
I have been given access keys and the documentation seems to direct you to extract data via SOAP siting this link https://api.brandbank.com/svc/feed/extractdata.asmx?WSDL
Can anyone provide an example of how to access the product feed of this API?
At a minimum you will need code that looks like this:
$wsdl = "https://api.brandbank.com/svc/feed/extractdata.asmx?WSDL";
try {
$soapclient = new SoapClient($wsdl, array(
'soap_version' => SOAP_1_1,
'trace' => 1,
'exceptions' => true,
)
);
$parameters = new stdClass();
$response = $soapclient->GetUnsentProductData($parameters);
} catch (Exception $e) {
var_dump($e ->getMessage());
}
The call won't work until you finish it with your access credentials, but it provides an example of how most SOAP calls look in PHP.

Issue With RETS Data Fetching Feed in PHP

I am using the PHRETS PHP library to fetch the RETS data from the rets API. I have and issue with getting the Data. It's giving me the Requested Class not found Error. Please help to solve this Error. My Code is:
date_default_timezone_set('America/New_York');
require_once("vendor/autoload.php");
$log = new \Monolog\Logger('PHRETS');
$log->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::DEBUG));
$config = new \PHRETS\Configuration;
$config->setLoginUrl('http://rets.navicamls.net/login.aspx')
->setUsername('xxx')
->setPassword('xxx')
->setRetsVersion('1.7.2');
$rets = new \PHRETS\Session($config);
$rets->setLogger($log);
$connect = $rets->Login();
if ($connect) {
echo "Connected!<br>";
}
else {
echo "Not Connected!<br>";
print_r($rets->Error());
exit;
}
//results consists of Property, class, and query
$results = $rets->Search(
"Property",
"A",
"*",
[
'QueryType' => 'DMQL2',
'Count' => 1, // count and records
'Format' => 'COMPACT-DECODED',
'Limit' => 10,
'StandardNames' => 0, // give system names
]
);
print_r($results); exit;
You need to first verify the name of the class in your search query is correct by looking up the metadata.
Use RETSMD.com and enter the RETS Server login url, username, and password.
Use the metadata functions in the PHRETS documentation on the main page
a. $system = $rets->GetSystemMetadata();
b. $classes = $rets->GetClassesMetadata('Property');

Using TwitterOauth to get user timeline, always returns "page not found", code 34

I'm trying to get the user timeline for my twitter timeline, and it keeps giving me the return "page not found". The code is below:
require_once("twitteroauth/autoload.php");
use Abraham\TwitterOAuth\TwitterOAuth;
$connection = new TwitterOAuth($this->consumer_key, $this->consumer_secret, $this->oauth_access_token, $this->oauth_access_token_secret);
$data = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$this->username."&count=".$this->limit);
return $data;
Can't figure out what I'm doing wrong, any help is appreciated. Thanks!
I just tried it, and initially ran into the same issue. Reading This Documentation, it appears that there is a different format for making API requests with the TwitterOAuth library.
The example in this post was helpful as well: How to get the 3,200 tweets (Twitter API 1.1)
Try this, it worked for me:
require_once("twitteroauth/autoload.php");
use Abraham\TwitterOAuth\TwitterOAuth;
$connection = new TwitterOAuth($this->consumer_key, $this->consumer_secret, $this->oauth_access_token, $this->oauth_access_token_secret);
$data = $connection->get("statuses/user_timeline", array('count' => $this->limit, 'exclude_replies' => true, 'screen_name' => $this->username));
return $data;

How to get google contact list using artdarek-oauth-4-laravel?

I am using artdarek-oauth-4-laravel for the Login to my website via Facebook, twitter and google.
Login part is working fine. But I want to get some more data from these api, like if user is registering through the google then I am looking for their general info as well as google contact list, or if the user is registering from Facebook then I am trying to get the /me and /friend-list etc.
Here, I am just taking the case of google.
I have set the config like this
'Google' => array(
'client_id' => '***********************************',
'client_secret' => '***********************************',
'scope' => array('userinfo_email', 'userinfo_profile', 'https://www.google.com/m8/feeds/'),
),
My Controller Function is this:-
public function loginWithGoogle()
{
$code = Input::get( 'code' );
$googleService = OAuth::consumer( 'Google' );
if ( !empty( $code ) )
{
$token = $googleService->requestAccessToken( $code );
// $result = json_decode( $googleService->request( 'https://www.googleapis.com/oauth2/v1/userinfo' ), true );
$result = json_decode( $googleService->request( 'https://www.google.com/m8/feeds/contacts/default/full' ), true );
echo json_encode($result);
}
else {
// get googleService authorization
$url = $googleService->getAuthorizationUri();
// return to google login url
return Redirect::to( (string)$url );
}
}
This code leads me to the google api and asks for all the permission that I have set in the scope of the service. Here once I got the access token after exchanging the code parameter with the api, I am calling the url to return me the contact list but it fails. And I am getting this message from the laravel :-Failed to request resource.
If I call the commented $result request, it returns me the result.
So, I wanted to know how can we use this library for the data other than login and register. In case of retrieving facebook friendlist the same thing happens but the login works. (My Facebook App has the permission to get friendlist).
Any help is appreciated.
Check this response, https://stackoverflow.com/a/26488136/434790.
It worked for me. The culprit: alt=json to be added to https://www.google.com/m8/feeds/contacts/default/full

Categories