Something went wrong. Try again.
A Zig client for the Paperless-ngx REST API, with streaming uploads, task waiting and a command-line tool.
Something went wrong. Try again.
2.8 kB · 79 lines
Zig
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! A client for the Paperless-ngx REST API.//!//! `Client` is the way in. It talks HTTP through zig-http and builds the//! multipart bodies of uploads with zig-mime's media type table, and//! otherwise is a typed reading of the API Paperless-ngx 3 serves as//! version 10://!//! * `Client.documents` -- listing, searching, reading, changing, deleting,//! downloading, uploading, and editing many at once.//! * `Client.tasks` -- the background work an upload becomes.//! * `Client.tags`, `correspondents`, `documentTypes`, `storagePaths`,//! `customFields`, `savedViews`, `shareLinks`, `users`, `groups` -- the//! same five calls each: list, get, create, update, delete.//! * `Client.statistics`, `status`, `remoteVersion`, `search`, and the trash.//! * `Client.raw` -- anything else, by path.//!//! `obtainToken` exchanges a username and password for an API token.
const std = @import("std");const Io = std.Io;const Allocator = std.mem.Allocator;
pub const Client = @import("Client.zig");pub const Documents = Client.Documents;pub const Tasks = Client.Tasks;pub const resource = @import("resource.zig");pub const models = @import("models.zig");pub const query = @import("query.zig");pub const multipart = @import("multipart.zig");pub const json = @import("json.zig");
pub const Id = models.Id;pub const Page = models.Page;pub const Clearable = json.Clearable;
pub const Document = models.Document;pub const DocumentFields = models.DocumentFields;pub const Tag = models.Tag;pub const Correspondent = models.Correspondent;pub const DocumentType = models.DocumentType;pub const StoragePath = models.StoragePath;pub const CustomField = models.CustomField;pub const Task = models.Task;
/// Exchanges a username and password for the user's API token, creating/// one if the user has none. The token is the same one every time, until/// somebody regenerates it in the web interface. Owned by the caller.pub fn obtainToken( io: Io, gpa: Allocator, base_url: []const u8, username: []const u8, password: []const u8,) (Client.Error)![]u8 { var client: Client = try .init(io, gpa, .{ .base_url = base_url }); defer client.deinit(); const Token = struct { token: []const u8 }; const parsed = try client.sendJson(Token, .post, "token/", .{}, .{ .username = username, .password = password, }); defer parsed.deinit(); return gpa.dupe(u8, parsed.value.token);}
test { std.testing.refAllDecls(@This()); std.testing.refAllDecls(Client); std.testing.refAllDecls(Documents); std.testing.refAllDecls(Tasks); std.testing.refAllDecls(resource); _ = json; _ = models; _ = query; _ = multipart;}