Sample code for 30+ languages & platforms
Xbase++

Permanently Delete a Specific GMail Message

See more GMail REST API Examples

Immediately and permanently deletes the specified message. This operation cannot be undone. (This is not the same as moving a message to Trash.)

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL cId
LOCAL cUserId
LOCAL cUrl
LOCAL cResponseStr

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("Chilkat.Http")
oHttp:AuthToken := "GMAIL-ACCESS-TOKEN"

//  The id of the GMail message to delete.
cId := "1669cc9a926bb8c1"
cUserId := "me"

oHttp:SetUrlVar("userId", "me")
oHttp:SetUrlVar("id", cId)

//  Delete the email.
cUrl := "https://www.googleapis.com/gmail/v1/users/{$userId}/messages/{$id}"
cResponseStr := oHttp:QuickDeleteStr(cUrl)
IF (oHttp:LastMethodSuccess != 1)
    ? oHttp:LastErrorText
    oHttp:destroy()
    RETURN
ENDIF

? "status = " + Str(oHttp:LastStatus)

//  A 204 response indicate success.
//  It is common for HTTP DELETE operations to respond with a 204 status code with an empty body for success.
//  You'll find many REST APIs follow this custom..
IF (oHttp:LastStatus != 204)
    ? cResponseStr
    ? "Failed."
    oHttp:destroy()
    RETURN
ENDIF

? "Message deleted!"

oHttp:destroy()