0

When I try to get the accounts lists with "Method: accounts.list" It shows this error:

    {
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "type",
            "description": "Field is required"
          },
          {
            "field": "account_name",
            "description": "Field is required"
          },
          {
            "field": "primary_owner",
            "description": "Field is required"
          }
        ]
      }
    ]
  }
}

The documentation does not show any required field and I dont understand why it shows that error, and how to fix it, this is the php code I use:

curleo('https://mybusinessaccountmanagement.googleapis.com/v1/accounts',$token['access_token'], $data = '');

function curleo($url, $token, $postdata){
    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$token));
    $result = curl_exec($ch);
    curl_close($ch);
    print_r($result);
}

Any idea how to fix it?

/-- Updated fix --/

curl_get('https://mybusinessaccountmanagement.googleapis.com/v1/accounts',$token['access_token'], $data = '');
    
function curl_get($url, $token){

    $curl = curl_init();

    curl_setopt_array($curl, array(
      CURLOPT_URL => $url,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "GET",
      CURLOPT_HTTPHEADER => array(
        'Authorization: Bearer '.$token
      ),
    ));
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);
    print_r($response);
}
user4239
  • 23
  • 4

0 Answers0