Sunday, May 7, 2017

[google-cloud-sql-discuss] Error 401 - Login Required when trying to add an authorized address through Cloud SQL API

Hi, I try to add an address through the Google cloud API with the following code :
- url = https://www.googleapis.com/sql/v1beta4/projects/osot-163701/instances/osot-db?alt=json
- 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?

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/4d1b0956-12d8-415d-9cc6-284ee455d7c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment