When using setMap with HTTP API V1
I get this answer from the server :
Code (PHP) :
$this->curly = curl_init();
curl_setopt($this->curly, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curly, CURLOPT_POST, true);
$data = array(
'apiKey' => $this->apiKey,
'spaceId' => $this->spaceId,
'mapId' => $this->mapId,
'mapContent' => json_encode($mapDecodedUpdated)
);
$postData=json_encode($data);
curl_setopt($this->curly, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data'));
curl_setopt($this->curly, CURLOPT_POSTFIELDS,$postData);
curl_setopt($this->curly,CURLOPT_URL,$this->urlSet); //urlSet = https://gather.town/api/setMap
$answer = curl_exec($this->curly);
curl_close($this->curly);
Did I miss something when calling the API ?
Maybe the conten-type is incorrect but I tested some other : application/json and * application/x-www-form-urlencoded
and the result is the same
Fair warning, I am not a PHP coder (currently), so I might be a little rusty. I was able to get the following to work. I generated it using ReqBin, so YRMV.
Get Map Example
<?php
//Removed my data
$url = "https://gather.town/api/getMap?apiKey=API_KEY&spaceId=SPACE_ID\SPACENAME&mapId=ROOM_NAME";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Accept: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
Set Map Example
<?php
$url = "https://gather.town/api/setMap";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Accept: application/json",
"Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = <<<DATA
{
//Removed my data
"apiKey":"API_KEY",
"spaceId":"SPACE_ID\\SPACE_NAME",
"mapId": "ROOM_NAME",
"mapContent": {MAP DATA}
}
DATA;
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
1 Like
You are the boss !
I had json encoded the map twice !
But itβs corrected and I used ReBin to debug, great tool !
Iβm working on an escape-game like space and the password door are good but I wanted to open access from a riddle solving on my website and with this API , it wil be great
Thanks a lot for this reactive help.