Lua
Lua
Move a GMail Message to Trash
See more GMail REST API Examples
Moves a specific GMail email message to trash.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
http.auth_token = "GMAIL-ACCESS-TOKEN"
-- The id of the GMail message to move to Trash.
local id = "16678c485e7f0a0c"
local userId = "me"
http:set_url_var("userId", "me")
http:set_url_var("id", id)
-- Move to trash by POSTing w/ an empty request body.
local url = "https://www.googleapis.com/gmail/v1/users/{$userId}/messages/{$id}/trash"
local resp = chilkat.HttpResponse.new()
local success = http:http_str("POST", url, "", "", "", resp)
if not success then
print(http.last_error_text)
return
end
print("status = " .. resp.status_code)
-- A 200 response status indicate success.
if resp.status_code ~= 200 then
print(resp.body_str)
print("Failed.")
return
end
-- A successful repsonse contains JSON that looks like this:
-- {
-- "id": "16678c485e7f0a0c",
-- "threadId": "16678c485e7f0a0c",
-- "labelIds": [
-- "TRASH",
-- "CATEGORY_SOCIAL"
-- ]
-- }
print("response body:")
print(resp.body_str)
print("Message moved to trash!")