# `invalidateSessions()`

Ends one or more sessions specified by a sessionId.

See [`sessionId`](/docs/platform/api/guide/sforce-api-header-sessionheader.md).

## Syntax

```java
InvalidateSessionsResult = connection.invalidateSessions(string[] sessionIds);
```

## Usage

Use this call to end one or more sessions.

You can also use [`logout()`](/docs/platform/api/guide/sforce-api-calls-logout.md) to end just one session, the session of the logged-in user.

## Sample Code—Java

This sample invalidates a set of sessions. The method in this sample takes an array of session IDs passed in as String values. The method then calls `invalidateSessions()` with this array and then checks the results for any errors.

```codesegment
public void invalidateSessionsSample(String[] sessionIds) {
   try {
      InvalidateSessionsResult[] results;
      results = connection.invalidateSessions(sessionIds);
      for (InvalidateSessionsResult result : results) {
         // Check results for errors
         if (!result.isSuccess()) {
            if (result.getErrors().length > 0) {
               System.out.println("Status code: "
                     + result.getErrors()[0].getStatusCode());
               System.out.println("Error message: "
                     + result.getErrors()[0].getMessage());
            }
         } else {
            System.out.println("Success.");
         }
      }
   } catch (ConnectionException ce) {
      ce.printStackTrace();
   }
}
```

## Sample Code—C\#

This sample invalidates a set of sessions. The method in this sample takes an array of session IDs passed in as String values. The method then calls `invalidateSessions()` with this array and then checks the results for any errors.

```codesegment
public void invalidateSessionsSample(string[] sessionIds)
{
   try
   {
      InvalidateSessionsResult[] results;
      results = binding.invalidateSessions(sessionIds);
      foreach (InvalidateSessionsResult result in results)
      {
         // Check results for errors
         if (!result.success)
         {
            if (result.errors.Length > 0)
            {
               Console.WriteLine("Status code: " +
                  result.errors[0].statusCode);
               Console.WriteLine("Error message: " +
                  result.errors[0].message);
            }                  
         }
         else
         {
            Console.WriteLine("Success.");
         }
      }
   }
   catch (SoapException e)
   {
      Console.WriteLine("An unexpected error has occurred: " +
                                 e.Message + "\n" + e.StackTrace);
   }
}
```

## Arguments

| Name         | Type     | Description                                                                                                                                                                                                                       |
| ------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sessionIds` | string[] | One or more [`sessionId`](/docs/platform/api/guide/sforce-api-header-sessionheader.md) strings. Limit 200. You can obtain your `sessionId` from the [SessionHeader](/docs/platform/api/guide/sforce-api-header-sessionheader.md). |

## Response

[InvalidateSessionsResult](/docs/platform/api/guide/sforce-api-calls-invalidatesessions-result.md)\[]

## Faults

[`UnexpectedErrorFault`](/docs/platform/api/guide/sforce-api-calls-concepts-core-data-objects.md)
