# Return a scheduled message

> **GET** `https://api.us.nylas.com/v3/grants/{grant_id}/messages/schedules/{scheduleId}`

Source: https://developer.nylas.com/docs/reference/api/messages/get-schedule-by-id/

Returns the specified scheduled message. You can retrieve both sent and unsent messages.

**Authentication:** NYLAS_API_KEY, ACCESS_TOKEN

## Parameters

### Path parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `scheduleId` | string | Yes | The ID of the scheduled message that you want to retrieve. |
| `grant_id` | string | Yes | ID of the grant to access. Use `/me/` to refer to the grant associated with an access token. |

## Responses

### 200 - Schedule(s) Retrieved

- `schedule_id` (string) **(required)** - The ID of the scheduled message.
- `status` (object) **(required)** - The status of the specified scheduled message.
  - `code` (string) - The status code which describes the state of the specified scheduled message.
  - `description` (string) - A description of the status of the specified scheduled message.
- `close_time` (integer) - The time that the message was sent, or failed to send, in seconds using the Unix timestamp format.

### 404 - Not Found

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.
  - `provider_error` (object) - The raw error from the provider, if available
    - `code` (string)
    - `message` (string)

## Code samples

### cURL

```bash
curl --request GET \
  --url 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/messages/schedules/<SCHEDULE_ID>' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY>'
```

### Node.js SDK

```javascript
import Nylas from "nylas";

const NylasConfig = {
  apiKey: "<NYLAS_API_KEY>",
  apiUri: "<NYLAS_API_URI>",
};

const nylas = new Nylas(NylasConfig);

async function fetchScheduledMessageById() {
  try {
    const events = await nylas.messages.findScheduledMessage({
      identifier: "<NYLAS_GRANT_ID>",
      scheduleId: "<SCHEDULE_ID>",
    });

    console.log("Events:", events);
  } catch (error) {
    console.error("Error fetching calendars:", error);
  }
}

fetchScheduledMessageById();

```

### Python SDK

```python
import sys
from nylas import Client

nylas = Client(
    "<NYLAS_API_KEY>",
    "<NYLAS_API_URI>"
)

grant_id = "<NYLAS_GRANT_ID>"
schedule_id = "<SCHEDULE_ID>"

event = nylas.messages.find_scheduled_message(
    grant_id,
    schedule_id,
)

print(event)
```

### Ruby SDK

```ruby
require 'nylas'

# Initialize Nylas client
nylas = Nylas::Client.new(
	  api_key: "<NYLAS_API_KEY>"
)

messages, _ = nylas.messages.find_scheduled_messages(
    identifier: "<NYLAS_GRANT_ID>",
    schedule_id: "<SCHEDULE_ID>")

messages.each {|message|
    puts message
}
```

### Java SDK

```java
import com.nylas.NylasClient;
import com.nylas.models.*;

public class ReturnMessage {
  public static void main(String[] args) throws NylasSdkTimeoutError, NylasApiError {
    NylasClient nylas = new NylasClient.Builder("<NYLAS_API_KEY>").build();

    Response<ScheduledMessage> message = nylas.messages().findScheduledMessage(
        "<NYLAS_GRANT_ID>", 
        "<SCHEDULED_MESSAGE_ID>");
        
    System.out.println(message.getData());
  }
}

```

### Kotlin SDK

```kotlin
import com.nylas.NylasClient

fun main(args: Array<String>) {
  val nylas: NylasClient = NylasClient(
      apiKey = "<NYLAS_API_KEY>"
  )

  val messages = nylas.messages().findScheduledMessage(
      "<NYLAS_GRANT_ID>", 
      "<SCHEDULED_MESSAGE_ID").data

  print(messages)
}
```
