Error 401 - Login Required when trying to add an authorized address through Cloud SQL API

16 views
Skip to first unread message

Maxime Arbez

unread,
May 8, 2017, 9:22:44 AM5/8/17
to Google Cloud SQL discuss
Hi, I try to add an address through the Google cloud API with the following code :
- send_method = PATCH

$headers=array('Authorization: Bearer ' . $access_token, 'Content-Type: application/json');
$send_method = "PATCH";
$access_token = "ya29.GltEBKYRM25dDrsBizJ4oCreSB7o5BxOTH47Xm7Z8wugqPnNkDWbfJStxXDW-aE3ey37f6p7zU38hkSrv9nqPQ8IyOhYQF1TKliaOlDYePh3582XhzXc6cWNVq5G";
$payload = '{"settings" : {"ipConfiguration" : {"authorizedNetworks" : [{ "value": "35.185.139.68" }]}}}';


$settings = array(
CURLOPT_CUSTOMREQUEST => $send_method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYPEER => 0,
                [CURLOPT_POSTFIELDS] => $payload
);

$curl = curl_init($url);
curl_setopt_array($curl, ($settings));

$result = curl_exec($curl);
curl_close($curl);


I know that my payload is good because I tried it through https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/patch .
I know that my token is ok because it has been provided by the Oauth playground.
I use a service account and I declared myself as owner.

But, unfortunately, I got the following error (even on Oauth playground):
 {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}



What can I do?
Reply all
Reply to author
Forward
0 new messages