๐Ÿ€ ATproto library for gleam
atproto library gleam
35

Configure Feed

Select the types of activity you want to include in your feed.

possum: add create_record

kacaii.dev (Jul 1, 2026, 3:37 PM -0300) 0b8964c8 ff44a45a

+86 -5
+86 -5
src/possum.gleam
··· 221 221 option.None -> values 222 222 } 223 223 224 - let body = 225 - json.object(values) 226 - |> json.to_string 227 - 228 224 request 229 225 |> request.set_method(http.Post) 230 226 |> request.set_header("content-type", "application/json") 231 227 |> request.set_path(com_atproto_server <> ".createSession") 232 - |> request.set_body(body) 228 + |> request.set_body(json.to_string(json.object(values))) 233 229 } 234 230 235 231 /// Refresh an authentication session. ··· 372 368 |> request.set_method(http.Get) 373 369 |> request.set_path(com_atproto_repo <> ".describeRepo") 374 370 |> request.set_query([#("repo", did.to_string(did))]) 371 + } 372 + 373 + /// Create a single new repository record. 374 + /// Requires auth, implemented by PDS. 375 + /// 376 + /// ## Body 377 + /// 378 + /// - **collection**: The NSID of the record collection. 379 + /// - **repo**: The handle or DID of the repo (aka, current account). 380 + /// - **rkey**: The Record Key. 381 + /// - **swapCommit**: Compare and swap with the previous commit by CID. 382 + /// - **validate**: Can be set to 'false' to skip Lexicon schema validation 383 + /// of record data, 'true' to require it, or leave unset to validate 384 + /// only for known Lexicons. 385 + /// 386 + /// ## Examples 387 + /// 388 + /// ```gleam 389 + /// import gleam/http/request 390 + /// import possum 391 + /// 392 + /// let request = 393 + /// request.new() 394 + /// |> request.set_host("personal.data-server.pds") 395 + /// |> possum.authorized("access-token") 396 + /// |> possum.create_record( 397 + /// did: did, 398 + /// rkey: "wibble", 399 + /// collection: "wibble.wobble.woo", 400 + /// record: [], 401 + /// swap_commit: option.None, 402 + /// validate: option.None, 403 + /// ) 404 + /// ``` 405 + /// 406 + /// ## Response 407 + /// 408 + /// ```json 409 + /// { 410 + /// "cid": "string", 411 + /// "uri": "string", 412 + /// "commit": { 413 + /// "cid": "string", 414 + /// "rev": "string" 415 + /// }, 416 + /// "validationStatus": "valid" 417 + /// } 418 + /// ``` 419 + /// 420 + /// Endpoint Docs: [/xrpc/com.atproto.repo.createRecord](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/POST/xrpc/com.atproto.repo.createRecord) 421 + pub fn create_record( 422 + request: request.Request(_), 423 + did: did.Did, 424 + rkey rkey: option.Option(String), 425 + collection collection: String, 426 + record record: List(#(String, json.Json)), 427 + swap_commit swap_commit: option.Option(String), 428 + validate validate: option.Option(Bool), 429 + ) -> request.Request(_) { 430 + let body = [ 431 + #("collection", json.string(collection)), 432 + #("record", json.object(record)), 433 + #("repo", json.string(did.to_string(did))), 434 + ] 435 + 436 + let body = case rkey { 437 + option.Some(value) -> [#("rkey", json.string(value)), ..body] 438 + option.None -> body 439 + } 440 + 441 + let body = case swap_commit { 442 + option.Some(value) -> [#("swapCommit", json.string(value)), ..body] 443 + option.None -> body 444 + } 445 + 446 + let body = case validate { 447 + option.Some(value) -> [#("swapCommit", json.bool(value)), ..body] 448 + option.None -> body 449 + } 450 + 451 + request 452 + |> request.set_method(http.Post) 453 + |> request.set_header("content-type", "application/json") 454 + |> request.set_body(json.to_string(json.object(body))) 455 + |> request.set_path(com_atproto_repo <> ".createRecord") 375 456 } 376 457 377 458 /// Get a single record from a repository. Does not require auth.