0

I received error when trying to call single array from json_decode()

Undefined Index AccontNumber

And I have try to use Isset to the variable and doesnt get any result, Where do I doing wrong ?

    $this->getToken();
    $path = '/banking/v2/corporates/BCAAPI2016/accounts/0201245680/statements?StartDate=2016-09-01&EndDate=2016-09-01';
    $method = 'GET';
    $data = array();
    $this->getSignature($path, $method, $data);
    $headers = array(
      'X-BCA-Key: '.self::$api_key,
      'X-BCA-Timestamp: '.self::$timestamp,
      'Authorization: Bearer '.self::$access_token,
      'X-BCA-Signature: '.self::$signature,
      'Content-Type: application/json',
      'Origin: '.$_SERVER['SERVER_NAME']
      );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, self::$main_url.$path);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt_array($ch, array(
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_HTTPHEADER => $headers,
        ));
    $output = curl_exec($ch); // This is API Response
    curl_close($ch);
//this part I get error
    $result = json_decode($output,true);

    return view("bca.bca", [
        "result" => $result
        ]);

my view

@if ($result['AccountDetailDataSuccess'])
{{ $result['AccountNumber'] }}
{{ $result['Currency'] }}
{{ $result['Balance'] }}
{{ $result['AvailableBalance'] }}
{{ $result['FloatAmount'] }}
{{ $result['HoldAmount'] }}
{{ $result['Plafon'] }}
@elseif ($result['AccountDetailDataFailed'])
{{ $result['English'] }}
{{ $result['Indonesian'] }}
{{ $result['AccountNumber'] }}
@endif

and this the result if I var_dump($result)

array(2) { ["AccountDetailDataSuccess"]=> array(1) { [0]=> array(7) { ["AccountNumber"]=> string(10) "0201245680" ["Currency"]=> string(3) "IDR" ["Balance"]=> string(12) "118849999.53" ["AvailableBalance"]=> string(12) "118849999.53" ["FloatAmount"]=> string(4) "0.00" ["HoldAmount"]=> string(4) "0.00" ["Plafon"]=> string(4) "0.00" } } ["AccountDetailDataFailed"]=> array(0) { } }

How can I call just one single array from the JSON result ?

2
  • Can know how did you get the X-BCA-Signatue ? Commented May 20, 2020 at 11:48
  • @vishwasjadav if I'm not mistaken X-BCA-Signature is a combination. can get it in the BCA documentation. Commented May 21, 2020 at 15:48

1 Answer 1

2

AccountNumber is located in the AccountDetailDataSuccess array, thus call

$result['AccountDetailDataSuccess'][0]['AccountNumber']

same for currency etc.

Sign up to request clarification or add additional context in comments.

2 Comments

I prefer echo '<pre>'; print_r($a); echo '</pre>'; sometimes over var_dump, because the layout is just a bit more readable.
Thanks again bro, I'll your suggest

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.