Immediately and permanently deletes the specified label and removes it from any messages and threads that it is applied to. Try it now or see an example.
Request
HTTP request
DELETE https://www.googleapis.com/gmail/v1/users/userId/labels/id
Parameters
Parameter name | Value | Description |
---|---|---|
Path parameters | ||
id |
string |
The ID of the label 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:
Scope |
---|
https://mail.google.com/ |
https://www.googleapis.com/auth/gmail.modify |
https://www.googleapis.com/auth/gmail.labels |
For more information, see the authentication and authorization page.
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 label. * * @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 labelId ID of Label to delete. * @throws IOException */ public static void deleteLabel(Gmail service, String userId, String labelId) throws IOException{ service.users().labels().delete(userId, labelId).execute(); System.out.println("Label with id: " + labelId + " deleted successfully."); } // ... }
.NET
Uses the .NET client library.
using Google.Apis.Gmail.v1; using Google.Apis.Gmail.v1.Data; // ... public class MyClass { // ... /// <summary> /// Delete Label. /// </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="labelId">ID of the Label to delete.</param> public static void DeleteLabel(GmailService service, String userId, String labelId) { try { service.Users.Labels.Delete(userId, labelId).Execute(); } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); } } // ... }
PHP
Does not use a client library.
/** * Delete Label 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 $labelId Id of Label to be updated. */ function deleteLabel($service, $user, $labelId) { try { $service->users_labels->delete($user, $labelId); print 'Label with id: ' . $labelId . ' successfully deleted.'; } catch (Exception $e) { print 'An error occurred: ' . $e->getMessage(); } }
Python
Uses the Python client library.
"""Deletes a label with specified label id. """ from apiclient import errors def DeleteLabel(service, user_id, label_id): """Delete a label. 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. label_id: string id of the label. """ try: service.users().labels().delete(userId=user_id, id=label_id).execute() print 'Label with id: %s deleted successfully.' % label_id except errors.HttpError, error: print 'An error occurred: %s' % error
JavaScript
Does not use a client library.
/** * Delete Label with given ID. * * @param {String} userId User's email address. The special value 'me' * can be used to indicate the authenticated user. * @param {String} labelId ID of Label to delete. */ function deleteLabel(userId, labelId) { var request = gapi.client.gmail.users.labels.delete({ 'userId': userId, 'id': labelId }); request.execute(function(resp) { }); }
Try it!
Use the APIs Explorer below to call this method on live data and see the response.