Oracle Cloud Infrastructure Node.js/TypeScript Client for Work Requests

2.130.0 · active · verified Tue Apr 21

The `oci-workrequests` package is an official Oracle Cloud Infrastructure (OCI) Node.js/TypeScript client specifically designed to interact with the OCI Work Requests service. Currently at version 2.130.0, this package is part of the broader OCI TypeScript SDK and receives very frequent updates, often on a daily or weekly basis, reflecting continuous feature development and alignment with new OCI service capabilities. It provides a type-safe and idiomatic interface for managing asynchronous operations within OCI, allowing developers to programmatically monitor the status and outcomes of long-running tasks across various OCI services. Key differentiators include its tight integration with the OCI ecosystem, comprehensive type definitions, and adherence to OCI's API standards, simplifying the development of robust cloud automation and management scripts.

Common errors

Warnings

Install

Imports

Quickstart

This code initializes the WorkRequests client and lists the first 10 work requests in a specified compartment, demonstrating basic API interaction.

import { WorkRequestsClient } from 'oci-workrequests';
import * as common from 'oci-common';
import { requests } from 'oci-workrequests';

async function listAllWorkRequests(): Promise<void> {
  try {
    // Configure authentication using default provider (e.g., OCI config file or instance principal)
    const provider = new common.auth.DefaultAuthenticationDetailsProvider();
    
    // Initialize the WorkRequests client
    const client = new WorkRequestsClient({
      authenticationDetailsProvider: provider
    });

    // Define the request to list work requests
    // Replace 'ocid1.compartment.oc1..aaaaaaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' with your compartment OCID
    const listRequest: requests.ListWorkRequestsRequest = {
      compartmentId: process.env.OCI_COMPARTMENT_ID ?? 'ocid1.compartment.oc1..aaaaaaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
      // You can add filters like status, resourceId, etc.
      limit: 10 // Limit to 10 results for brevity
    };

    // Call the ListWorkRequests API
    console.log('Listing OCI Work Requests...');
    let response = await client.listWorkRequests(listRequest);
    
    if (response.items && response.items.length > 0) {
      console.log(`Found ${response.items.length} work requests:`)
      for (const wr of response.items) {
        console.log(`  ID: ${wr.id}, Status: ${wr.status}, Resource: ${wr.resources ? wr.resources[0]?.identifier : 'N/A'}`);
      }
    } else {
      console.log('No work requests found in the specified compartment.');
    }

  } catch (error) {
    console.error('Error listing work requests:', error);
  }
}

listAllWorkRequests();

view raw JSON →