script_projects_versions_get
Retrieve a specific version of a Google Apps Script project by providing the script ID and version number, enabling efficient management and access to script iterations.
Instructions
Get a version of a Google Apps Script project.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| access_token | No | OAuth access token. | |
| alt | No | Data format for response. | |
| callback | No | JSONP callback. | |
| fields | No | Selector specifying which fields to include in a partial response. | |
| key | No | API key for the project. | |
| oauth_token | No | OAuth 2.0 token for the current user. | |
| prettyPrint | No | Returns response with indentations and line breaks. | |
| quotaUser | No | Available to use for quota purposes for server-side applications. | |
| scriptId | Yes | The ID of the script project. | |
| versionNumber | Yes | The version number of the script project. |
Implementation Reference
- The executeFunction that performs the HTTP GET request to the Google Apps Script API endpoint /v1/projects/{scriptId}/versions/{versionNumber}, handling authentication, query parameters, error logging, and response parsing.const executeFunction = async ({ scriptId, versionNumber, fields, alt = 'json', key, access_token, quotaUser, oauth_token, callback, prettyPrint = true }) => { const baseUrl = 'https://script.googleapis.com'; const token = process.env.GOOGLE_APP_SCRIPT_API_API_KEY; const url = new URL(`${baseUrl}/v1/projects/${scriptId}/versions/${versionNumber}`); // Append query parameters const params = new URLSearchParams({ fields, alt, key, access_token, quotaUser, oauth_token, callback, prettyPrint: prettyPrint.toString(), '$.xgafv': '1', upload_protocol: 'raw', uploadType: 'media' }); // Set up headers for the request const headers = { 'Accept': 'application/json' }; // If a token is provided, add it to the Authorization header if (token) { headers['Authorization'] = `Bearer ${token}`; } // Perform the fetch request try { const response = await fetch(`${url}?${params.toString()}`, { method: 'GET', headers }); // Check if the response was successful if (!response.ok) { const errorData = await response.json(); throw new Error(errorData); } // Parse and return the response data const data = await response.json(); return data; } catch (error) { const errorDetails = { message: error.message, stack: error.stack, scriptId, versionNumber, timestamp: new Date().toISOString(), errorType: error.name || 'Unknown' }; logger.error('VERSION_GET', 'Error retrieving script version', errorDetails); console.error('❌ Error retrieving script version:', errorDetails); // Return detailed error information for debugging return { error: true, message: error.message, details: errorDetails, rawError: { name: error.name, stack: error.stack } }; } };
- Exports the apiTool object which registers the tool named 'script_projects_versions_get', references the handler function, and defines the input schema with required parameters scriptId and versionNumber.const apiTool = { function: executeFunction, definition: { type: 'function', function: { name: 'script_projects_versions_get', description: 'Get a version of a Google Apps Script project.', parameters: { type: 'object', properties: { scriptId: { type: 'string', description: 'The ID of the script project.' }, versionNumber: { type: 'string', description: 'The version number of the script project.' }, fields: { type: 'string', description: 'Selector specifying which fields to include in a partial response.' }, alt: { type: 'string', enum: ['json', 'xml'], description: 'Data format for response.' }, key: { type: 'string', description: 'API key for the project.' }, access_token: { type: 'string', description: 'OAuth access token.' }, quotaUser: { type: 'string', description: 'Available to use for quota purposes for server-side applications.' }, oauth_token: { type: 'string', description: 'OAuth 2.0 token for the current user.' }, callback: { type: 'string', description: 'JSONP callback.' }, prettyPrint: { type: 'boolean', description: 'Returns response with indentations and line breaks.' } }, required: ['scriptId', 'versionNumber'] } } } };
- JSON schema definition for the tool's input parameters, including descriptions, types, and required fields.type: 'object', properties: { scriptId: { type: 'string', description: 'The ID of the script project.' }, versionNumber: { type: 'string', description: 'The version number of the script project.' }, fields: { type: 'string', description: 'Selector specifying which fields to include in a partial response.' }, alt: { type: 'string', enum: ['json', 'xml'], description: 'Data format for response.' }, key: { type: 'string', description: 'API key for the project.' }, access_token: { type: 'string', description: 'OAuth access token.' }, quotaUser: { type: 'string', description: 'Available to use for quota purposes for server-side applications.' }, oauth_token: { type: 'string', description: 'OAuth 2.0 token for the current user.' }, callback: { type: 'string', description: 'JSONP callback.' }, prettyPrint: { type: 'boolean', description: 'Returns response with indentations and line breaks.' } }, required: ['scriptId', 'versionNumber'] }
- tools/paths.js:16-16 (helper)Lists the file path for this tool as part of all Google Apps Script API tool paths, likely used for dynamic loading or registration.'google-app-script-api/apps-script-api/script-projects-versions-get.js',