Sample code for 30+ languages & platforms
Node.js

Get a List of Message IDs in GMail User's Mailbox

See more GMail REST API Examples

Demonstrates how to get a list of message IDs in a GMail mailbox. The "userId" can be either the user's email address or the special value "me" to indicate the authenticated user.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

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

    var http = new chilkat.Http();

    http.AuthToken = "ACCESS_TOKEN";

    http.Accept = "application/json";

    var resp = new chilkat.HttpResponse();
    success = http.HttpNoBody("GET","https://www.googleapis.com/gmail/v1/users/userId/messages",resp);
    if (success == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log("Response Status Code: " + resp.StatusCode);

    var jsonResponse = new chilkat.JsonObject();
    jsonResponse.Load(resp.BodyStr);
    jsonResponse.EmitCompact = false;
    console.log(jsonResponse.Emit());

    if (resp.StatusCode !== 200) {
        console.log("Failed.");
        return;
    }

    //  {
    //    "messages": [
    //      users.messages Resource
    //    ],
    //    "nextPageToken": string,
    //    "resultSizeEstimate": unsigned integer
    //  }

    var id;
    var threadId;

    var resultSizeEstimate = jsonResponse.IntOf("resultSizeEstimate");
    var i = 0;
    var count_i = jsonResponse.SizeOfArray("messages");
    while (i < count_i) {
        jsonResponse.I = i;
        id = jsonResponse.StringOf("messages[i].id");
        threadId = jsonResponse.StringOf("messages[i].threadId");
        i = i+1;
    }


}

chilkatExample();