aboutsummaryrefslogtreecommitdiff
path: root/content/docs/mal2go/v4/manga/get-manga-by-id.md
blob: b138785a2e7d6572b5dfb4565d036bf82c3b8798 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
title: "Getting a manga's information"
description: "Specify a manga's ID to get all the data about it."
weight: 3
---

`GetMangaById` takes in a manga's ID (which can be obtained using [`SearchManga`](/docs/mal2go/v4/manga/search-for-a-manga) or through the URL of the manga's page on MAL) and returns information about it. This method takes these arguments:

- `id int` The manga's ID
- `fields []string` The fields to include in the response. [Here]() is a list of the valid fields. Just using an empty slice (`[]string{}`) will include all the fields.

Example:

``` go
package main

import (
    "github.com/MikunoNaka/MAL2Go/v4/manga"
    "log"
    "fmt"
)

func main() {
  authToken := "YOUR_TOKEN_HERE"
  myClient := manga.Client {
    AuthToken: "Bearer " + authToken,
  }
    
  id := 103890
  fields := []string{"title", "my_list_status", "num_chapters"}
    
  manga, err := myClient.GetMangaById(id, fields)
  if err != nil {
    log.Fatal(err) // remember kids, always handle errors
  }
    
  fmt.Printf("You have read %d out of %d chapters in %s. Your list status for %s is %s.\n", manga.MyListStatus.ChaptersRead, manga.NumChapters, manga.Title, manga.Title, manga.MyListStatus.Status)
}
```

Above example prints something like
`"You have read 7 out of 187 chapters in Bokutachi wa Benkyou ga Dekinai. Your list status for Bokutachi wa Benkyou ga Dekinai is reading."`

Above output shows blank status because mushishi is not in my list. This is expected.