1
votes

I am trying to get the developer metadata about a spreadsheet using the Google Script API, as found on this website.

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.developerMetadata/search

I have tried the following, however I am getting no response back? Can anyone see where I am going wrong?

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var fileId = ss.getId();
    var token = ScriptApp.getOAuthToken();

    var paramsPost = {
        method: 'post',
        headers: {
            Authorization: 'Bearer ' + token
        },
        muteHttpExceptions: true,
        contentType: 'application/json',
        payload: JSON.stringify({
            dataFilters: [{
                developerMetadataLookup: {
                    locationType: 'COLUMN'
                }
            }]
        })
    };

    var url = 'https://sheets.googleapis.com/v4/spreadsheets/' + fileId + '?developerMetadata:search';
    var res = UrlFetchApp.fetch(url, paramsPost);
    var data = JSON.parse(res.getContentText());
2
Is there a metadata associated with a column? - TheMaster
If you want to retrieve the developer metadata using Sheets API, how about modifying to var url = 'https://sheets.googleapis.com/v4/spreadsheets/' + fileId + '/developerMetadata:search';? Because your endpoint is not correct. ? of '?developerMetadata:search' is /. developers.google.com/sheets/api/reference/rest/v4/… - Tanaike
This was the issue, if you would like to add it as an answer I can set as correct - user3284707
Thank you for replying. I posted a modified endpoint as an answer. Could you please confirm it? - Tanaike

2 Answers

1
votes

In order to use the method of spreadsheets.developerMetadata.search of Sheets API, please modify the endpoint as follows.

From:

var url = 'https://sheets.googleapis.com/v4/spreadsheets/' + fileId + '?developerMetadata:search';

To:

var url = 'https://sheets.googleapis.com/v4/spreadsheets/' + fileId + '/developerMetadata:search';
  • ? of '?developerMetadata:search' is /.

Reference:

1
votes

You no longer need to use the REST API directly to access developer metadata.

As of November 14, 2018, methods to access developer metadata were added to the built-in Spreadsheet service. See Release Notes for details.