前提・実現したいこと
CloudGarageのPublic APIを試しています。PHPで書いているのですが、自動バックアップ情報が取れません。
発生している問題・エラーメッセージ
500エラーが発生しています。エラーメッセージは[CloudGarage API リファレンス](https://api.cloudgarage.jp/doc/index.html#/Server API/getServerAutoBackupUsingGET)の通りですが、以下になります。
json
1{ 2 "fault":{ 3 "messages":[ 4 "failed to execute API" 5 ] 6 } 7}
該当のソースコード
php
1<?php 2$baseUrl = "https://api.cloudgarage.jp"; 3$config = json_decode(file_get_contents('./config.json'), true); 4/* 5config.jsonの内容は以下のような形 6{ 7 "clientId": "AAA", 8 "clientSecret": "BBB" 9} 10*/ 11 12// トークンの取得 13$token = getToken($baseUrl, $config); 14// インスタンスの取得 15$instances = getInstances($baseUrl, $token); 16// 最初のインスタンスの自動バックアップ情報を取得 17$backupInfo = getAutoBackupInfo($baseUrl, $token, $instances[0]['id']); 18 19var_dump($backupInfo); 20 21// GET処理を行う関数 22function get($url, $token, $key) { 23 $options = array ( 24 'http' => array ( 25 'header' => implode("\r\n", array( 26 'Content-type: application/json', 27 "X-Auth-Token: $token" 28 )) 29 ) 30 ); 31 $contents = file_get_contents($url, false, stream_context_create($options)); 32 return json_decode($contents, true)[$key]; 33} 34 35// 自動バックアップ情報を取得する 36function getAutoBackupInfo($baseUrl, $token, $id) { 37 $url = "$baseUrl/servers/$id/autoBackup"; 38 // ↓これが500エラー 39 return get($url, $token, 'autoBackup'); 40} 41 42// インスタンス情報を取得する 43function getInstances($baseUrl, $token) { 44 $url = "$baseUrl/servers"; 45 return get($url, $token, 'servers'); 46} 47 48// トークンを取得する 49function getToken($baseUrl, $config) { 50 $url = "$baseUrl/tokens"; 51 $options = array ( 52 'http' => array ( 53 'method' => 'POST', 54 'header' => 'Content-type: application/json', 55 'content' => json_encode( 56 array( 57 'client_id' => $config['clientId'], 58 'client_secret' => $config['clientSecret'] 59 ) 60 ) 61 ) 62 ); 63 $contents = file_get_contents($url, false, stream_context_create($options)); 64 return json_decode($contents, true)['token']['id']; 65} 66?>
試したこと
GET で /servers/{resource_id}/autoBackup を実行しました。

あなたの回答
tips
プレビュー