We have a google spreadsheet with a sheet named something like foo + bar (yay). When I try to select data from the sheet using the Java API, I'm getting back an error from Google saying:
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Unable to parse range: foo bar (yay)!A2:Z",
"reason" : "badRequest"
} ],
"message" : "Unable to parse range: foo bar (yay)!A2:Z",
"status" : "INVALID_ARGUMENT"
}
The code looks something like this (some details of authentication elided, and translated from Scala)
Sheets s = ... // constructed using HTTP transport & credentials
String range = "'foo + bar (yay)'!A2:Z";
String spreadsheetId = ... // fill in your own
ValueRange values = s.spreadsheets().values().get(spreadsheetId, range).execute();
It's based on the following code example: https://developers.google.com/sheets/api/quickstart/java#step_3_set_up_the_sample
Notice that the + has been replaced by a single space , as if it were being URL encoded. I tried replacing + with %2B but I still get an error and it repeats %2B back to me as if I meant literally "%2B" - so I don't think it's a matter of URL encoding.
I tried listing the sheet names for this spreadsheet, and I'm getting back a + sign in the sheet name, so I don't think that's the problem. Then I tried renaming the sheet to use the word "and" instead of +, and my code was able to successfully select the range - thus I'm pretty certain the + is the problem. I don't see any description of escaping special characters in the documentation.
I noticed this in the documentation: https://developers.google.com/sheets/api/guides/concepts#a1_notation and tried surrounding the sheet name with single quotes ("'foo + bar (yay)'") but to no avail.
Is there any way I can select this range without renaming the sheet?
i've hit this same bug - also using java libraries, and trying to reference a sheet named "Week 1+2".. i tried the "'Week 1+2'!A2:Z" idea but java didn't like it. i then tried "'Week1\+2'!A2:Z" and it compiled, but got an "Unable to parse range 'Week 1\ 2' error. it's like (as someone pointed out) the '+' gets translated to a space. I saw elsewhere someone was having an issue with a - in the name too?
** NOT AN ANSWER!!! tried to add as a comment to above but it won't let me**
interesting fact -> i tested the python library to read the sheet, and it accepts the sheetname with an embedded + quite happily. so this would appear to be a java thing....
Finally got this to work.
When a sheet name is used in an API call as the RANGE, such as sheets.googleapis.com/v4/spreadsheets/{sheetID}/values/SHEET_NAME_AS_RANGE?key={key}, the trick is to NOT use single quotes around the range name AND to use encodeURIComponent on the sheet name.
So, for example a sheet with a name of NY/POINTS+AndSpace Here would get encoded as NY%2FPOINTS%2BAndSpace%20Here and look like this in the example I gave:
sheets.googleapis.com/v4/spreadsheets/{sheetID}/values/NY%2FPOINTS%2BAndSpace%20Here?key={key}
That should mean the OP would be able to use the following:
String sheetName = "foo + bar (yay)"
String range = encodeURIComponent(sheetName) + "!A2:Z"
(I only tested this using the sheet name by itself as the RANGE, not including the A2:Z part, so including that would need to be confirmed).
Related
Im new to python and can't figure out how to save my pdf file with a custom name.
What I want to do is something like:
Name = input('What is your name: ')
pdf.output('Name.pdf')
And as I expected the name of the pdf file created is now: Name
I tried searching for it but I think im using the wrong words for it since I can't find a solution for my problem. I might be explaning it badly. But if anyone got an answer for it it would be much appreciated :)
Sir, in your question:
pdf.output('Name.pdf')
Here you are passing Name.pdf as a string to the output function if you want to pass the Name variable you should not use ' quotes around the value you are passing you final code should look something like this:
name = input("Enter your name: ")
name = name + ".pdf" //adds .pdf extension to the name entered
pdf.output(name) //see how there are no quotes around name variable
I would like to screen scrape a few user details including the handphone no. from one application and paste the details into another application. There's a spacing in the handphone no. e.g. 8123 4567. I would like to remove the spacing and paste 81234567 into the other application.
I have use Build Data Table and Write Range to store the captured information in. In the handphone no. screen scrape activity, I did the following additional steps to split the numbers and combine them into 1. It works the first few times but when I tried running the script a few days later, it stopped working. Basically, the handphone no. is not completely copied over. Sometimes it returns as 8123 and sometimes as 812.
Assign
ArrayHandphoneNo = HandphoneNo.Split({" "},stringsplitoptions.None)
Assign
HandphoneNo = ArrayHandphoneNo(0)
Try Catch
HandphoneNo = HandphoneNo + ArrayHandphoneNo(1)
Catches exception
Assign
HandphoneNo = HandphoneNo
May I know what went wrong?
Why you having a workaround. From my perspective you simply need a line of code that is removing all spaces. So you get back the full digit number. So try with this:
myString = myString.Replace(" ", "")
in your assign activity.
Could look like this one:
I'm trying to parse my URL with wildcards. The problem appears when I try to parse long strings with a wildcard. For example, my URL looks like this:
http://testapi.com/v1/cards/%s/reissue?DesignId=%s&Comment=%s
and this is my code:
get_object.setRestUrl(String.format(url, card_id, design_id, comment))
When comment = "Something" it works, but when comment = "Something something", it goes on an error and says that it is "Unable to parse HTTP request".
How is it possible to make suitable my code with long strings with wildcards? I know that when typing long string it gives URL that looks like this:
http://testapi.com/v1/cards/1/Block?reasonId=1&comment=Something%20like%20that%20example
Just needed to modify with comment.replace(" ", "%20"), and now it works fine, even when there are no spaces.
Source : https://forum.katalon.com/t/getting-an-error-unable-to-parse-http-request/17685
P.S
If it is not allowed to post answer from another site, I will remove it.
You could try it:
get_object.setRestUrl(String.format(url, card_id, design_id, comment.replace(" ", "%20")))
More information could be found at https://forum.katalon.com/t/getting-an-error-unable-to-parse-http-request/17685
Using Google Sheets, I am trying to retrieve text passages from the Perseus Scaife Library, which has a working API.
When I query for the document node (=importxml("https://scaife-cts.perseus.org/api/cts?request=GetPassage&urn=urn:cts:greekLit:tlg0527.tlg001.opp-grc2:1.1","/")) I get all the data, including the URNs etc. However, any other xpath_query gives an error.
I know that Google Sheets can access the data, but I would like to be able to select only one node (//p).
You want to retrieve the text in passage. If my understanding is correct, how about this answer?
=importxml(A1, "//*[local-name()='passage']")
Result :
Note :
https://scaife-cts.perseus.org/api/cts?request=GetPassage&urn=urn:cts:greekLit:tlg0527.tlg001.opp-grc2:1.1 is converted by URL encode and put to "A1".
Converted URL is https://scaife-cts.perseus.org/api/cts?request=GetPassage&urn=urn%3acts%3agreekLit%3atlg0527%2etlg001%2eopp%2dgrc2%3a1%2e1.
Reference :
local-name
If this was not what you want, I'm sorry.
I'm working on automating Google analytics to get results into a google drive dashboard and coming up with an error code in "illegal character. (line 7, file "code")" How do i fix this problem? Here is the full script. I appreciate the help in advance. Thanks.
// Get Data.
var results = Analytics.Data.Ga.get(
tableId,
startDate,
endDate,
'ga:visitors,ga:visits,ga:pageviews',
{‘dimensions’: ‘ga:date’});
// Output to spreadsheet.
var sheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet();
sheet.getRange(2, 1, results.getRows().length, headerNames.length)
.setValues(results.getRows());
// Make Sandwich.
Not sure if line 7 in the error message is the same line 7 in the code you pasted, but if it is, then it looks like the single quotes are different. Use the straight single quote ('), and not the curvy one.
Here's what I mean:
{‘dimensions’: ‘ga:date’});
should be
{'dimensions': 'ga:date'});
Hope this helps.