> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://help.sigmacomputing.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://help.sigmacomputing.com/_mcp/server.

# Members: Update (JavaScript)

> This script updates the account type of a member on the Sigma platform by sending a PATCH request to the API with the new member type.

This recipe demonstrates how to update a member's account type, based on `memberId`.

Each section of the script has inline comments provided.

Refer to the [Sigma REST API Recipes](https://quickstarts.sigmacomputing.com/guide/developers_api_code_samples/index.html?index=../..index#0) QuickStart for step-by-step instructions.

## Example script

```javascript JavaScript
// This script will update the account type for a member, based on the memberId defined in the .env file

// 1: Load environment variables from a specific .env file for configuration
require('dotenv').config({ path: 'sigma-api-recipes/.env' });

// 2: Import the function to obtain a bearer token from the authenticate-bearer module
const getBearerToken = require('../get-access-token');

// 3: Import Axios for making HTTP requests
const axios = require('axios');

// 4: Load use-case specific variables from environment variables
const newMemberType = process.env.NEW_MEMBER_TYPE; // The new account type you want to assign
const memberId = process.env.MEMBERID; // The unique identifier of the member whose type you want to update
const baseURL = process.env.baseURL; // Your base URL

// Define an asynchronous function to update a member's account type
async function updateMemberAccountType() {
  const accessToken = await getBearerToken();
  if (!accessToken) {
    console.log('Failed to obtain Bearer token.');
    return;
  }

  try {
    // Construct the request URL using the base URL and member ID
    const requestURL = `${baseURL}/members/${memberId}`;
    
    // Log the constructed URL before sending the request
    console.log(`URL sent to Sigma: ${requestURL}`);

    // Make a PATCH request to the API to update the member's account type
    const response = await axios.patch(requestURL, {
      memberType: newMemberType, // Data payload for the PATCH request
    }, {
      headers: {
        'Content-Type': 'application/json', // Indicate that the request body is JSON
        'Authorization': `Bearer ${accessToken}` // Authenticate the request
      }
    });

    // Log the response data to indicate success
    console.log('User account type updated successfully:', JSON.stringify(response.data, null, 2));
  } catch (error) {
    // Log detailed error information if the request fails
    console.error('Error updating member account type:', error.response ? error.response.data : error);
  }
}

// Execute the function to update a member's account type
updateMemberAccountType();
```

## Endpoints used

1. Get authentication token: `getBearerToken` function
2. Update member account type: `${baseURL}/members/${memberId}`