Skip to main content
Add my solution
Source Link

Is there an API call where you can get all achievements and all unread achievements?

Like this:

Update

Thanks to the answer of Glorfindel, I use the following methods to calculate the unread achievements.

Note: I'm using angular 8

notification.service.ts

public getAchievements(options?: IQuestionOptions): Observable<IResponse> {   
  const headers = new HttpHeaders()
    .set('Accept', '*/*');

  const params = new HttpParams()
    .set('key', {{APP_KEY}})
    .set('access_token', {{TOKEN}})
    .set('pageSize', '30')
    .set('page', '1')
    .set('filter', 'O5lYbEN2lExNfdp2Q');

  return this.http
    .get<IResponse>(
      'https://api.stackexchange.com/2.3/', 
      { headers, params }
    );
}

Counting unread items

public countUnread(items: any): number {
  if (!items) {
    return 0;
  }

  return items
    .map(item => item.is_unread ?
      item.reputation_change ?
        item.reputation_change
        : 1
      : 0)
    .reduce((accumulator, currentValue) => accumulator + currentValue);
}

Also to be mentioned is that this method is used for counting unread messages and unread achievements, depending on what was handed over.

Is there an API call where you can get all achievements and all unread achievements?

Like this:

Is there an API call where you can get all achievements and all unread achievements?

Like this:

Update

Thanks to the answer of Glorfindel, I use the following methods to calculate the unread achievements.

Note: I'm using angular 8

notification.service.ts

public getAchievements(options?: IQuestionOptions): Observable<IResponse> {   
  const headers = new HttpHeaders()
    .set('Accept', '*/*');

  const params = new HttpParams()
    .set('key', {{APP_KEY}})
    .set('access_token', {{TOKEN}})
    .set('pageSize', '30')
    .set('page', '1')
    .set('filter', 'O5lYbEN2lExNfdp2Q');

  return this.http
    .get<IResponse>(
      'https://api.stackexchange.com/2.3/', 
      { headers, params }
    );
}

Counting unread items

public countUnread(items: any): number {
  if (!items) {
    return 0;
  }

  return items
    .map(item => item.is_unread ?
      item.reputation_change ?
        item.reputation_change
        : 1
      : 0)
    .reduce((accumulator, currentValue) => accumulator + currentValue);
}

Also to be mentioned is that this method is used for counting unread messages and unread achievements, depending on what was handed over.

added 2 characters in body; edited tags; edited title
Source Link
Glorfindel
  • 6.9k
  • 3
  • 22
  • 49

How to get (unredunread) achievements?

Is there a apian API call where you can get all achievements and all unread achievements?

Like this
 :

How to get (unred) achievements

Is there a api call where you can get all achievements and all unread achievements?

Like this
 

How to get (unread) achievements?

Is there an API call where you can get all achievements and all unread achievements?

Like this:

Source Link

How to get (unred) achievements

Is there a api call where you can get all achievements and all unread achievements?

Like this