Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.0.0+

Permanently delete one Gmail message

See more GMail REST API Examples

Permanent deletion. Supply the ID of a message you intend to erase. This removes it immediately and cannot be undone. Use Move one Gmail message to Trash for recoverable removal. Google requires the full mail scope for permanent deletion.

Authorize the application with https://mail.google.com/. The example reads the access token from gmail-token.json in a private working directory. Authorize a desktop application.

Google documentation

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loToken
LOCAL loHttp
LOCAL loResp
LOCAL loReply
LOCAL loUrl

lnSuccess = 0

*  Assumes Chilkat is unlocked. See Global Unlock Sample.

loToken = CreateObject('Chilkat.JsonObject')
lnSuccess = loToken.LoadFile("gmail-token.json")
IF (lnSuccess <> 1) THEN
    ? "Could not read gmail-token.json from the private working directory."
    RELEASE loToken
    CANCEL
ENDIF

IF ((loToken.JsonTypeOf("access_token") <> 1) OR (loToken.StringOfEquals("access_token","",1) = 1)) THEN
    ? "An OAuth access token is required."
    RELEASE loToken
    CANCEL
ENDIF

loHttp = CreateObject('Chilkat.Http')
loHttp.RequireSslCertVerify = 1
loHttp.AuthToken = loToken.StringOf("access_token")
loResp = CreateObject('Chilkat.HttpResponse')
loReply = CreateObject('Chilkat.JsonObject')
loUrl = CreateObject('Chilkat.StringBuilder')
loUrl.Append("https://gmail.googleapis.com/gmail/v1/users/me/messages/")
loUrl.Append("GMAIL_MESSAGE_ID")
lnSuccess = loHttp.HttpNoBody("DELETE",loUrl.GetAsString(),loResp)
IF (loResp.StatusCode = 0) THEN
    ? "Gmail did not return an HTTP response."
    RELEASE loToken
    RELEASE loHttp
    RELEASE loResp
    RELEASE loReply
    RELEASE loUrl
    CANCEL
ENDIF

IF ((lnSuccess <> 1) OR (loResp.StatusCode < 200) OR (loResp.StatusCode >= 300)) THEN
    ? "Gmail HTTP " + STR(loResp.StatusCode)
    lnSuccess = loReply.Load(loResp.BodyStr)
    IF (lnSuccess = 1) THEN
        ? loReply.StringOf("error.message")
    ENDIF

    RELEASE loToken
    RELEASE loHttp
    RELEASE loResp
    RELEASE loReply
    RELEASE loUrl
    CANCEL
ENDIF

*  Successful deletion has no message body to parse.
? "Message permanently deleted."

RELEASE loToken
RELEASE loHttp
RELEASE loResp
RELEASE loReply
RELEASE loUrl