Nostr-API Documentation

You can interact with the Nostr protocol through this REST API. Supports posting notes, reacting to notes, replying to notes, sending direct messages and reading notes based on filters or mentions.

IMPORTANT!

This API is under development.
Please DO NOT use with your main npub until this notice is removed.

POST /

A simple API to perform actions on the Nostr protocol.


Authentication

To use the API you will need to send your nsec in hex format in the HTTP request header as X-Auth-NSEC.

Responses

Success:

{ "status": "success", "action": "action_name", "notes": [ { "id": "note_id", "content": "Note content", "tags": [["p", "public_key"]], "created_at": 1695999999 } ] }


Error:

{ "status": "error", "message": "Invalid JSON input or missing 'action' field." }



Relay Actions

Post a Note

Payload:

{ "action": "postNote", "content": "Hello world!", "relay_url": "wss://relay.damus.io" }


Parameters:
FieldTypeDescriptionRequired?Default
actionstringThe action to perform = postNoterequired
contentstringThe content of the note.optional
relay_urlstringThe WebSocket URL of the relay.optionalwss://relay.damus.io


React to a Note

Payload:

{ "action": "reactToNote", "note_id": "cd9d5761f085d73b47d2968825750068cbd7bfb5e64805b97dfc820822fb438b", "reaction": "+", "relay_url": "wss://relay.damus.io" }


Parameters:
FieldTypeDescriptionRequired?Default
actionstringThe action to perform = reactToNoterequired
note_idstringThe ID of the note to react to or reply to.requird
reactionstringThe reaction (e.g., +, 👍).optional
relay_urlstringThe WebSocket URL of the relay.optionalwss://relay.damus.io


Reply to a Note

Payload:

{ "action": "replyToNote", "note_id": "cd9d5761f085d73b47d2968825750068cbd7bfb5e64805b97dfc820822fb438b", "reply_content": "This is a reply!", "author_pubkey": "pubkey_of_original_author", "relay_url": "wss://relay.damus.io" }


Parameters:
FieldTypeDescriptionRequired?Default
actionstringThe action to perform = replyToNoterequired
note_idstringThe ID of the note to react to or reply to.required
reply_contentstringThe content of the reply.required
author_pubkeystringThe public key of the author of the note being replied to.optional
relay_urlstringThe WebSocket URL of the relay.optionalwss://relay.damus.io


Send a Direct Message

Payload:

{ "action": "sendDirectMessage", "recipient": "pubkey_of_the_recipient", "content": "This is a message", "relay_url": "wss://relay.damus.io" }


Parameters:
FieldTypeDescriptionRequired?Default
actionstringThe action to perform = sendDirectMessagerequired
recipientstringThe public key of the recipient of the message.required
contentstringThe content of the note.required
relay_urlstringThe WebSocket URL of the relay.optionalwss://relay.damus.io


Read Direct Message(s)

Payload:

{ "action": "readDirectMessage", "limit": 5, "relay_url": "wss://relay.damus.io" }


Parameters:
FieldTypeDescriptionRequired?Default
actionstringThe action to perform = readDirectMessagerequired
limitintegerThe maximum number of results to return.optional20
relay_urlstringThe WebSocket URL of the relay.optionalwss://relay.damus.io


Read Notes by Filter

Payload:

{ "action": "readNotesByFilter", "filter": { "kinds": [1], "authors": ["author_public_key_hex"], "tags": [ {"t": "test"} ] }, "limit": 10, "relay_url": "wss://relay.damus.io" }


Parameters:
FieldTypeDescriptionRequired?Default
actionstringThe action to perform = readNotesByFilterrequired
filterobjectFilter by kinds, authors and/or tags. Tags are evaluated as OR.optional
limitintegerThe maximum number of results to return.optional20
relay_urlstringThe WebSocket URL of the relay.optionalwss://relay.damus.io


Read Notes Mentioning Me

Payload:

{ "action": "readNotesMentioningMe", "limit": 5, "relay_url": "wss://relay.damus.io" }


Parameters:
FieldTypeDescriptionRequired?Default
actionstringThe action to perform = readNotesMentioningMerequired
limitintegerThe maximum number of results to return.optional20
relay_urlstringThe WebSocket URL of the relay.optionalwss://relay.damus.io


Utility Actions

Convert Key

Payload:

{ "action": "convertKey", "nsec_hex": "nsec_hex", "nsec_bech32": "nsec_bech32", "npub_hex": "npub_hex", "npub_bech32": "npub_bech32" }


Parameters:
FieldTypeDescriptionRequired?Default
actionstringThe action to perform = convertKeyrequired
nsec_hexstringThe nsec in hex format to be converted.optional
nsec_bech32stringThe nsec in bech32 format to be converted.optional
npub_hexstringThe npub in hex format to be converted.optional
npub_bech32stringThe npub in bech32 format to be converted.optional


Encrypt Content

Payload:

{ "action": "encryptContent", "recipient": "pubkey_of_the_recipient", "content": "This is a message" }


Parameters:
FieldTypeDescriptionRequired?Default
actionstringThe action to perform = encryptContentrequired
recipientstringThe public key of the recipient of the message.required
contentstringThe content to be encrypted.required


Decrypt Content

Payload:

{ "action": "decryptContent", "sender": "pubkey_of_the_sender", "encrypted_content": "LJxTnKadoSp+fBjIobgK85hA04jVmAg9PRiTMaPOoS4=?iv=kvompmANGDiCChSvY1w0Qg==" }


Parameters:
FieldTypeDescriptionRequired?Default
actionstringThe action to perform = decryptContentrequired
senderstringThe public key of the sender of the message.required
encrypted_contentstringThe encrypted content to be decrypted.required