Skip to content
Advertisement

Trying to get value from a non Object response in php

I would like to get the Instance ID of last entered company name in Veeam and save it in my database

im using Curl for the APi at Rest .

The below code gets the response and decodes it

$response = curl_exec($curl);
$json = $response;
$json_output = json_decode($json, true);
echo '<pre>';
print_r($json_output); 

the response if below

Array
(
    [meta] => Array
        (
            [pagingInfo] => Array
                (
                    [total] => 7
                    [count] => 7
                    [offset] => 0
                )

        )

    [data] => Array
        (
            [0] => Array
                (
                    [instanceUid] => 0aa2db5f-3450-4c30-8074-c215ca509475
                    [name] => Jerome_Company
                    [status] => active
                    [resellerUid] => 
                    [subscriptionPlanUid] => a8078b36-c29b-40db-90f5-4960a05fff1e
                    [permissions] => Array
                        (
                        )

                )

              

            [5] => Array
                (
                    [instanceUid] => ebcd92e9-bb13-4ea0-87c4-175bc7b5ab1f
                    [name] => Xoagub
                    [status] => active
                    [resellerUid] => 
                    [subscriptionPlanUid] => a8078b36-c29b-40db-90f5-4960a05fff1e
                    [permissions] => Array
                        (
                        )

                )

            [6] => Array
                (
                    [instanceUid] => 1325d332-b7d9-4960-9004-0b7ca335078e
                    [name] => Gmail
                    [status] => creating
                    [resellerUid] => 
                    [subscriptionPlanUid] => a8078b36-c29b-40db-90f5-4960a05fff1e
                    [permissions] => Array
                        (
                        )

                )

        )

)

is there a method were i can get the instanceUid of last entered company ?

Advertisement

Answer

Get the last entry of data and then the instanceUid:

echo end($json_output['data'])['instanceUid'];

But you shouldn’t be getting Trying to get value from a non Object anywhere unless you’ve tried to access something as an object like $json_output->data; which won’t work because you’ve decoded to an array with true passed to json_encode.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement