##ユーザー登録
<?php
$data = [
"jsonrpc"=> "2.0",
"method"=> "User.create",
"params"=> [
"username"=> "yamada",
"password"=> "password"
],
"id" => 1
];
$header = [
'X-Monaca-Backend-Management-API-Key: ************** ' // APIキー
];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://cloud.monaca.mobi/manage/json-rpc/************'); // エンドポイント
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
$result = json_decode($response, true);
var_export($result);
##ユーザー取得
ユーザー名からidを取得する
<?php
$username = 'yamada';
$data = [
"jsonrpc"=> "2.0",
"method"=> "User.list",
"params"=> [
"page"=> 1,
"itemsInPage"=> 100,
"sortProperty"=> "_username",
"sortOrder" => "asc",
"nameFilter" => $username
],
"id" => 1
];
$header = [
'X-Monaca-Backend-Management-API-Key: ********** '
];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://cloud.monaca.mobi/manage/json-rpc/***********');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response);
$result = $response->result;
$id = "";
for ($i = 0; $i < $result->totalItems; $i++) {
if ($result->items[$i]->_username == $username) {
$id = $result->items[$i]->_id;
break;
}
}
echo $id;
ネットを探してもサンプルが少なかったので。