Sample code for 30+ languages & platforms
React Native

Delete a Task from a Task List

See more Google Tasks Examples

Demonstrates how to delete a Google task from a task list.

Chilkat React Native Downloads

React Native
import { FileAccess, Http, HttpResponse } from '@chilkat/react-native'

async function chilkatExample() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  // Get the previously obtained access token.
  // See Get Google Tasks Access Token.

  const fac = new FileAccess();
  let accessToken: string;
  try {
    accessToken = fac.readEntireTextFile('qa_data/tokens/googleTasks.txt', 'utf-8');
  } catch {
    console.log(fac.lastErrorText);
    return;
  }

  const http = new Http();

  http.authToken = accessToken;

  http.setUrlVar('tasklist', 'MDM4MzQ4NTA3NDQwMDUxMzQ2OTQ6NzAwOTA4MDA1NzU2ODYwMzow');
  http.setUrlVar('task', 'MDM4MzQ4NTA3NDQwMDUxMzQ2OTQ6NzAwOTA4MDA1NzU2ODYwMzoxMTg0MzQxMTkzMjM2MDY1');

  const resp = new HttpResponse();
  try {
    await http.httpNoBodyAsync('DELETE', 'https://www.googleapis.com/tasks/v1/lists/{$tasklist}/tasks/{$task}', resp);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  // Show the response body. (empty for success)
  console.log(resp.bodyStr);

  // Examine the response status code. (204 = success)
  console.log(`response status code: ${resp.statusCode}`);
}