# Fetch Gallery

> Retrieves a list of gallery cards. When the type is set to `Recent`, the endpoint returns cards from all users. For any other specified type, it returns cards only from the corresponding category.

{% openapi src="/files/gJlKKDx0bj3wUm8btUfT" path="/api/task/cards" method="post" expanded="true" %}
[openapi3\_0 (5).json](https://4246159311-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJc2Olnfmy17B0BpCm82C%2Fuploads%2Fgit-blob-5050e1639ebc3dccc8449cfb5488b2a8e5510689%2Fopenapi3_0%20\(5\).json?alt=media)
{% endopenapi %}

### Examples

{% tabs %}
{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"time"
)

const BaseURI = "https://hyperhuman.deemos.com/api"

var client = &http.Client{Timeout: 10 * time.Second}

type CommonError struct {
	Error *string `json:"error,omitempty"`
}

type GalleryType string

const (
	Recent   GalleryType = "Recent"
	Featured GalleryType = "Featured"
	Mine     GalleryType = "Mine"
	Group    GalleryType = "Group"
	Story    GalleryType = "Story"
)

type CardStatusType string

const (
	All       CardStatusType = "All"
	Generated CardStatusType = "Generated"
	Liked     CardStatusType = "Liked"
	Packing   CardStatusType = "Packing"
	Packed    CardStatusType = "Packed"
)

type TaskType string

const (
	DreamFace   TaskType = "DreamFace"
	ImagineFace TaskType = "ImagineFace"
	API         TaskType = "API"
	Panorama    TaskType = "Panorama"
	Rodin       TaskType = "Rodin"
	Media2Face  TaskType = "Media2Face"
)

type TaskStep string

const (
	Created         TaskStep = "Created"
	Preprocess      TaskStep = "Preprocess"
	Generate        TaskStep = "Generate"
	ModelGenerate   TaskStep = "ModelGenerate"
	TextureGenerate TaskStep = "TextureGenerate"
	ModelRefine     TaskStep = "ModelRefine"
	TextureRefine   TaskStep = "TextureRefine"
)

type UserBasicInformation struct {
	UserUUID  string `json:"user_uuid,omitempty"`
	Username  string `json:"username,omitempty"`
	AvatarUrl string `json:"avatar_url,omitempty"`
	Email     string `json:"email,omitempty"`
}

type GroupSettings struct {
	AllowedStyle       []string `json:"allowed_style,omitempty"`
	AllowedTopology    []string `json:"allowed_topology,omitempty"`
	MaxMemberCount     *int     `json:"max_member_count,omitempty"`
	AllowPreview       *bool    `json:"allow_preview,omitempty"`
	AdditionalSettings []string `json:"additional_settings,omitempty"`
}

type GroupMeta struct {
	Uuid           string         `json:"uuid"`
	Name           string         `json:"name"`
	MemberCount    int            `json:"member_count"`
	ExpirationDate string         `json:"expiration_date"`
	Settings       *GroupSettings `json:"settings"`
}

type GalleryResponse struct {
	TaskUUID     string               `json:"task_uuid"`
	Type         TaskType             `json:"type"`
	ImageUrl     *string              `json:"image_url,omitempty"`
	VideoUrl     *string              `json:"video_url,omitempty"`
	Prompt       *string              `json:"prompt,omitempty"`
	NumLike      int                  `json:"num_like"`
	IsLike       bool                 `json:"is_like"`
	Time         string               `json:"time"`
	Author       UserBasicInformation `json:"author"`
	UserState    *string              `json:"user_state,omitempty"`
	Lisenced     *bool                `json:"lisenced,omitempty"`
	Title        *string              `json:"title,omitempty"`
	Style        *string              `json:"style,omitempty"`
	IsPrivate    *bool                `json:"is_private,omitempty"`
	Group        *GroupMeta           `json:"group,omitempty"`
	IsGenme      *bool                `json:"is_genme,omitempty"`
	AllowPreview *bool                `json:"allow_preview,omitempty"`
	Step         string               `json:"step"`
	PendingJobs  []string             `json:"pending_jobs,omitempty"`
}

func FetchGallery(token *string, pageIndex int, galleryType GalleryType, userType *CardStatusType, taskType *TaskType, taskStep []TaskStep, groupUuid *string, tagIds []int) (string, []GalleryResponse, error) {
	// Create the request body
	data := map[string]any{"page_num": pageIndex, "type": galleryType}
	if userType != nil {
		data["user_type"] = userType
	}
	if taskType != nil {
		data["task_type"] = taskType
	}
	if taskStep != nil && len(taskStep) > 0 {
		data["task_step"] = taskStep
	}

	if groupUuid != nil {
		data["group_uuid"] = groupUuid
	}

	if tagIds != nil && len(tagIds) > 0 {
		data["tag_ids"] = tagIds
	}

	jsonData, err := json.Marshal(data)
	if err != nil {
		return "", nil, err
	}

	// Create the request
	req, err := http.NewRequest("POST", fmt.Sprintf("%s/task/cards", BaseURI), bytes.NewBuffer(jsonData))
	if err != nil {
		return "", nil, err
	}

	// Set headers
	if token != nil {
		req.Header.Set("Authorization", "Bearer "+*token)
	}
	req.Header.Set("Content-Type", "application/json")

	resp, err := client.Do(req)
	if err != nil {
		return "", nil, err
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusCreated {
		return "", nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
	}

	var responseData []GalleryResponse
	err = json.NewDecoder(resp.Body).Decode(&responseData)
	if err != nil {
		return "", nil, err
	}

	return resp.Header.Get("Subscription-Key"), responseData, nil
}

// LoginResponse represents the response from the login endpoint.
type LoginResponse struct {
	CommonError
	UserBasicInformation
	Token string `json:"token,omitempty"`
}

// Login performs JWT-based authentication.
func Login(email, password string) (string, *UserBasicInformation, error) {
	payload := map[string]string{"password": password, "email": email}

	jsonData, err := json.Marshal(payload)
	if err != nil {
		return "", nil, err
	}

	req, err := http.NewRequest("POST", fmt.Sprintf("%s/user/login", BaseURI), bytes.NewBuffer(jsonData))
	if err != nil {
		return "", nil, err
	}

	req.Header.Set("Content-Type", "application/json")

	resp, err := client.Do(req)
	if err != nil {
		return "", nil, err
	}
	defer resp.Body.Close()

	var responseData LoginResponse
	err = json.NewDecoder(resp.Body).Decode(&responseData)
	if err != nil {
		return "", nil, err
	}

	if responseData.Error != nil {
		return "", nil, fmt.Errorf("error: %s", *responseData.Error)
	}

	return responseData.Token, &responseData.UserBasicInformation, nil
}

func main() {
	email := "example@example.com"
	password := "<your password>"
	token, info, _ := Login(email, password)
	fmt.Println("Logged in successfully. Token:", token, "BasicInformation:", *info)
	userType := All
	_, result, _ := FetchGallery(&token, 0, Mine, &userType, nil, nil, nil, nil)
	fmt.Printf("Fetched %d Gallery items\n", len(result))
	if len(result) > 0 {
		fmt.Printf("The the first gallery item has got %d like(s).\n", result[0].NumLike)
	}
}

```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://on-premises.docs.hyper3d.ai/task/fetch-gallery.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
