# Registering Papers

## Types

***

#### PaperContext

| Field       | Type                              | Description                                                                    |
| ----------- | --------------------------------- | ------------------------------------------------------------------------------ |
| id          | string                            | Unique id of the paper                                                         |
| label       | string                            | Label of the paper                                                             |
| price       | number?                           | Price of the paper                                                             |
| icon        | string?                           | [Fontawesome icon](https://fontawesome.com/icons) to use in menus.             |
| canPublish  | function(source: number): boolean | Function that determines is player allowed to publish article from this paper. |
| canDelete   | function(source: number): boolean | Function that determines is player allowed to delete article from this paper.  |
| onPurchased | function(source: number)?         | Function that executes when someone purchased a newspaper from this paper.     |

## How to Register Paper?

***

You can register paper using API.RegisterPaper. You can find default WeazelNews paper in

`no-newspaper/newspapers/sh_weazelnews.lua` You can copy this file and edit variables to create a new paper or you can register paper from another resource using API. API examples can be found in `no-newspaper/api/server/examples.lua`

## Examples

***

```lua
local API = exports["no-newspaper"]
local WeazelNews = API:RegisterPaper({
    id = "weazelnews",
    label = "Weazel News",
    canPublish = function(source)
        local player = ESX.GetPlayerFromId(source)
        return player and player.job.name == "weazelnews"
    end,
    canDelete = function(source)
        local player = ESX.GetPlayerFromId(source)
        return player and player.job.name == "weazelnews"
    end
})

local function PrintArticles(articles)
    for _, article in pairs(articles) do
        print(article.id)
        print(article.header)
        print(article.author)
        print(article.content)
        print(article.image)
        print(article.date)
    end
end

local function PrintAllArticles()
    local articles = WeazelNews:GetAllArticles()

    PrintArticles(articles)
end

local function PrintArticlesByDate(date)
    local articles = WeazelNews:GetArticles(date)

    PrintArticles(articles)
end

RegisterNetEvent("jail:player", function(source, months)
    local player = ESX.GetPlayerFromId(source)

    if not player then return end

    local fullname = player.get("firstname") .. " " .. player.get("lastname")

    WeazelNews:Publish({
        header = "Jail Sentence",
        author = "Bolingbroke Penitentiary",
        content = fullname .. " sentenced for " .. months .. " months in jail!"
    })
end)

```


---

# 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://none-fivem.gitbook.io/nonem/resources/no-newspaper/configuration/registering-papers.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.
