Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sheet API batch update issue iOS

Am trying to do a batch update with google sheet API for iOS but am getting an error invalid value at 'data[0].values[0]' (type.googleapis.com/google.protobuf.ListValue),

here is my code

 NSString *baseUrl = @"https://sheets.googleapis.com/v4/spreadsheets/";
NSString *spreadsheetId = @"1tJd4toWFxmHAEOeONauRPcuH_rWJOESLQT7TvCIK0x0";

baseUrl= [baseUrl stringByAppendingString:spreadsheetId];
baseUrl = [baseUrl stringByAppendingString:@"/values:batchUpdate/"];



NSMutableDictionary * params=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"USER_ENTERED",@"valueInputOption", nil];

NSURL *postURL=[GTLUtilities URLWithString:baseUrl queryParameters:params];

NSLog(@"base url is %@", postURL);

GTLObject * body=[[GTLObject alloc]init];



NSMutableArray * titleArray=[[NSMutableArray alloc]initWithObjects:@"Customer ID",@"Customer Name",@"Latitude",@"Longitude" ,@"Last_Updated_At",nil];
NSMutableArray * wheelArray2=[[NSMutableArray alloc]initWithObjects:@"rt",@"SHJ",@"150.00",@"100.00",@"2:00:00", nil];

//[contentArray addObject:titleArray];



NSMutableDictionary * batchParams=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"USER_ENTERED",@"valueInputOption", nil];


NSMutableArray * batchParametersContentArray=[[NSMutableArray alloc]init];


NSMutableDictionary*  batchParametersTitlesDict=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Sheet1!A1:E1",@"range",@"COLUMNS",@"majorDimension",titleArray,@"values", nil];


NSMutableDictionary*  batchParametersContentDict=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Sheet1!A7:E7",@"range",@"ROWS",@"majorDimension",wheelArray2,@"values", nil];


[batchParametersContentArray addObject:batchParametersTitlesDict];

[batchParametersContentArray addObject:batchParametersContentDict];

[batchParams setObject:batchParametersContentArray forKey:@"data"];


NSLog(@"batch params are %@",batchParams);


body.JSON=batchParams;


[self.service fetchObjectByInsertingObject:body forURL:postURL completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
    if (error==nil) {
        NSLog(@"batch performed successfully");
    }
    else
    {
        NSLog(@"error is %@", error);
    }

}];

My Request parameters are

batch params are {
data =     (
            {
        majorDimension = COLUMNS;
        range = "Sheet1!A1:E1";
        values =             (
            "Customer ID",
            "Customer Name",
            Latitude,
            Longitude,
            "Last_Updated_At"
        );
    },
            {
        majorDimension = ROWS;
        range = "Sheet1!A7:E7";
        values =             (
            rt,
            SHJ,
            "150.00",
            "100.00",
            "2:00:00"
        );
    }
);
valueInputOption = "USER_ENTERED";
}

The error is

error is Error Domain=com.google.GTLJSONRPCErrorDomain Code=400 "(Invalid value at 'data[0].values[0]' (type.googleapis.com/google.protobuf.ListValue), "Customer ID"

Invalid value at 'data[0].values[1]' (type.googleapis.com/google.protobuf.ListValue), "Customer Name" Invalid value at 'data[0].values[2]' (type.googleapis.com/google.protobuf.ListValue), "Latitude" Invalid value at 'data[0].values[3]' (type.googleapis.com/google.protobuf.ListValue), "Longitude" Invalid value at 'data[0].values[4]' (type.googleapis.com/google.protobuf.ListValue), "Last_Updated_At" Invalid value at 'data[1].values[0]' (type.googleapis.com/google.protobuf.ListValue), "rt" Invalid value at 'data[1].values[1]' (type.googleapis.com/google.protobuf.ListValue), "SHJ" Invalid value at 'data[1].values[2]' (type.googleapis.com/google.protobuf.ListValue), "150.00" Invalid value at 'data[1].values[3]' (type.googleapis.com/google.protobuf.ListValue), "100.00" Invalid value at 'data[1].values[4]' (type.googleapis.com/google.protobuf.ListValue), "2:00:00")" UserInfo={error=Invalid value at 'data[0].values[0]' (type.googleapis.com/google.protobuf.ListValue), "Customer ID" Invalid value at 'data[0].values[1]' (type.googleapis.com/google.protobuf.ListValue), "Customer Name" Invalid value at 'data[0].values[2]' (type.googleapis.com/google.protobuf.ListValue), "Latitude" Invalid value at 'data[0].values[3]' (type.googleapis.com/google.protobuf.ListValue), "Longitude" Invalid value at 'data[0].values[4]' (type.googleapis.com/google.protobuf.ListValue), "Last_Updated_At" Invalid value at 'data[1].values[0]' (type.googleapis.com/google.protobuf.ListValue), "rt" Invalid value at 'data[1].values[1]' (type.googleapis.com/google.protobuf.ListValue), "SHJ" Invalid value at 'data[1].values[2]' (type.googleapis.com/google.protobuf.ListValue), "150.00" Invalid value at 'data[1].values[3]' (type.googleapis.com/google.protobuf.ListValue), "100.00" Invalid value at 'data[1].values[4]' (type.googleapis.com/google.protobuf.ListValue), "2:00:00", NSLocalizedFailureReason=(Invalid value at 'data[0].values[0]' (type.googleapis.com/google.protobuf.ListValue), "Customer ID" Invalid value at 'data[0].values[1]' (type.googleapis.com/google.protobuf.ListValue), "Customer Name" Invalid value at 'data[0].values[2]' (type.googleapis.com/google.protobuf.ListValue), "Latitude" Invalid value at 'data[0].values[3]' (type.googleapis.com/google.protobuf.ListValue), "Longitude" Invalid value at 'data[0].values[4]' (type.googleapis.com/google.protobuf.ListValue), "Last_Updated_At" Invalid value at 'data[1].values[0]' (type.googleapis.com/google.protobuf.ListValue), "rt" Invalid value at 'data[1].values[1]' (type.googleapis.com/google.protobuf.ListValue), "SHJ" Invalid value at 'data[1].values[2]' (type.googleapis.com/google.protobuf.ListValue), "150.00" Invalid value at 'data[1].values[3]' (type.googleapis.com/google.protobuf.ListValue), "100.00" Invalid value at 'data[1].values[4]' (type.googleapis.com/google.protobuf.ListValue), "2:00:00"), GTLStructuredError=GTLErrorObject 0x7f89ca465990: {code:400 message:"Invalid value at 'data[0].values[0]' (type.googleapis.com/google.protobuf.ListValue), "Customer ID" Invalid value at 'data[0].values[1]' (type.googleapis.com/google.protobuf.ListValue), "Customer Name" Invalid value at 'data[0].values[2]' (type.googleapis.com/google.protobuf.ListValue), "Latitude" Invalid value at 'data[0].values[3]' (type.googleapis.com/google.protobuf.ListValue), "Longitude" Invalid value at 'data[0].values[4]' (type.googleapis.com/google.protobuf.ListValue), "Last_Updated_At" Invalid value at 'data[1].values[0]' (type.googleapis.com/google.protobuf.ListValue), "rt" Invalid value at 'data[1].values[1]' (type.googleapis.com/google.protobuf.ListValue), "SHJ" Invalid value at 'data[1].values[2]' (type.googleapis.com/google.protobuf.ListValue), "150.00" Invalid value at 'data[1].values[3]' (type.googleapis.com/google.protobuf.ListValue), "100.00" Invalid value at 'data[1].values[4]' (type.googleapis.com/google.protobuf.ListValue), "2:00:00"" errors?:[1] status?:"INVALID_ARGUMENT"}}

like image 670
Syed Ismail Ahamed Avatar asked Aug 11 '16 16:08

Syed Ismail Ahamed


1 Answers

Values are intended to be a 2d array. They should be in the form of [[ 'a', 'b', 'c'], [ 1, 2, 3 ]]

You're supplying the values as a 1d array ['a', 'b', 'c'], and the error message is complaining the 'a' can't fit into a ListValue since it's not an array. The solution is to use a 2d array, although I can't provide an example here of exactly what you should do since I'm not sure how you intend your input to map to the spreadsheet.

like image 103
Sam Berlin Avatar answered Oct 05 '22 08:10

Sam Berlin