### Paginated Media Query Examples Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/pagination.md Examples of making a paginated query to get a list of Media entries using different programming languages. Note that variables not provided in the variables object are ignored. ```javascript import Anilist from 'anilist-api'; const anilist = new Anilist(); async function getAnimePage() { const query = ` query ($page: Int, $perPage: Int) { Page(page: $page, perPage: $perPage) { pageInfo { currentPage hasNextPage perPage } media { id title { romaji } } } } `; const variables = { page: 1, perPage: 3 }; const data = await anilist.graphql(query, variables); console.log(JSON.stringify(data, null, 2)); } getAnimePage(); ``` ```php 1, 'perPage' => 3 ]; $body = json_encode(['query' => $query, 'variables' => $variables]); $request = new Request('POST', 'https://graphql.anilist.co', ['Content-Type' => 'application/json'], $body); $response = $client->send($request); echo $response->getBody(); ``` ```python import requests url = 'https://graphql.anilist.co' query = """ query ($page: Int, $perPage: Int) { Page(page: $page, perPage: $perPage) { pageInfo { currentPage hasNextPage perPage } media { id title { romaji } } } } """ variables = { 'page': 1, 'perPage': 3 } response = requests.post(url, json={'query': query, 'variables': variables}) print(response.json()) ``` ```rust use reqwest::Error; #[derive(serde::Deserialize)] struct Page { pageInfo: PageInfo, media: Vec } #[derive(serde::Deserialize)] struct PageInfo { currentPage: u32, hasNextPage: bool, perPage: u32 } #[derive(serde::Deserialize)] struct Media { id: u32, title: MediaTitle } #[derive(serde::Deserialize)] struct MediaTitle { romaji: String } #[tokio::main] async fn main() -> Result<(), Error> { let query = r#"query ($page: Int, $perPage: Int) { Page(page: $page, perPage: $perPage) { pageInfo { currentPage hasNextPage perPage } media { id title { romaji } } } }"#; let variables = serde_json::json!({ "page": 1, "perPage": 3 }); let client = reqwest::Client::new(); let res = client.post("https://graphql.anilist.co") .json(&serde_json::json!({"query": query, "variables": variables})) .send() .await?; let data: serde_json::Value = res.json().await?; println!("{}", serde_json::to_string_pretty(&data).unwrap()); Ok(()) } ``` -------------------------------- ### Get Media by ID Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media.md Fetches a specific media entry using its unique ID. A 404 response is returned if the ID does not exist. ```graphql query ($id: Int) { Media (id: $id) { id title { romaji english native } } } ``` -------------------------------- ### Get a single list entry by media ID and user ID Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media-list.md Retrieve a specific media list entry by providing both the media ID and the user ID. This is the recommended approach when you know the media and the user for whom you want to fetch the list entry. ```APIDOC ## Get a single list entry by media ID and user ID ### Description Retrieves a specific media list entry by providing both the media ID and the user ID. This is the recommended approach when you know the media and the user for whom you want to fetch the list entry. ### Method POST ### Endpoint https://graphql.anilist.co ### Parameters #### Query Parameters - **mediaId** (Int) - Required - The ID of the media. - **userId** (Int) - Required - The ID of the user. ### Request Example ```graphql query ($mediaId: Int!, $userId: Int!) { MediaList(mediaId: $mediaId, userId: $userId) { id media { id title { romaji } } } } ``` ### Response #### Success Response (200) - **id** (Int) - The ID of the media list entry. - **media** (Object) - The media object associated with the list entry. - **id** (Int) - The ID of the media. - **title** (Object) - The title of the media. - **romaji** (String) - The Romaji title of the media. ``` -------------------------------- ### Get media by ID Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media.md Retrieves a specific media entry using its unique ID. Returns a 404 if the ID does not correspond to any media. ```APIDOC ## Get media by ID ### Description This is one of the most barebones queries you can make. It will directly return the media with the specified ID. If the ID does not match up with a media, you will receive a `404` response code. ### Method QUERY ### Endpoint `/graphql` ### Parameters #### Query Parameters - **id** (Int!) - Required - The ID of the media to retrieve. ### Request Example ```graphql query ($id: Int) { Media (id: $id) { id title { romaji english native } } } ``` ### Response #### Success Response (200) - **Media** (Object) - The media object with the requested details. - **id** (Int) - The unique identifier for the media. - **title** (Object) - An object containing different title formats. - **romaji** (String) - The Romaji title of the media. - **english** (String) - The English title of the media. - **native** (String) - The native language title of the media. #### Response Example ```json { "data": { "Media": { "id": 1, "title": { "romaji": "Cowboy Bebop", "english": "Cowboy Bebop", "native": "カウボーイビバップ" } } } } ``` ``` -------------------------------- ### Get Related Media and Characters (GraphQL) Source: https://context7.com/anilist/docs/llms.txt Query for related media (sequels, prequels, etc.) and character information, including voice actors, for a given media ID. This demonstrates the use of connection fields like `edges` and `nodes`. ```graphql # Get all related media (sequels, prequels, side stories, etc.) for a given anime query ($id: Int!) { Media(id: $id) { id title { romaji } relations { edges { relationType # SEQUEL, PREQUEL, SIDE_STORY, etc. node { id title { romaji } type format status } } } characters(page: 1) { edges { role # MAIN, SUPPORTING, BACKGROUND voiceActors { id name { first last } languageV2 } node { id name { full } } } } } } ``` -------------------------------- ### SaveMediaListEntry Mutation Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/mutations.md This mutation allows you to create a new media list entry or update an existing one. If an `id` is provided, it updates the entry; otherwise, it creates a new one. The example demonstrates creating a new entry for a media item. ```APIDOC ## SaveMediaListEntry ### Description Creates a new media list entry or updates an existing one based on the presence of an `id`. ### Method `mutation` ### Example ```graphql mutation ($mediaId: Int, $status: MediaListStatus) { SaveMediaListEntry(mediaId: $mediaId, status: $status) { id status } } ``` ### Variables - **mediaId** (Int) - The ID of the media to add to the list. - **status** (MediaListStatus) - The status to set for the media list entry. ### Response #### Success Response - **id** (Int) - The ID of the created or updated media list entry. - **status** (MediaListStatus) - The status of the media list entry. ### Response Example ```json { "data": { "SaveMediaListEntry": { "id": 4, "status": "CURRENT" } } } ``` ``` -------------------------------- ### Making Authenticated Requests in Javascript Source: https://github.com/anilist/docs/blob/master/docs/guide/auth/authenticated-requests.md Include the access token in the Authorization header as a Bearer token for authenticated API calls. This example demonstrates the structure for a Javascript request. ```javascript const accessToken = "YOUR_ACCESS_TOKEN"; fetch('https://graphql.anilist.co', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': `Bearer ${accessToken}` }, body: JSON.stringify({ query: ` query { Viewer { id name } } ` }) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Making Authenticated Requests in PHP Source: https://github.com/anilist/docs/blob/master/docs/guide/auth/authenticated-requests.md Include the access token in the Authorization header as a Bearer token for authenticated API calls. This example demonstrates the structure for a PHP request. ```php $accessToken = "YOUR_ACCESS_TOKEN"; $query = 'query { Viewer { id name } }'; $variables = []; $headers = [ 'Content-Type: application/json', 'Accept: application/json', 'Authorization: Bearer ' . $accessToken ]; $data = [ 'query' => $query, 'variables' => $variables ]; $options = [ 'http' => [ 'header' => $headers, 'method' => 'POST', 'content' => json_encode($data), 'ignore_errors' => true ] ]; $context = stream_context_create($options); $result = file_get_contents('https://graphql.anilist.co', false, $context); if ($result === false) { // Handle error echo 'Error fetching data'; } else { $responseData = json_decode($result, true); print_r($responseData); } ``` -------------------------------- ### Get Media List Entry from Media Object Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media-list.md Retrieve the authenticated user's list entry directly from the `Media` object. This field returns `null` if the user is not authenticated. It requires the media ID as an argument. ```graphql query ($id: Int!) { Media(id: $id) { id title { romaji } mediaListEntry { id } } } ``` -------------------------------- ### Get media list entry from Media object Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media-list.md When requesting a `Media` object, you can use the `mediaListEntry` field to retrieve the list entry for the authenticated user. If the request is not authenticated, this field will return `null`. ```APIDOC ## Get media list entry from Media object ### Description When requesting a `Media` object, you can use the `mediaListEntry` field to retrieve the list entry for the authenticated user. If the request is not authenticated, this field will return `null`. ### Method POST ### Endpoint https://graphql.anilist.co ### Parameters #### Query Parameters - **id** (Int!) - Required - The ID of the media. ### Request Example ```graphql query ($id: Int!) { Media(id: $id) { id title { romaji } mediaListEntry { id } } } ``` ### Response #### Success Response (200) - **id** (Int) - The ID of the media. - **title** (Object) - The title of the media. - **romaji** (String) - The Romaji title of the media. - **mediaListEntry** (Object) - The list entry for the authenticated user, or null if not authenticated. - **id** (Int) - The ID of the media list entry. ``` -------------------------------- ### Studio Source: https://github.com/anilist/docs/blob/master/docs/reference/query.md Queries for studio information with various filtering and sorting options. ```APIDOC ## Studio ### Description Studio query. ### Query - **id** (Int) - Filter by the studio id - **search** (String) - Filter by search query - **id_not** (Int) - Filter by the studio id - **id_in** ([Int]) - Filter by the studio id - **id_not_in** ([Int]) - Filter by the studio id - **sort** ([StudioSort]) - The order the results will be returned in ``` -------------------------------- ### Get Authenticated User Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/user.md Retrieves the currently authenticated user's information by inferring from the access token. This is the most straightforward method to get the current user's details. ```APIDOC ## Get the currently authenticated user Unlike many other queries, the `Viewer` query infers the current user from the access token. This is the simplest way to get the current user. ::: info If you only require the user ID, you can use a JWT library to decode the access token and get the user ID from the `sub` field. ::: [Apollo Studio](https://studio.apollographql.com/sandbox/explorer?endpoint=https%3A%2F%2Fgraphql.anilist.co&explorerURLState=N4IgJg9gxgrgtgUwHYBcQC4QEcYIE4CeABMADp6lJFEBqAlggO74nmXXV1htUdICGiHtQC%2BPESBFA) ```graphql query { Viewer { id name } } ``` ``` -------------------------------- ### Fetch Light Novels from 2020 Source: https://context7.com/anilist/docs/llms.txt This GraphQL query retrieves light novels that started publishing in 2020, sorted by popularity. ```APIDOC ## Fetch Light Novels from 2020 ### Description This GraphQL query retrieves light novels that started publishing in 2020, sorted by popularity. ### Method POST ### Endpoint https://graphql.anilist.co ### Query ```graphql query ($page: Int = 1) { Page(page: $page, perPage: 20) { pageInfo { hasNextPage } media( type: MANGA format: NOVEL startDate_greater: 20200000 startDate_lesser: 20210000 sort: [POPULARITY_DESC, SCORE_DESC] ) { id title { romaji } averageScore popularity } } } ``` ### Request Example (Python) ```python import requests query = """ query ($page: Int = 1) { Page(page: $page, perPage: 20) { pageInfo { hasNextPage } media(type: MANGA, format: NOVEL, startDate_greater: 20200000, startDate_lesser: 20210000, sort: [POPULARITY_DESC]) { id title { romaji } averageScore } } } """ response = requests.post( 'https://graphql.anilist.co', json={'query': query, 'variables': {'page': 1}} ) print(response.json()) ``` ``` -------------------------------- ### Create Media List Entry Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/mutations.md Use the 'Save' prefix to create a new media list entry. Authentication is required, and the response includes the ID of the newly created entry. ```php 1, 'status' => 'CURRENT', ]; $response = $client->request($mutation, $variables); print_r($response); /* { "data": { "SaveMediaListEntry": { "id": 4, "status": "CURRENT" } } } */ ``` -------------------------------- ### Fetch Light Novels with Python (GraphQL) Source: https://context7.com/anilist/docs/llms.txt Use the `requests` library in Python to send a GraphQL query to the AniList API and retrieve light novel data. The response is printed as JSON. ```python import requests query = """ query ($page: Int = 1) { Page(page: $page, perPage: 20) { pageInfo { hasNextPage } media(type: MANGA, format: NOVEL, startDate_greater: 20200000, startDate_lesser: 20210000, sort: [POPULARITY_DESC]) { id title { romaji } averageScore } } } """ response = requests.post( 'https://graphql.anilist.co', json={'query': query, 'variables': {'page': 1}} ) print(response.json()) ``` -------------------------------- ### Redirect User for Authorization (PHP) Source: https://github.com/anilist/docs/blob/master/docs/guide/auth/authorization-code.md Construct the authorization URL in PHP to redirect users to AniList for authentication. Ensure the redirect_uri matches your application settings. ```php $query = [ 'client_id' => '{client_id}', 'redirect_uri' => '{redirect_uri}', // http://example.com/callback 'response_type' => 'code' ]; $url = 'https://anilist.co/api/v2/oauth/authorize?' . urldecode(http_build_query($query)); // ... echo "Login with Anilist"; ``` -------------------------------- ### OAuth2 Implicit Grant - Step 1 (HTML) Source: https://context7.com/anilist/docs/llms.txt Initiate the OAuth2 Implicit Grant flow for client-side applications by providing a link that redirects the user to AniList for authorization. The `client_id` is required. ```html Login with AniList ``` -------------------------------- ### Get the relations of a media Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media.md Retrieves all related media entries for a given media, such as prequels, sequels, and side stories, using the `relations` field. ```APIDOC ## Get the relations of a media ### Description In many cases, you might want to know all the related media of an entry: prequels, sequels, side stories, and more. We can do this with the `relations` field. Since `relations` is a connection, we will need to use the `edges` field to know how the related media are connected. ### Method QUERY ### Endpoint `/graphql` ### Parameters #### Query Parameters - **id** (Int!) - Required - The ID of the media for which to retrieve relations. ### Request Example ```graphql query ($id: Int!) { Media (id: $id) { id title { romaji } relations { edges { relationType node { id title { romaji } } } } } } ``` ### Response #### Success Response (200) - **Media** (Object) - The media object containing relation information. - **id** (Int) - The unique identifier for the media. - **title** (Object) - An object containing different title formats. - **romaji** (String) - The Romaji title of the media. - **relations** (Object) - An object containing the related media connections. - **edges** (Array of RelationEdge) - A list of edges representing the relationships. - **relationType** (RelationType) - The type of relation (e.g., prequel, sequel). - **node** (Media) - The related media node. - **id** (Int) - The unique identifier for the related media. - **title** (Object) - An object containing different title formats for the related media. - **romaji** (String) - The Romaji title of the related media. #### Response Example ```json { "data": { "Media": { "id": 1, "title": { "romaji": "Cowboy Bebop" }, "relations": { "edges": [ { "relationType": "PREQUEL", "node": { "id": 2, "title": { "romaji": "Cowboy Bebop: The Animated Series" } } } ] } } } } ``` ``` -------------------------------- ### Link for Authorization - HTML Source: https://github.com/anilist/docs/blob/master/docs/guide/auth/implicit.md Use this HTML link to redirect users to AniList for authorization. Ensure you replace `{client_id}` with your application's client ID. ```html Login with AniList ``` -------------------------------- ### Get Authenticated User Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/user.md Use the Viewer query to retrieve the current user's ID and name. This query infers the user from the access token. ```graphql query { Viewer { id name } } ``` -------------------------------- ### SaveMediaListEntry Mutation (Create/Update) Source: https://context7.com/anilist/docs/llms.txt Use SaveMediaListEntry to create a new list entry if no ID is provided, or update an existing one with an ID. All mutations require an authenticated request. Valid status values are: CURRENT, PLANNING, COMPLETED, DROPPED, PAUSED, REPEATING. ```javascript // Create a new list entry (no id → creates new entry) const createMutation = " mutation ($mediaId: Int, $status: MediaListStatus, $score: Float) { SaveMediaListEntry(mediaId: $mediaId, status: $status, score: $score) { id status score } } "; // Update an existing entry (id → updates existing entry) const updateMutation = " mutation ($listEntryId: Int, $status: MediaListStatus, $progress: Int) { SaveMediaListEntry(id: $listEntryId, status: $status, progress: $progress) { id status progress } } "; const accessToken = 'YOUR_ACCESS_TOKEN'; // Create: Add Cowboy Bebop (id: 1) as "currently watching" fetch('https://graphql.anilist.co', { method: 'POST', headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json', 'Accept': 'application/json', }, body: JSON.stringify({ query: createMutation, variables: { mediaId: 1, status: 'CURRENT', score: 0 }, }), }) .then(res => res.json()) .then(data => { console.log(data); // { "data": { "SaveMediaListEntry": { "id": 4, "status": "CURRENT", "score": 0 } } } // Update: mark the entry as COMPLETED using the returned list entry id return fetch('https://graphql.anilist.co', { method: 'POST', headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json', 'Accept': 'application/json', }, body: JSON.stringify({ query: updateMutation, variables: { listEntryId: data.data.SaveMediaListEntry.id, status: 'COMPLETED', progress: 26 }, }), }); }) .then(res => res.json()) .then(data => console.log(data)); // { "data": { "SaveMediaListEntry": { "id": 4, "status": "COMPLETED", "progress": 26 } } } ``` -------------------------------- ### Get Light Novels from 2020 Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media.md Fetch all manga with the NOVEL format published in 2020. Uses `startDate_greater` and `startDate_lesser` for date range filtering. The `page` argument defaults to 1. ```graphql query ($page: Int = 1) { Page(page: $page) { pageInfo { hasNextPage } media( type: MANGA format: NOVEL startDate_greater: 20200000 startDate_lesser: 20210000 ) { id title { romaji } } } } ``` -------------------------------- ### Link for Authorization - PHP Source: https://github.com/anilist/docs/blob/master/docs/guide/auth/implicit.md Generate a URL in PHP to redirect users to AniList for authorization. Replace `{client_id}` with your application's client ID and ensure proper URL encoding. ```php $query = [ 'client_id' => '{client_id}', 'response_type' => 'token' ]; $url = 'https://anilist.co/api/v2/oauth/authorize?' . urldecode(http_build_query($query)); // ... echo "Login with Anilist"; ``` -------------------------------- ### Redirect User for Authorization (HTML) Source: https://github.com/anilist/docs/blob/master/docs/guide/auth/authorization-code.md Use this HTML link to initiate the authorization process by redirecting the user to AniList's authorization endpoint. ```html Login with AniList ``` -------------------------------- ### Get all light novels from 2020 Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media.md This query retrieves all light novels published in the year 2020 by filtering the media type, format, and date range. The `page` argument defaults to 1. ```APIDOC ## Get all light novels from 2020 It's time to get a bit more advanced with our queries. In this example, we will be getting all the light novels that started publishing in 2020. Light novels are found under the `MANGA` type with the `NOVEL` format. We can use the `format` argument to filter by the format of the media. To get a range of dates, we will use the `startDate_greater` and `startDate_lesser` arguments. These arguments are of the `FuzzyDateInt` type, which means they are integers that represent a date. Also notice how instead of making the `page` argument required, we are setting it to `1` by default. ::: info `FuzzyDateInt` is in the format of `YYYYMMDD`. ::: ```graphql query ($page: Int = 1) { Page(page: $page) { pageInfo { hasNextPage } media( type: MANGA format: NOVEL startDate_greater: 20200000 startDate_lesser: 20210000 ) { id title { romaji } } } } ``` ``` -------------------------------- ### Activity Query Parameters Source: https://github.com/anilist/docs/blob/master/docs/reference/query.md This section outlines the various parameters available for querying activities. These parameters allow for filtering by user ID, message ID, media ID, activity type, reply status, creation time, and ID ranges. Sorting options are also provided. ```APIDOC ## Query Parameters for Activities ### Description Allows filtering and sorting of activities based on various criteria. ### Parameters #### Query Parameters - **userId** (Int) - Filter by the owner user id. - **messengerId** (Int) - Filter by the id of the user who sent a message. - **mediaId** (Int) - Filter by the associated media id of the activity. - **type** (ActivityType) - Filter by the type of activity. - **isFollowing** (Boolean) - Filter activity to users who are being followed by the authenticated user. - **hasReplies** (Boolean) - Filter activity to only activity with replies. - **hasRepliesOrTypeText** (Boolean) - Filter activity to only activity with replies or is of type text. - **createdAt** (Int) - Filter by the time the activity was created. - **id_not** (Int) - Filter by the activity id. - **id_in** ([Int]) - Filter by the activity id. - **id_not_in** ([Int]) - Filter by the activity id. - **userId_not** (Int) - Filter by the owner user id. - **userId_in** ([Int]) - Filter by the owner user id. - **userId_not_in** ([Int]) - Filter by the owner user id. - **messengerId_not** (Int) - Filter by the id of the user who sent a message. - **messengerId_in** ([Int]) - Filter by the id of the user who sent a message. - **messengerId_not_in** ([Int]) - Filter by the id of the user who sent a message. - **mediaId_not** (Int) - Filter by the associated media id of the activity. - **mediaId_in** ([Int]) - Filter by the associated media id of the activity. - **mediaId_not_in** ([Int]) - Filter by the associated media id of the activity. - **type_not** (ActivityType) - Filter by the type of activity. - **type_in** ([ActivityType]) - Filter by the type of activity. - **type_not_in** ([ActivityType]) - Filter by the type of activity. - **createdAt_greater** (Int) - Filter by the time the activity was created. - **createdAt_lesser** (Int) - Filter by the time the activity was created. - **sort** ([ActivitySort]) - The order the results will be returned in. ``` -------------------------------- ### Get Media Relations Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media.md Retrieves all related media entries for a given media ID, such as prequels and sequels. It uses the `relations` field and requires navigating through `edges` to access connected media nodes. ```graphql query ($id: Int!) { Media (id: $id) { id title { romaji } relations { edges { relationType node { id title { romaji } } } } } } ``` -------------------------------- ### Activity Source: https://github.com/anilist/docs/blob/master/docs/reference/query.md Queries for activity information with filtering options. ```APIDOC ## Activity ### Description Activity query. ### Query - **id** (Int) - Filter by the activity id - **userId** (Int) ``` -------------------------------- ### Get a full media list collection Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media-list.md Retrieve the user's entire media list, split by status and custom lists. This query is useful when you need the complete list of media a user has tracked. ```APIDOC ## Get a full media list collection ### Description Retrieves the user's entire media list, split by status and custom lists. This query is useful when you need the complete list of media a user has tracked. The `type` argument is required, and you must provide either a `userId` or `userName`. ### Method POST ### Endpoint https://graphql.anilist.co ### Parameters #### Query Parameters - **type** (MediaType!) - Required - The type of media to retrieve (e.g., ANIME, MANGA). - **userId** (Int) - Optional - The ID of the user. - **userName** (String) - Optional - The username of the user. ### Request Example ```graphql query ($type: MediaType!, $userId: Int!) { MediaListCollection(type: $type, userId: $userId) { lists { name entries { id media { id title { romaji } } } } } } ``` ### Response #### Success Response (200) - **lists** (Array) - An array of lists, each containing entries. - **name** (String) - The name of the list (e.g., 'Watching', 'Completed', custom list name). - **entries** (Array) - An array of media list entries within the list. - **id** (Int) - The ID of the media list entry. - **media** (Object) - The media object associated with the list entry. - **id** (Int) - The ID of the media. - **title** (Object) - The title of the media. - **romaji** (String) - The Romaji title of the media. ``` -------------------------------- ### Basic Media Query Source: https://context7.com/anilist/docs/llms.txt Fetches a single anime or manga entry by its unique integer ID. Media IDs can be found in the AniList URL. ```APIDOC ## Media Query ### Description Fetches a single anime or manga entry by its unique integer ID. ### Method POST ### Endpoint https://graphql.anilist.co ### Parameters #### Request Body - **query** (String) - Required - The GraphQL query string. - **variables** (Object) - Optional - Variables to be used in the query. ### Request Example ```javascript const query = ` query ($id: Int) { Media(id: $id, type: ANIME) { id title { romaji english native } episodes status averageScore genres } } `; const variables = { id: 1 }; // Cowboy Bebop fetch('https://graphql.anilist.co', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', }, body: JSON.stringify({ query, variables }), }) .then(res => res.json()) .then(data => console.log(data)); ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **Media** (Object) - The requested media entry. - **id** (Int) - The unique ID of the media. - **title** (Object) - The title of the media. - **romaji** (String) - The Romaji title. - **english** (String) - The English title. - **native** (String) - The native language title. - **episodes** (Int) - The number of episodes. - **status** (String) - The current status of the media (e.g., FINISHED, RELEASING). - **averageScore** (Int) - The average score of the media. - **genres** (Array of Strings) - The genres associated with the media. #### Response Example ```json { "data": { "Media": { "id": 1, "title": { "romaji": "Cowboy Bebop", "english": "Cowboy Bebop", "native": "カウボーイビバップ" }, "episodes": 26, "status": "FINISHED", "averageScore": 86, "genres": ["Action", "Adventure", "Drama", "Sci-Fi"] } } } ``` ``` -------------------------------- ### MediaListOptionsInput Fields Source: https://github.com/anilist/docs/blob/master/docs/reference/input/medialistoptionsinput.md Defines the configurable options for a user's media list, including sorting, splitting, and custom list settings. ```APIDOC ## MediaListOptionsInput ### Description A user's list options for anime or manga lists. ### Fields - **sectionOrder** (String[]): The order each list should be displayed in. - **splitCompletedSectionByFormat** (Boolean): If the completed sections of the list should be separated by format. - **customLists** (String[]): The names of the user's custom lists. - **advancedScoring** (String[]): The names of the user's advanced scoring sections. - **advancedScoringEnabled** (Boolean): If advanced scoring is enabled. - **theme** (String): list theme. ``` -------------------------------- ### Example API Unavailable Error Response Source: https://github.com/anilist/docs/blob/master/docs/guide/considerations.md This JSON structure represents an error response when the AniList API is temporarily unavailable due to stability issues. It includes a GraphQL error message and a status code of 403. ```json { "errors": [ { "message": "The AniList API has been temporarily disabled due to severe stability issues. Please check the official AniList Discord for more information.", "status": 403, "locations": [ { "line": 1, "column": 1 } ] } ], "data": null } ``` -------------------------------- ### SaveRecommendation Source: https://github.com/anilist/docs/blob/master/docs/reference/mutation.md Recommend a media. Requires mediaId, mediaRecommendationId, and a rating. ```APIDOC ## SaveRecommendation ### Description Recommendation a media. ### Method MUTATION ### Parameters #### Mutation Parameters - **mediaId** (Int) - Required - The id of the base media - **mediaRecommendationId** (Int) - Required - The id of the media to recommend - **rating** (RecommendationRating) - Required - The rating to give the recommendation ### Response #### Success Response - **SaveRecommendation** (Recommendation) - Returns the created recommendation object. ``` -------------------------------- ### Advanced Media Browse/Filter Query Structure Source: https://context7.com/anilist/docs/llms.txt Demonstrates the structure for advanced media browsing and filtering using the `Page` query with various filter arguments on the `media` field. Supports multi-level sorting. ```graphql # The Page query accepts a rich set of filter arguments on the `media` field, mirroring AniList's browse page. # Date filters use the `FuzzyDateInt` format (`YYYYMMDD`). # The `sort` argument accepts an array of `MediaSort` enum values for multi-level sorting. ``` -------------------------------- ### Get a Single Media List Entry by ID Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media-list.md Use this query to fetch a specific media list entry using its unique ID. The `id` field refers to the list entry ID, not the media ID. Arguments like `mediaId` and `userId` will be ignored if not provided. ```graphql query ($id: Int, $mediaId: Int, $userId: Int) { MediaList(id: $id, mediaId: $mediaId, userId: $userId) { id media { id title { romaji } } } } ``` -------------------------------- ### Get Full Media List Collection Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media-list.md Fetch the user's complete media list, automatically organized by status and custom lists. This query is limited to the 11,000 most recently updated unique entries. Ensure to include custom lists in your processing to avoid missing entries. ```graphql query ($type: MediaType!, $userId: Int!) { MediaListCollection(type: $type, userId: $userId) { lists { name entries { id media { id title { romaji } } } } } } ``` -------------------------------- ### Make a GraphQL API Request Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/index.md Use this code to make a POST request to the AniList GraphQL API. Include your query and variables in the payload. Ensure you are sending a POST request to https://graphql.anilist.co. ```javascript const query = ` query ($id: Int) { Media(id: $id) { id title { romaji english native } } } `; const variables = { id: 15125 }; fetch('https://graphql.anilist.co', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', }, body: JSON.stringify({ query, variables }) }) .then(response => response.json()) .then(data => console.log(data)); ``` ```php 15125 ]; $ch = curl_init('https://graphql.anilist.co'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS', json_encode(['query' => $query, 'variables' => $variables])); $response = curl_exec($ch); curl_close($ch); $data = json_decode($response, true); print_r($data); ?> ``` ```python import requests query = ''' query ($id: Int) { Media(id: $id) { id title { romaji english native } } } ''' variables = { 'id': 15125 } url = 'https://graphql.anilist.co' response = requests.post(url, json={'query': query, 'variables': variables}) print(response.json()) ``` ```rust use reqwest::Error; #[tokio::main] async fn main() -> Result<(), Error> { let query = r#"query ($id: Int) { Media(id: $id) { id title { romaji english native } } }"#; let variables = serde_json::json!({ "id": 15125 }); let client = reqwest::Client::new(); let response = client.post("https://graphql.anilist.co") .json(&serde_json::json!({ "query": query, "variables": variables })) .send() .await?; let data: serde_json::Value = response.json().await?; println!("{}", data); Ok(()) } ``` -------------------------------- ### Get a single list entry by ID Source: https://github.com/anilist/docs/blob/master/docs/guide/graphql/queries/media-list.md Retrieve a specific media list entry using its unique ID. The `id` field refers to the list entry ID, not the media ID. This entry ID can be obtained from the `mediaListEntry` field on a `Media` object, the `SaveMediaListEntry` mutation, or the `MediaListCollection` query. ```APIDOC ## Get a single list entry by ID ### Description Retrieves a specific media list entry using its unique ID. The `id` field refers to the list entry ID, not the media ID. This entry ID can be obtained from the `mediaListEntry` field on a `Media` object, the `SaveMediaListEntry` mutation, or the `MediaListCollection` query. ### Method POST ### Endpoint https://graphql.anilist.co ### Parameters #### Query Parameters - **id** (Int) - Required - The ID of the media list entry. - **mediaId** (Int) - Optional - The ID of the media. - **userId** (Int) - Optional - The ID of the user. ### Request Example ```graphql query ($id: Int, $mediaId: Int, $userId: Int) { MediaList(id: $id, mediaId: $mediaId, userId: $userId) { id media { id title { romaji } } } } ``` ### Response #### Success Response (200) - **id** (Int) - The ID of the media list entry. - **media** (Object) - The media object associated with the list entry. - **id** (Int) - The ID of the media. - **title** (Object) - The title of the media. - **romaji** (String) - The Romaji title of the media. ``` -------------------------------- ### Studio Object Fields Source: https://github.com/anilist/docs/blob/master/docs/reference/object/studio.md This snippet details the fields available for the Studio object, including their types and descriptions. It covers basic information like id and name, media-related fields, and user-specific fields like isFavourite. ```APIDOC ## Studio Object ### Description Represents an animation or production company. ### Fields - **id** (Int!): The id of the studio. - **name** (String!): The name of the studio. - **isAnimationStudio** (Boolean!): If the studio is an animation studio or a different kind of company. - **media** (MediaConnection): The media the studio has worked on. - **sort** ([MediaSort]): The order the results will be returned in. - **isMain** (Boolean): If the studio was the primary animation studio of the media. - **onList** (Boolean): - **page** (Int): The page. - **perPage** (Int): The amount of entries per page, max 25. - **siteUrl** (String): The url for the studio page on the AniList website. - **isFavourite** (Boolean!): If the studio is marked as favourite by the currently authenticated user. - **favourites** (Int): The amount of user's who have favourited the studio. ``` -------------------------------- ### User Source: https://github.com/anilist/docs/blob/master/docs/reference/query.md Queries for user information with various filtering and sorting options. ```APIDOC ## User ### Description Queries for user information. ### Query - **id** (Int) - Filter by the user id - **name** (String) - Filter by the name of the user - **isModerator** (Boolean) - Filter to moderators only if true - **search** (String) - Filter by search query - **sort** ([UserSort]) - The order the results will be returned in ```