Check_username api endpoint seems to not work correctly

when we want to sinup in discourse and write a username, if the username is taken, discourse suggest for another username. I wanted to use this feature in my apis and tracked down the api call made by discourse using this topic.

It seems I should do somthing like the following, however when I test it with postman, I dont get the correct response:

https://myforum.com/u/check_username?api_key=xxxx&api_username=yyyy&username=zzzz&email=a@b.c

This is also the php code I wrote for this:

$discourse_url = 'https://myforum.com/';
$api_user = 'xxxx';
$api_key = 'yyyy';
$username = 'zzz';
$email = 'a@b.c'
$data = array(  'api_key'=>$api_key,  'api_username'=>$api_user,  'username'=>$username, 'email'=>$email);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $discourse_url."u/check_username?".http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
$response = curl_exec($ch);
echo $response;
1 Like

Try appending .json to your url and it should work.

https://myforum.com/u/check_username.json?api_key=xxxx&api_username=yyyy&username=zzzz&email=a@b.c

5 Likes

This topic was automatically closed after 2292 days. New replies are no longer allowed.