从 KashFlow API 获取所有客户记录时出现问题


Problems getting all customer records from KashFlow API

我已经完成了大部分的腿部工作。我已经连接到 API,它返回了一个客户对象数组,我只是在为如何遍历每个客户对象而苦苦挣扎。

以下是 API 调用返回的结构:

stdClass Object
(
[Customer] => Array
    (
        [0] => stdClass Object
            (
                [CustomerID] => 20409125
                [Name] => Computer Says No
                [Telephone] => 
                [Mobile] => 
                [Email] => myemail@address.com
                [Website] => 
            )
        [1] => stdClass Object
            (
                [CustomerID] => 20409126
                [Name] => Joe Bloggs
                [Telephone] => 
                [Mobile] => 
                [Email] => myemail@address.com
                [Website] => 
            )
        [3] => stdClass Object
            (
                [CustomerID] => 20409127
                [Name] => Jane Bloggs
                [Telephone] => 
                [Mobile] => 
                [Email] => myemail@address.com
                [Website] => 
            )
    )
)

这是我尝试循环响应的方式

$kashflow = new Kashflow('my username','my password');
$customers = $kashflow->getCustomers();
foreach($customers as $customer){
echo "<pre>";
print_r($customer->CustomerID);
echo "</pre>";
}

如果我print_r($customers),我会得到:

stdClass Object
(
[GetCustomersResult] => stdClass Object
    (
        [Customer] => Array
            (
                [0] => stdClass Object
                    (
                        [CustomerID] => 20409125
                    )
                [1] => stdClass Object
                    (
                        [CustomerID] => 20409126
                    )
                [2] => stdClass Object
                    (
                        [CustomerID] => 20409127
                    )
              )
      )
)

试试这个:

$kashflow = new Kashflow('my username','my password');
$customers = $kashflow->getCustomers();
foreach($customers->GetCustomersResult->Customer as $customer){
    echo "<pre>";
    print_r($customer->CustomerID);
    echo "</pre>";
}

你得到的记录是这样的

    $first_id= array_column($customers, 'cust_id');
    foreach($first_id as $id)
    {
      echo "<pre>";
      echo $id;
      echo "</pre>"
    }