# Publish NWC Request

Publishes the NWC request event and returns the response

### Without Webhook

`POST` `https://api.getalby.com/nwc/nip47`

**Request Body**

| Name                                           | Type                                        | Description                                                                      |
| ---------------------------------------------- | ------------------------------------------- | -------------------------------------------------------------------------------- |
| relayUrl                                       | string                                      | If no relay is provided, it uses the default relay (wss\://relay.getalby.com/v1) |
| walletPubkey<mark style="color:red;">\*</mark> | string                                      | Pubkey of the NWC Wallet Provider                                                |
| event<mark style="color:red;">\*</mark>        | JSON object (see [example](#event-example)) | **Signed** request event                                                         |

#### Event Example

```json
{
  "id": "a16ycf4a01bcxx........xxxxx",
  "pubkey": "a16y69effexxxx........xxxxx",
  "created_at": 1700000021,
  "kind": 23194,
  "tags": [
    [
      "p",
      "a16y6sfa01bcxx........xxxxx"
    ]
  ],
  "content": "<encrypted content>",
  "sig": "<signature>"
}
// Source: https://pkg.go.dev/github.com/nbd-wtf/go-nostr@v0.30.0#Event
```

#### Response

{% tabs %}
{% tab title="200: OK" %}

```javascript
{
  "event": {
    "id": "a16ycf4a01bcxx........xxxxx",
    "pubkey": "a16y69effexxxx........xxxxx",
    "created_at": 1709033612,
    "kind": 23195,
    "tags": [
      [
        "p",
        "f490f5xxxxx........xxxxx"
      ],
      [
        "e",
        "a41aefxxxxx........xxxxx"
      ]
    ],
    "content": "<encrypted content>",
    "sig": "<signature>",
  },
  "state": "PUBLISHED"
}
```

{% endtab %}
{% endtabs %}

### With Webhook

`POST` `https://api.getalby.com/nwc/nip47/webhook`

**Request Body**

| Name                                           | Type                                        | Description                                                                           |
| ---------------------------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------- |
| relayUrl                                       | string                                      | If no relay is provided, it uses the default relay (wss\://relay.getalby.com/v1)      |
| webhookUrl<mark style="color:red;">\*</mark>   | string                                      | Webhook URL to publish the response event, returns the event directly if not provided |
| walletPubkey<mark style="color:red;">\*</mark> | string                                      | Pubkey of the NWC Wallet Provider                                                     |
| event<mark style="color:red;">\*</mark>        | JSON object (see [example](#event-example)) | **Signed** request event                                                              |

#### Response

{% tabs %}
{% tab title="200: OK" %}

```javascript
{
  "state": "WEBHOOK_RECEIVED"
}
```

{% endtab %}
{% endtabs %}

#### Response to webhook

{% tabs %}
{% tab title="200: OK" %}

```javascript
{
  "id": "a16ycf4a01bcxx........xxxxx",
  "pubkey": "a16y69effexxxx........xxxxx",
  "created_at": 1709033612,
  "kind": 23195,
  "tags": [
    [
      "p",
      "f490f5xxxxx........xxxxx"
    ],
    [
      "e",
      "a41aefxxxxx........xxxxx"
    ]
  ],
  "content": "<encrypted content>",
  "sig": "<signature>",
}
```

{% 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://guides.getalby.com/developer-guide/developer-guide/nostr-wallet-connect-api/building-lightning-apps/nwc-http-api/publish-nwc-request.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.
