1

This is the response when I call the login method from twinfield API. It given the session id and cluster namespace, but the problem is how to get the value from it.

$customerApiConnector = new \PhpTwinfield\ApiConnectors\CustomerApiConnector($login);
print_r($customerApiConnector);die;

Output:

  PhpTwinfield\ApiConnectors\CustomerApiConnector Object
    (
        [service:protected] => PhpTwinfield\Services\ProcessXmlService Object
            (
                [trace] => 1
                [compression] => 32
                [_stream_context] => Resource id #153
                [_soap_version] => 1
                [sdl] => Resource id #154
                [__default_headers] => Array
                    (
                        [0] => SoapHeader Object
                            (
                                [namespace] => http://www.twinfield.com/
                                [name] => Header
                                [data] => Array
                                    (
                                        [SessionID] => f7b4c213-1a01-4c7c-87cb-7de80b1583fe
                                    )

                                [mustUnderstand] => 
                            )

                    )

            )

    )

This is the other object.

Array
(
    [1] => PhpTwinfield\CustomerAddress Object
        (
            [ID:PhpTwinfield\CustomerAddress:private] => 1
            [type:PhpTwinfield\CustomerAddress:private] => invoice
            [default:PhpTwinfield\CustomerAddress:private] => true
            [name:PhpTwinfield\CustomerAddress:private] => Anand
            [contact:PhpTwinfield\CustomerAddress:private] => 
            [country:PhpTwinfield\CustomerAddress:private] => IN
            [city:PhpTwinfield\CustomerAddress:private] => Indore
            [postcode:PhpTwinfield\CustomerAddress:private] => 452001
            [telephone:PhpTwinfield\CustomerAddress:private] => 
            [fax:PhpTwinfield\CustomerAddress:private] => 
            [email:PhpTwinfield\CustomerAddress:private] => anand@comfisoft.com
            [field1:PhpTwinfield\CustomerAddress:private] => 
            [field2:PhpTwinfield\CustomerAddress:private] => lig
            [field4:PhpTwinfield\CustomerAddress:private] => 
            [field5:PhpTwinfield\CustomerAddress:private] => 
            [field6:PhpTwinfield\CustomerAddress:private] => 
        )

)
halfer
  • 19,824
  • 17
  • 99
  • 186
Anand Pandey
  • 2,025
  • 3
  • 20
  • 39
  • You probably need to call `->get()` on it – Ohgodwhy Dec 27 '17 at 06:43
  • okay i will try – Anand Pandey Dec 27 '17 at 06:46
  • @Ohgodwhy: Its not working :( (1/1) FatalThrowableError Type error: Too few arguments to function PhpTwinfield\ApiConnectors\CustomerApiConnector::get(), 0 passed in C:\xampp\htdocs\twinfield\app\Http\Controllers\ApiController.php on line 55 and exactly 2 expected – Anand Pandey Dec 27 '17 at 06:48
  • I see, a quick look over the docs shows that you need to pass an argument (For sure), so instead use `->listAll();` – Ohgodwhy Dec 27 '17 at 08:11
  • again same problem (1/1) FatalThrowableError Type error: Too few arguments to function PhpTwinfield\ApiConnectors\CustomerApiConnector::listAll(), 0 passed in C:\xampp\htdocs\twinfield\app\Http\Controllers\ApiController.php on line 55 and exactly 1 expected – Anand Pandey Dec 27 '17 at 08:19
  • How are you calling it? Don't chain it, call it from the variable. `$customerApiConnector->listAll();` It's right [here in the docs](https://github.com/php-twinfield/twinfield). cntrl **Getting data from the API** – Ohgodwhy Dec 27 '17 at 08:23
  • I call the same. print_r($customerApiConnector->listAll());die; – Anand Pandey Dec 27 '17 at 08:24
  • @Ohgodwhy: listAll() is another function for listing the customers.I already do that. I just want the value from the $customerApiConnector object. – Anand Pandey Dec 27 '17 at 08:26

1 Answers1

1

Try this it will work ;)

function accessProtectedProperty($obj, $prop)
{
    $reflection = new \ReflectionClass($obj);
    $property = $reflection->getProperty($prop);
    $property->setAccessible(true);
    return json_decode($property->getValue($obj));
}
Jahid
  • 51
  • 4