Jump to content

Assigning achievements manually through API awardbadge


Go to solution Solved by Daniel F,

Recommended Posts

I'm trying to assign an achievements via API to a user, manually.

the badge is ID 17 and the user is ID 1.

to try here's the code:

$client = new Client();

$response = $client->request('POST','https://domain.it/api/core/members/1/achievements/17/awardbadge?key=***');

$headers = $response->getHeaders();
$body = $response->getBody();

var_dump($headers, $body);

or

$url = 'https://**/api/core/members/1/achievements/17/awardbadge?key=***';


$endpoint = $url;

$options = [
'form_params' => [
'$badgeId' => 17
]
];
$client = new Client();
$request =  $client->post($endpoint, $options);

when I run it, without everything being ignored, even at the Log API, it does not result in the execution of this endpoint but Laravel marks me in the log:

Quote

Server error: `POST https://domain.it/api/core/members/1/achievements/17/awardbadge?key=***` resulted in a `500 Internal Server Error` response:

how do I assign an achievements manually through api?

 

Edited by Askancy
Link to comment
Share on other sites

  • 3 weeks later...
29 minutes ago, Daniel F said:

If not, what was the logged error?

Blank page, I tried with:

 

			$url = 'https://forum.***.it/api/core/members/1/achievements/34/awardbadge?key=***';
			$data = array('$badgeId' => 34);

			// use key 'http' even if you send the request to https://...
			$options = array(
			    'http' => array(
			        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
			        'method'  => 'POST',
			        'content' => http_build_query($data)
			    )
			);
			$context  = stream_context_create($options);
			$result = file_get_contents($url, false, $context);

			return $result;

in Rest API Log, it doesn't even appear to be making an API request.

Link to comment
Share on other sites

3 hours ago, Daniel F said:

Thanks, there was a bug in the endpoint which will be resolved in an upcoming release.

I noticed that I'm registering this error for the API:

 

ArgumentCountError: Too few arguments to function IPS\core\api\_members::POSTitem_achievements_awardbadge(), 2 passed in /var/www/vhosts/***.it/forum.****.it/system/Api/Controller.php on line 180 and at least 5 expected (0)
#0 /var/www/vhosts/***.it/forum.***.it/system/Api/Controller.php(180): IPS\core\api\_members->POSTitem_achievements_awardbadge()
#1 /var/www/vhosts/***.it/forum.***.it/system/Dispatcher/Api.php(329): IPS\Api\_Controller->execute()
#2 /var/www/vhosts/***.it/forum.***.it/api/index.php(11): IPS\Dispatcher\_Api->run()
#3 {main}

Is the error fixed? I hope to implement this function soon in my cms...

Link to comment
Share on other sites

  • 4 weeks later...
3 hours ago, Daniel F said:

The fix will be included in the next regular release.

I take this opportunity to ask you something too...

I use this request api to print the notifications of the logged in user:

                              @php
                                $url = 'https://forum.***.it/';
                                $apiKey = '***';
                                $point = '/core/members/'.\IPS\Member::loggedIn()->member_id.'/notifications';
                                $endpoint = $url. 'api'. $point. '?key='. $apiKey;

                                $json = file_get_contents($endpoint);
                                $json_data = json_decode($json, true);
                              @endphp
                              @foreach($json_data["results"] as $value)
                              @if ($value["notificationData"][unread] == 'true') <strong> @endif
                              <a href='{{$value["notificationData"]["url"]}}'>
                                <li class="dropdown-list-item">
                                    <span class="dropdown-list-text text-success">
                                      @if ($value["notificationType"] == "new_badge")
                                        <i class="fas fa-certificate"></i>
                                      @else
                                        <i class="far fa-envelope"></i>
                                      @endif
                                    </span>
                                    <div class="dropdown-list-body">
                                        {{$value["notificationData"]["title"]}}
                                    </div>
                                </li>
                                </a>
                                @if ($value["notificationData"][unread] == 'true') </strong> @endif
                              @endforeach

why does it print all the notifications in English, even if the user has the language set in Italian? Otherwise, how do I tell the API request to return the notification to me in Italian?

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...