Users.drafts: delete

Requires authorization

Immediately and permanently deletes the specified draft. Does not simply trash it. Try it now or see an example.

Request

HTTP request

DELETE https://www.googleapis.com/gmail/v1/users/userId/drafts/id

Parameters

Parameter name Value Description
Path parameters
id string The ID of the draft to delete.
userId string The user's email address. The special value me can be used to indicate the authenticated user.

Authorization

This request requires authorization with at least one of the following scopes (read more about authentication and authorization).

Scope
https://mail.google.com/
https://www.googleapis.com/auth/gmail.modify
https://www.googleapis.com/auth/gmail.compose

Request body

Do not supply a request body with this method.

Response

If successful, this method returns an empty response body.

Examples

Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).

Java

Uses the Java client library.

import com.google.api.services.gmail.Gmail;

import java.io.IOException;

// ...

public class MyClass {

  // ...


  /**
   * Delete draft email.
   *
   * @param service Authorized Gmail API instance.
   * @param userId User's email address. The special value "me"
   * can be used to indicate the authenticated user.
   * @param draftId ID of Draft to deleted.
   * @throws IOException
   */
  public static void deleteDraft(Gmail service, String userId, String draftId) throws IOException{
    service.users().drafts().delete(userId, draftId).execute();
    System.out.println("Draft with id: " + draftId + " deleted successfully.");
  }

  // ...
}

.NET

Uses the .NET client library.

using Google.Apis.Gmail.v1;
using Google.Apis.Gmail.v1.Data;

// ...

public class MyClass {

  // ...

  /// <summary>
  /// Delete a draft.
  /// </summary>
  /// <param name="service">Gmail API service instance.</param>
  /// <param name="userId">User's email address. The special value "me"
  /// can be used to indicate the authenticated user.</param>
  /// <param name="draftId">Id of the draft to delete.</param>
  public static void DeleteDraft(GmailService service, String userId, String draftId)
  {
      try
      {
          service.Users.Drafts.Delete(userId, draftId).Execute();
      }
      catch (Exception e)
      {
          Console.WriteLine("An error occurred: " + e.Message);
      }
  }

  // ...

}

PHP

Does not use a client library.

/**
 * Delete Draft email with given ID.
 *
 * @param  Google_Service_Gmail $service Authorized Gmail API instance.
 * @param  string $userId User's email address. The special value 'me'
 * can be used to indicate the authenticated user.
 * @param  string $draftId ID of Draft to delete.
 */
function deleteDraft($service, $user, $draftId) {
  try {
    $service->users_drafts->delete($user, $draftId);
    print 'Draft with ID: ' . $draftId . ' deleted successfully.';
  } catch (Exception $e) {
    print 'An error occurred: ' . $e->getMessage();
  }
}

Python

Uses the Python client library.

"""Deletes a draft with specified draft id.
"""

from apiclient import errors


def DeleteDraft(service, user_id, draft_id):
  """Delete a draft email.

  Args:
    service: Authorized Gmail API service instance.
    user_id: User's email address. The special value "me"
    can be used to indicate the authenticated user.
    draft_id: string id of the draft.
  """
  try:
    service.users().drafts().delete(userId=user_id, id=draft_id).execute()
    print 'Draft with id: %s deleted successfully.' % draft_id
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

JavaScript

Does not use a client library.

/**
 * Delete Draft with given ID.
 *
 * @param  {String} userId User's email address. The special value 'me'
 * can be used to indicate the authenticated user.
 * @param  {String} draftId ID of Draft to delete.
 */
function deleteDraft(userId, draftId) {
  var request = gapi.client.gmail.users.drafts.delete({
    'userId': userId,
    'id': draftId
  });
  request.execute(function(resp) { });
}

Try it!

Use the APIs Explorer below to call this method on live data and see the response.

Enviar comentarios sobre…

¿Necesitas ayuda? Visita nuestra página de asistencia.