Php Arrays / Table需要获得" EntityId"

时间:2017-11-20 09:36:37

标签: php arrays api

我是桌面/数组的新手,我无法使用它。 我正在尝试获取" EntityId"的数据,如果我更改"电话"它不起作用。到" EntityId"。我尝试了很多,但我无法自己解决这个问题。我希望有人可以解释我做错了什么,或者我没注意到什么。

任何帮助都将不胜感激。

脚本

<?php 
require_once 'autoload.php';

$username = '*****************';
$password = '*********';
$authWsdl = 'https://webservices.autotask.net/atservices/1.5/atws.wsdl';
$opts = array('trace' => 1);
$client = new ATWS\Client($authWsdl, $opts);
$zoneInfo = $client->getZoneInfo($username);

$authOpts = array(
    'login' => $username,
    'password' => $password,
    'trace' => 1,   // Allows us to debug by getting the XML requests sent
);
$wsdl = str_replace('.asmx', '.wsdl', $zoneInfo->getZoneInfoResult->URL);
$client = new ATWS\Client($wsdl, $authOpts);

// Instantiate a Query object, designed to make complex
// queries simple.
$query = new ATWS\AutotaskObjects\Query('Contact');

$firstnameField = new ATWS\AutotaskObjects\QueryField('ID');
$firstnameField->addExpression('Equals', '30682996');

$query->addField($firstnameField);

// If you want to debug the XML produced by the Query object
// print($query->asXml());

// Print the results of the query
print_r($client->query($query));

$json = ($client->query($query));
$phone = $json->queryResult->EntityResults->Entity->Phone;
echo $phone;

输出

ATWS\AutotaskObjects\QueryResponse Object 
    ( [queryResult] => ATWS\AutotaskObjects\ATWSResponse Object 
        ( [EntityResults] => ATWS\AutotaskObjects\ArrayOfEntity Object 
            ( [Entity] => ATWS\AutotaskObjects\Contact Object 
                ( [AccountID] => 236 
                [Active] => 0 
                [AdditionalAddressInformation] => 
                [AddressLine] => Dorpstraat 
                [AddressLine1] => 
                [AlternatePhone] => 040-4444555566 
                [City] => Veldhoven 
                [Country] => Netherlands 
                [CountryID] => 158 
                [CreateDate] => 2017-11-18T05:36:46.14 
                [EMailAddress] => Email@email.nl 
                [Extension] => 
                [ExternalID] => 
                [FaxNumber] => 467863453 
                [FirstName] => Ellis 
                [LastActivityDate] => 2017-11-18T05:36:46.14 
                [LastModifiedDate] => 2017-11-18T05:36:46.127 
                [LastName] => Dodo
                [MiddleInitial] => 
                [MobilePhone] => 061231235 
                [Note] => 
                [Notification] => 1 
                [Phone] => 040-4444555566 
                [RoomNumber] => 
                [State] => GH 
                [Title] => 
                [ZipCode] => 5890aa 
                [Fields] => 
                [UserDefinedFields] => ATWS\AutotaskObjects\ArrayOfUserDefinedField Object 
                    ( [UserDefinedField] => ) 
                    [id] => 30682996 
                    [BulkEmailOptOut] => 
                    [SurveyOptOut] => 
                    [FacebookUrl] => 
                    [TwitterUrl] => 
                    [LinkedInUrl] => 
                    [PrimaryContact] => ) ) 
                    [EntityResultType] => contact 
                    [EntityReturnInfoResults] => ATWS\AutotaskObjects\ArrayOfEntityReturnInfo Object ( [EntityReturnInfo] => ATWS\AutotaskObjects\EntityReturnInfo Object ( [DatabaseAction] => None [DuplicateStatus] => ATWS\AutotaskObjects\EntityDuplicateStatus Object ( [Found] => [Ignored] => [MatchInfo] => [Fields] => [UserDefinedFields] => ) [EntityId] => 30682996 [Message] => [Fields] => [UserDefinedFields] => ) [Fields] => [UserDefinedFields] => ) [Errors] => ATWS\AutotaskObjects\ArrayOfATWSError Object ( [ATWSError] => [Fields] => [UserDefinedFields] => ) [ReturnCode] => 1 ) ) 

@kunal

输出

ATWS\AutotaskObjects\QueryResponse Object ( [queryResult] => ATWS\AutotaskObjects\ATWSResponse Object ( [EntityResults] => ATWS\AutotaskObjects\ArrayOfEntity Object ( [Entity] => ATWS\AutotaskObjects\Contact Object ( [AccountID] => 236 [Active] => 0 [AdditionalAddressInformation] => [AddressLine] => Dorpstraat [AddressLine1] => [AlternatePhone] => 040-4444555566 [City] => Veldhoven [Country] => Netherlands [CountryID] => 158 [CreateDate] => 2017-11-18T05:36:46.14 [EMailAddress] => Test@email.ciom [Extension] => [ExternalID] => [FaxNumber] => 467863453 [FirstName] => Ellis [LastActivityDate] => 2017-11-18T05:36:46.14 [LastModifiedDate] => 2017-11-18T05:36:46.127 [LastName] => Bommers [MiddleInitial] => [MobilePhone] => 0612312asd35 [Note] => [Notification] => 1 [Phone] => 040-44asd44555566 [RoomNumber] => [State] => NB [Title] => [ZipCode] => 1239aa [Fields] => [UserDefinedFields] => ATWS\AutotaskObjects\ArrayOfUserDefinedField Object ( [UserDefinedField] => ) [id] => 30682996 [BulkEmailOptOut] => [SurveyOptOut] => [FacebookUrl] => [TwitterUrl] => [LinkedInUrl] => [PrimaryContact] => ) ) [EntityResultType] => contact [EntityReturnInfoResults] => ATWS\AutotaskObjects\ArrayOfEntityReturnInfo Object ( [EntityReturnInfo] => ATWS\AutotaskObjects\EntityReturnInfo Object ( [DatabaseAction] => None [DuplicateStatus] => ATWS\AutotaskObjects\EntityDuplicateStatus Object ( [Found] => [Ignored] => [MatchInfo] => [Fields] => [UserDefinedFields] => ) [EntityId] => 30682996 [Message] => [Fields] => [UserDefinedFields] => ) [Fields] => [UserDefinedFields] => ) [Errors] => ATWS\AutotaskObjects\ArrayOfATWSError Object ( [ATWSError] => [Fields] => [UserDefinedFields] => ) [ReturnCode] => 1 ) ) 
Notice: Undefined property: ATWS\AutotaskObjects\ArrayOfUserDefinedField::$EntityReturnInfoResults in C:\xampp\htdocs\Api\Autotask\vendor\test.php on line 35

Notice: Trying to get property of non-object in C:\xampp\htdocs\Api\Autotask\vendor\test.php on line 35

Notice: Trying to get property of non-object in C:\xampp\htdocs\Api\Autotask\vendor\test.php on line 35

Notice: Trying to get property of non-object in C:\xampp\htdocs\Api\Autotask\vendor\test.php on line 35

阵列

<?php
namespace ATWS\AutotaskObjects;

class Contact extends Entity
{
    public $AccountID;
    public $Active;
    public $AdditionalAddressInformation;
    public $AddressLine;
    public $AddressLine1;
    public $AlternatePhone;
    public $City;
    public $Country;
    public $CountryID;
    public $CreateDate;
    public $EMailAddress;
    public $Extension;
    public $ExternalID;
    public $FaxNumber;
    public $FirstName;
    public $LastActivityDate;
    public $LastModifiedDate;
    public $LastName;
    public $MiddleInitial;
    public $MobilePhone;
    public $Note;
    public $Notification;
    public $Phone;
    public $RoomNumber;
    public $State;
    public $Title;
    public $ZipCode;
}

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,你正在寻找: -

echo $json->queryResult->EntityResults->Entity->UserDefinedFields->UserDefinedField->EntityReturnInfoResults->DatabaseAction->EntityReturnInfo->EntityId;