# Return scheduled messages

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

Source: https://developer.nylas.com/docs/reference/api/messages/get-schedules/

Returns a list of scheduled messages. You can retrieve both sent and unsent messages.

**Authentication:** NYLAS_API_KEY, ACCESS_TOKEN

## Parameters

### Path parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `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) Successfully Retrieved

- Array of object
  - `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.

## Code samples

### cURL

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

### Node.js SDK

```javascript
import Nylas from "nylas";

const nylas = new Nylas({
  apiKey: "<NYLAS_API_KEY>",
  apiUri: "<NYLAS_API_URI>",
});

async function fetchMessageSchedules() {
  try {
    const identifier = "<NYLAS_GRANT_ID>";
    const messageSchedules = await nylas.messages.listScheduledMessages({
      identifier,
    });

    console.log("Message Schedules:", messageSchedules);
  } catch (error) {
    console.error("Error fetching message schedules:", error);
  }
}

fetchMessageSchedules();

```

### Python SDK

```python
import sys
from nylas import Client

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

grant_id = "<NYLAS_GRANT_ID>"

messages = nylas.messages.list_scheduled_messages(
  grant_id
)

print(messages)
```

### Ruby SDK

```ruby
require 'nylas'

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

messages, _ = nylas.messages.list_scheduled_messages(identifier: "<NYLAS_GRANT_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();

    ListResponse<ScheduledMessage> message = nylas.messages().listScheduledMessages("<NYLAS_GRANT_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().listScheduledMessages("<NYLAS_GRANT_ID>").data
  
  print(messages)
}

```
