Google Sheet API batchGet unable to parse range with Integromat - google-sheets-api

I am trying to use the batchGet method of Google Sheets found here. The ranges and sheetID work fine when I am using the "Try this API" feature. The problem is Integromat requires me to form the URL manually, it's not clear how that's done.
I am trying:
https://sheets.googleapis.com/v4/spreadsheets/{my sheet ID}/values:batchGet?ranges=[sheet1!a1:a2,sheet1!b1:b2]
I keep getting the error:
"400: INVALID_ARGUMENT - Unable to parse range: "
Integromat is supposed to automatically replace special characters with their % form so I don't think it's that.

Try this instead,
/v4/spreadsheets/1MiLOwcEImnih0svZBrGwMQZ3xi3vSchhNWPiPA8Tcz0/values:batchGet?ranges=Availability!a1%3Aa2&ranges=Availability!b1%3Ab2
Instead of using,ranges=[sheet1!a1:a2,sheet1!b1:b2] it should be,
ranges=sheet1!a1:a2 & ranges=sheet1!b1:b2
Of course with URL encoding, which should be handled by Integromat.

Related

VB macro changing encoding on REST request

I have an excel file with a button associated to a VB macro like this:
Sub button_macro()
Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
MyRequest.Open "GET", "http://theurl/service?param=""Gestión"""
MyRequest.Send
End Sub
But the response I get is something like:
"Gestión" is not a valid value for param.
How can I avoid VB converting the 'ó' character to another encoding?
If I send the request via browser like:
http://theurl/service?param="Gestión"
The service answer as desired.
EDIT:
Curiously MsgBox "Código único" works as expected showing the 'ó' and 'ú' characters correctly.
It works in the browser because the browser encodes the request for you - you can see that if you use your browser's Developer tools - eg for your "example" URL of
http://theurl/service?param="Gestión"
I see
http://theurl/service?param=%22Gesti%C3%B3n%22
You can encode your parameters using (eg) the UTF-supporting method from the accepted answer here: How can I URL encode a string in Excel VBA?

URL redirection automation in UFT/Selenium

A URL of a webpage is being changed to a new URL.There are 200 such old URLs that have changed to new URLs.
Test scenario :1.200 old URls with their corresponding new URLs are present in two different columns in an Excel sheet.When an old URL is entered in the address bar,it will be directed to the new URL in the browser.
Can the above test be automated via Selenium or UFT for 200 URLs?
You can do it more easily and much quicker by using Java HttpURLConnection class unless you are forced in a solution with Selenium\QTP
Open up the connection with the old link with the openConnection() method of URL class. Check for the response from getResponseCode() method. If response is not in 300 series then you have a problem. If response is in 300 series you have correct behaviour and check the redirected URL from the Location header.
Have a look at this link which will make things easier - https://www.mkyong.com/java/java-httpurlconnection-follow-redirect-example/
You have to do the Exact same way in QTP. But i have a doubt.
i.e. If you have new URLs the nwhy u will enter old urls in Browser addressBar ?
anyway u can look at the following
as u have said in Excel file old & new URL are mentioned Adjacent cells.
Then you might either use Following things to read excel file.
1) Create Excel.Application object
or
2) Use DataTabe to import Excel Sheet
or
3) U can use Excel as ADODB connection
now just read the old URL from that Excel file & take value from the New url column cells & store it in a Varriable(let say : strNewURL).
Then you can do this & use FOR loop
set IE= CreateObject("InternetExplorer.Application)
IE.Visible = True
'For loop here
' [intsomecount] is variabel which is teh no of times loops gonna iterate, in This case the Number of URL mentioned
For iterator=0 to intsomecount step 1
IE.Navigate strNewURL
wait 3
Next
lemme know if you concerns. :)

How to open a URL from MS Access with parameters

I have a basic MS Access application that has a button on a form that should open a webpage with the ID of the Access record as the parameter, but everything I have tried results either in an error by Access or only the base URL opening in the web page.
I have tried adding VBA to the button's click event as so:
Application.FollowHyperlink _
"http://example.com/index.php?r=controller/action&id=" & Me.ID
but all I get is the base URL opening on the web browser (ie http://example.com). If I remove the '?' and the '&' from the full URL the button will open the browser with the full URL minus the '?' and the '&', which of course errors the page.
I have tried setting a hyperlink control's property as:
="http://example.com/index.php?r=controller/action&id=" & Me.ID
but it does the same thing as noted above.
I have tried creating a Macro with the same results. I have tried using the Hyperlink Builder and using [formName]![id] as the parameter but same thing happens or Access errors.
I have read this article: https://msdn.microsoft.com/en-us/library/office/ff822080.aspx and tried adding the part in the URl after 'index.php/ to the ExtraInfo place in the code, but same thing.
Help! It can't be that hard to simply have Access open a URL with a parameter on the end of the URL.
Application.FollowHyperlink is fickle.
Use either ShellExecute:
Open an html page in default browser with VBA?
or
CreateObject("Shell.Application").Open "http://example.com/index.php?r=controller/action&id=" & Me.ID
see https://stackoverflow.com/a/18922262/3820271
If the URL is in a string variable, you may need to cast it to Variant, because that's what Shell.Application.Open expects:
strUrl = "http://example.com/index.php?r=controller/action&id=" & Me.ID
CreateObject("Shell.Application").Open CVar(strUrl)
see https://stackoverflow.com/a/56173911/3820271, thanks Toby and Anthony for pointing this out!
Note that if you are having issues with CreateObject("Shell.Application").Open not working with a variable, it might be a casting issue - try tossing a CVar() around the parameter. See https://stackoverflow.com/a/56173911/8512931 for more details.

Publish an excel worksheet as an HTML file using a command button

So I have tons of data in my workbook that I need to pass on to my users in a way that allows them to interact with the workbook..., but also limits what they can actually do. So I have made it so they can access certain pages to Add needed data, then I've given access to a menu page so they can run a report.
This report I have found is best if it's an html page.
To that end, I have tried several different ways, save as...and publish. I like the publish version, but I can not for the life of me get this working. All the samples I see, appear to be the same. Here is the line of code in question:
ActiveWorkbook.PublishObjects.Add(xlSourceSheet, ActiveWorkbook.Path & ".htm, "Sheet1", "", xlHtmlStatic, "", "Report Title").Publish True
Every time I get a run time error '1004':
Method 'Publish' of object 'PublishObject' failed
I have the above line of code in a sub, am I missing something? Do I need to set up the publish differently? Thanks for any ideas.
I have had a similar mysterious problem that sometimes it (.Publish) works and sometimes it doesn't, when I try publish.
However, I think the problem might be, in cases when it doesn't work right off the bat, to first save the relevant region as a webpage so that it exists already on the server. After that region has been saved at least once (manually or else maybe with .SaveAs .. see below), then the publish might work.
Here is an example of how I get this to work more consistently, something to convey the structure that works for me:
wkb=ActiveWorkbook.Name 'save wb for later access
url="http://a.com/b.htm" 'save to Internet
sheetname="c"
Sheets(sheetname).Range("d1:e2").Select 'activating sheet may be necessary
On Error Resume Next 'anticipate error to handle it
'Now comes the publish line the first time... which may work.. or not
ActiveWorkbook.PublishObjects.Add(xlSourceRange,url,sheetname,"d1:e2",xlHtmlStatic,"blah","moreblah").Publish (True) 'may fail to create page on website if page didn't already exist
theerr=Err.Number
On Error GoTo 0 'back to default error handling (none)
If theerr <> 0 Then 'if here perhaps because page nonexistent
'msgbox "maybe add warning here [FYI]"
Sheets("dummysheetwithlittleornodata").Copy 'will create workbook
On Error Resume Next
ActiveWorkbook.SaveAs url 'may fail to create webpage first time
ActiveWorkbook.saveAs url 'twice needed for some reason sometimes. [works for me]
On Error GoTo 0
'with fresh dummy html page created, now publish should hopefully work.. let's try again
ActiveWorkbook.Close savechanges:=False 'clean up and avoid popup
Workbooks(wkb).Activate 'get back to correct wkb
Sheets(sheetname).Range("d1:e2").Select
ActiveWorkbook.PublishObjects.Add(xlSourceRange,url,sheetname,"d1:e2",xlHtmlStatic,"blah","moreblah").Publish (True) 'hopefully if failed first time, now it succeeded ! good luck.
End If
The above code structure has allowed me to solve several publish problems I was having. All the techniques together have been enough so far to allow me to save a range from a sheet as a webpage (to server I have write access to) without having to do anything manually (like a manual save or even click on popup). Good Luck.
[The different non-obvious techniques include activating a range before trying a range publish, using the error handling approach and anticipating failure at certain points, the 2x saveas to compensate for mysterious inconsistent failures when using one saveas only, closing and getting back to original workbook cleanly, and using saveas to "guarantee" page exists in form that will make publish to succeed more consistently.]

How to write to a "Google Spreadsheet" from Excel 2003 VBA

I Have an Excel 2003 file with a line similar to this:
I need to click "the button" and it adds that line as the last one on a Google Spreadsheet
Similar to:
Is it possible?
Should I use the command-line Google tools?
Is there a better way? Easier way?
How would you do it?
(once I know how to add "stuff" from VBA to Google Docs, how the f do i add it to the last line?)
More info: I have an Excel 2003 "program" that saves all of the company's sales (with the customer info), and I'd like do make a global address book that's easily updated by my (non it) co-workers.
You don't need OAuth or the spreadsheet API. Google Spreadsheet allows data entry with a simple form, which means also that a HTTP POST will do the trick. You just need to prepare your spreadsheet to accept data entries via a form as follows:
Login to your Google Docs account
Create a spreadsheet or open an existing one
Click on Tools / Create a form
Add anything in the form description just to enable the Save button
Save the form
Copy the formkey value displayed in the link at the bottom of the form creation page
Now you can issue a simple post into the spreadsheet without OAuth
You can test the entry now with curl if you have it on your system (replace the formkey placeholder with the formkey from your table):
curl.exe -v -k "http://spreadsheets.google.com/formResponse?formkey=<formkey>" -d "entry.0.single=test&entry.1.single=test2&pageNumber=0&backupCache=&submit=Submit"
Next we try to execute the form POST from our Excel sheet via the following code. Add a reference to "Microsoft XML, v3.0" before. Replace column1 with your desired values.
Dim httpRequest as XMLHTTP
Set httpRequest = New XMLHTTP
httpRequest.Open "POST", "http://spreadsheets.google.com/formResponse?formkey=<formkey>&ifq", False
httpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
httpRequest.Send "entry.0.single=" + column1 + "&entry.1.single=" + column2 + "&pageNumber=0&backupCache&submit=Submit"
'Check result in the following vars
httpRequest.status
httpRequest.statusText
Hope that helps
I had started answering your question, but realized that it was much less trivial than I thought it was when I started playing with the OAuth 2.0 API. I think it would be a lot easier if you could make your Google spreadsheet public, but I doubt that is advisable with sales data.
The reason this is non-trivial is the authentication part. The ASP OAuth below is probably usable with some work, but I noticed it uses Session variables and some other ASP objects, so you'd have to do a lot of tweaking.
In that light, here is my original answer, if it helps.
There is a google spreadsheet API:
https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row
The OAuth 2.0 link that the spreadsheet docs refer to is out-of-date. You can play with the OAuth requests here, which should help you get started.
API functions are called by GET/POST requests with XML, which you can call using the XMLHTTP object.
First, reference Microsoft XML in your Excel project (Tools->References->Microsoft XML, v6.0)
In your VBA, you essentially use the following to send XML requests:
Dim x as MSXML2.XMLHTTP
Set x = New MSXML2.XMLHTTP
x.Open "POST", "http://example.com/", False
x.Send "<xmldata></xmldata>"
You should be able to adapt this OAuth 2.0 ASP library for your VBA code.
This is an ASP example of how to use that OAuth library; again since both the ASP and the VBA are using the VBScript syntax, it could probably be adapted.
I spent the last couple of days trying to find a good easy solution to this problem.
None seemed to work for me so I had to utilize bits and pieces from various posts I found on-line.
Steps to follow:
Create a Google spreadsheet
Create a form (under “Tools” – “Create a form”) with a three fields (you can add fields later after testing)
Go back to the Google spreadsheet and it should have created a new sheet (called "Form Responses") with headings matching the field names given when setting up the form.
Column A will automatically have as a heading “Timestamp” with your field names as headings for columns B, C & D etc.
Now click on “Form” – “Go to Live Form”
Write-click and “Inspect” (Ctrl-Shift-I) and click on Network
Enter some data (anything) for each of the respective fields and click on “Submit”
Click on “Headers” Click on “formResponse”.
Under “General” copy the url of the form. Note a “?” is required at the end of the url.
Also under headers find “Form Data”. This will be used in MyURL
Look for the entry.123456789 for each of the fields.
You will need these numbers for each field.
Replace xxxxxxxx in your code with your form's respective numbers.
Open up your Excel spreadsheet and copy in the sub-routine shown below
In the VBA editor click on Tools – References select the Microsoft XML.v3.0, (Microsoft XML Core Services)
Code:
Sub Write_Info_To_Google()
Dim ScriptEngine
Dim http As Object
Dim myURL As String
Set http = CreateObject("MSXML2.ServerXMLHTTP")
Set ScriptEngine = CreateObject("MSScriptControl.ScriptControl")
ScriptEngine.Language = "JScript"
ScriptEngine.AddCode "function encode(str) {return encodeURIComponent(str);}"
myURL = "https://docs.google.com/forms/d/e/ . . . . /formResponse?" & _
"entry.xxxxxxxxx=" + Cells(2, 1).Text + _
"&entry.yyyyyyyyy=" + Cells(2, 2).Text + _
"&entry.zzzzzzzzz=" + Cells(2, 3).Text
http.Open "GET", myURL, False
http.setRequestHeader "User-Agent", "Google Chrome 70.03538.102 (compatible; MSIE _
6.0; Windows NT 5.0)"
http.send
End Sub
Run this macro and watch your data from row 2 appear in the Google spreadsheet
Rather than use VBA in Excel, use a full fledged VB.NET application with the Excel Interop COM package. It's syntax is largely similar to the VBA commands, but to do the transferring to Google docs will be much easier in VB.NET.
Use the Google Documents List API to create a new spreadsheet.
Use the Google Spreadsheets API to move the data into your online spreadsheet.
Both Google APIs are REST APIs, so you'll have to use HttpRequest objects in VB.NET. Here is a great example of how to use them, just change the URLs so they are appropriate for Google. Google Spreadsheets even offers a library that abstracts away many of those steps.