AutoIT - winhttp.winhttprequest.5.1 MSXML2.XMLHTTP.6.0 large download fail - xmlhttprequest

I have a problem with winhttp.winhttprequest.5.1 & MSXML2.XMLHTTP.6.0 for download large bin file.
My code :
;Droit Admin
#RequireAdmin
;Handler Error
Global $__g_oHTTP_ErrorHandler = ObjEvent("AutoIt.Error", __HTTP_OnError)
$local = #DesktopDir & "\test.bin"
$lien = "https://mylink1-26Mb"
;$lien = "https://mylink2-11Mb"
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
;First Connection with SSO authenticate
$url = "https://sso.authenticate"
$target = "https://domain"
$body = "USER=ABCD1234&PASSWORD=AZERTY&target=" & $target
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Open("POST", $url, False)
$oHTTP.Send($body)
;Print
ConsoleWrite($oHTTP.Status & #CR)
ConsoleWrite($oHTTP.GetAllResponseHeaders & #CR)
Console :
200
Cache-Control: no-cache, private
Connection: Keep-Alive Date: Thu,25 Aug 2022 07:12:25 GMT
Keep-Alive: timeout=5, max=98
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: text/html;charset=UTF-8
Expires: -1
Server: Apache
Vary: Accept-Encoding
X-Vcap-Request-Id: ############################
;Request HEAD to obtain size file
$oHTTP.Open("HEAD", $lien, False)
$oHTTP.Send()
;Print
$size_cloud_file = $oHTTP.GetResponseHeader("Content-Length")
ConsoleWrite($oHTTP.Status & #CR)
ConsoleWrite($oHTTP.GetAllResponseHeaders & #CR)
Console :
200
Cache-Control: no-cache, private
Connection: Keep-Alive
Date: Thu, 25 Aug 2022 07:12:25 GMT
Keep-Alive: timeout=5, max=97
Pragma: no-cache
qr> Content-Length: 26683497
Content-Type: text/plain;charset=UTF-8
Expires: 0
Server: Apache
Content-Description: File Transfer
Content-Disposition: attachment;filename=file.bin
X-Vcap-Request-Id: ########################
;Download File
$oHTTP.Open("GET", $lien, False)
$oHTTP.Send()
;Print all values
Consolewrite("#Status : " & $oHTTP.Status & #CR)
Consolewrite("#Status Text : " & $oHTTP.StatusText & #CR)
Consolewrite("#GetAllResponseHeaders : " & #CR & $oHTTP.GetAllResponseHeaders & #CR)
;Consolewrite("Response Text : " & $oHTTP.ResponseText & #CR)
if ($oHTTP.option(0)) Then Consolewrite("#UserAgentString : " & $oHTTP.option(0) & #CR)
if ($oHTTP.option(1)) Then Consolewrite("#URL : " & $oHTTP.option(1) & #CR)
if ($oHTTP.option(2)) Then Consolewrite("#URLCodePage : " & $oHTTP.option(2) & #CR)
if ($oHTTP.option(3)) Then Consolewrite("#EscapePercentInURL : " & $oHTTP.option(3) & #CR)
if ($oHTTP.option(4)) Then Consolewrite("#SslErrorIgnoreFlags : " & $oHTTP.option(4) & #CR)
if ($oHTTP.option(5)) Then Consolewrite("#SelectCertificate : " & $oHTTP.option(5) & #CR)
if ($oHTTP.option(6)) Then Consolewrite("#EnableRedirects : " & $oHTTP.option(6) & #CR)
if ($oHTTP.option(7)) Then Consolewrite("#UrlEscapeDisable : " & $oHTTP.option(7) & #CR)
if ($oHTTP.option(8)) Then Consolewrite("#UrlEscapeDisableQuery : " & $oHTTP.option(8) & #CR)
if ($oHTTP.option(9)) Then Consolewrite("#SecureProtocols : " & $oHTTP.option(9) & #CR)
if ($oHTTP.option(10)) Then Consolewrite("#EnableTracing : " & $oHTTP.option(10) & #CR)
if ($oHTTP.option(11)) Then Consolewrite("#RevertImpersonationOverSsl : " & $oHTTP.option(11) & #CR)
if ($oHTTP.option(12)) Then Consolewrite("#EnableHttpsToHttpRedirects : " & $oHTTP.option(12) & #CR)
if ($oHTTP.option(13)) Then Consolewrite("#EnablePassportAuthentication : " & $oHTTP.option(13) & #CR)
if ($oHTTP.option(14)) Then Consolewrite("#MaxAutomaticRedirects : " & $oHTTP.option(14) & #CR)
if ($oHTTP.option(15)) Then Consolewrite("#MaxResponseHeaderSize : " & $oHTTP.option(15) & #CR)
if ($oHTTP.option(16)) Then Consolewrite("#MaxResponseDrainSize : " & $oHTTP.option(16) & #CR)
if ($oHTTP.option(17)) Then Consolewrite("#EnableHttp1_1 : " & $oHTTP.option(17) & #CR)
if ($oHTTP.option(18)) Then Consolewrite("#EnableCertificateRevocationCheck : " & $oHTTP.option(18) & #CR)
Console :
#Status : 200
#Status Text : OK
#GetAllResponseHeaders :
Cache-Control: no-cache, private
Connection: Keep-Alive
Date: Thu, 25 Aug 2022 07:12:26 GMT
Keep-Alive: timeout=5, max=96
Pragma: no-cache
Content-Length: 26683497
Content-Type: text/plain;charset=UTF-8
Expires: 0
Server: Apache
Vary: Accept-Encoding
Content-Description: File Transfer
Content-Disposition: attachment;filename=file.bin
X-Vcap-Request-Id: ######################################
#UserAgentString : Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
#URL : https://mylink1-26Mb
#URLCodePage : 65001
#EnableRedirects : True
#UrlEscapeDisableQuery : True
#RevertImpersonationOverSsl : True
#MaxAutomaticRedirects : 10
#MaxResponseHeaderSize : 65536
#MaxResponseDrainSize : 1024000
#EnableHttp1_1 : True
;Copy ResponseBody to bin local file
FileDelete($local)
$handle = FileOpen($local, 18)
FileWrite($handle, $oHTTP.ResponseBody) ;=> ResponseBody empty or not exist
FileClose($handle)
Func __HTTP_OnError($oError)
ConsoleWrite(#ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & #CRLF & _
#TAB & "err.number is: " & #TAB & #TAB & "0x" & Hex($oError.number) & #CRLF & _
#TAB & "err.windescription:" & #TAB & $oError.windescription & #CRLF & _
#TAB & "err.description is: " & #TAB & $oError.description & #CRLF & _
#TAB & "err.source is: " & #TAB & #TAB & $oError.source & #CRLF & _
#TAB & "err.helpfile is: " & #TAB & $oError.helpfile & #CRLF & _
#TAB & "err.helpcontext is: " & #TAB & $oError.helpcontext & #CRLF & _
#TAB & "err.lastdllerror is: " & #TAB & $oError.lastdllerror & #CRLF & _
#TAB & "err.scriptline is: " & #TAB & $oError.scriptline & #CRLF & _
#TAB & "err.retcode is: " & #TAB & "0x" & Hex($oError.retcode) & #CRLF & #CRLF)
EndFunc ;==>_MyCOMErrFunc
If i use the same script with a 11Mb file, there are no problem !
It's same error with COM : "MSXML2.XMLHTTP.6.0"
Thanks for your help !

Solution :
I use https://github.com/dragana-r/autoit-winhttp
Thanks to #dragana
#include <WinHttpConstants.au3>
#include <WinHttp.au3>
Func Download($lien,$local,$progressbar)
;Check compatibility with windows
If Not _WinHttpCheckPlatform() Then
ConsoleWrite("WinHTTP not compatible" & #CR)
Return "WinHTTP not compatible"
EndIf
$sProxy = "my_proxy:my_port"
$sProxyBypass = "my_proxy_local_bypass"
$url = "https://sso.authenticate"
$target = "https://domain"
$body = "USER=ABCD1234&PASSWORD=AZERTY&target=" & $target
;First connexion POST
;OPEN
$hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240", _
$WINHTTP_ACCESS_TYPE_NAMED_PROXY, _
$sProxy, _
$sProxyBypass)
if #error Then
ConsoleWrite("ERREUR : WinHttpOpen :" & #error & #CR)
Return "ERREUR : WinHttpOpen"
EndIf
;CONNECT
$hConnect = _WinHttpConnect($hOpen, $url, $INTERNET_DEFAULT_HTTPS_PORT)
if #error Then
ConsoleWrite("ERREUR : WinHttpConnect1 : " & #error)
Return "ERREUR : WinHttpConnect1"
EndIf
;REQUEST SEND
$hRequest = _WinHttpSimpleSendSSLRequest($hConnect, "POST", $surl, $WINHTTP_NO_REFERER, $body)
if #error Then
ConsoleWrite("ERREUR : WinHttpSimpleSendSSLRequest1 : " & #error)
Return "ERREUR : WinHttpSimpleSendSSLRequest1"
EndIf
;WAIT
_WinHttpReceiveResponse($hRequest)
;OUT if problems
If ( _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_STATUS_CODE) <> 200 ) Then
ConsoleWrite("ERREUR : Connexion fail" & #CR)
Return "ERREUR : Connexion fail"
EndIf
;Second : HEAD (obtain size)
$url_crack = _WinHttpCrackUrl($lien)
$url = $url_crack[0] & "://" & $url_crack[2] & "/"
$surl = $url_crack[6] & $url_crack[7]
$hConnect = _WinHttpConnect($hOpen, $url, $INTERNET_DEFAULT_HTTPS_PORT)
if #error Then
ConsoleWrite("ERREUR : WinHttpConnect2 : " & #error)
Return "ERREUR : WinHttpConnect2"
EndIf
$hRequest = _WinHttpSimpleSendSSLRequest($hConnect, "HEAD", $surl, $WINHTTP_NO_REFERER)
if #error Then
ConsoleWrite("ERREUR : WinHttpSimpleSendSSLRequest2 : " & #error & #CR)
Return "ERREUR : WinHttpSimpleSendSSLRequest2"
EndIf
;WAIT
_WinHttpReceiveResponse($hRequest)
;OUT if problems
If ( _WinHttpQueryOption($hRequest, $WINHTTP_OPTION_URL) <> $lien ) Then
ConsoleWrite("ERREUR : Requête HEAD" &#CR)
Return "ERREUR : Requête HEAD"
EndIf
$size_cloud_file = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_LENGTH)
$size_local_file = FileGetSize($local)
GUICtrlSetData($progressbar, 0)
GUICtrlSetState($progressbar, $GUI_SHOW)
;If size is different
If $size_cloud_file <> $size_local_file Then
;CONNECT
$hConnect = _WinHttpConnect($hOpen, $url, $INTERNET_DEFAULT_HTTPS_PORT)
if #error Then
ConsoleWrite("ERREUR : WinHttpConnect3 : " & #error & #CR)
Return "ERREUR : WinHttpConnect3"
EndIf
$hRequest = _WinHttpSimpleSendSSLRequest($hConnect, _
"GET", _
$surl, _
Default, _
Default, _
Default)
if #error Then
ConsoleWrite("ERREUR : WinHttpSimpleSendSSLRequest : " & #error)
Return "ERREUR : WinHttpSimpleSendSSLRequest"
EndIf
$sData = Binary("")
If _WinHttpQueryDataAvailable($hRequest) Then
While 1
$sChunk = _WinHttpReadData($hRequest, 2)
If #error Then ExitLoop
$sData &= $sChunk
$pourcent = Int((BinaryLen($sData) / $size_cloud_file) * 100)
GUICtrlSetData($progressbar, $pourcent)
WEnd
Else
ConsoleWrite("ERREUR : WinHttpQueryDataAvailable : " & #error)
Return "ERREUR : WinHttpQueryDataAvailable"
EndIf
;Copy Byte Array to file
FileDelete($local)
$handle = FileOpen($local, 18)
FileWrite($handle, $sData)
FileClose($handle)
;If fail copy or download
If ( FileGetSize($local) <> $size_cloud_file ) Then
ConsoleWrite("ERREUR : File error" & #CR)
Return "ERREUR : File error"
EndIf
endfunc

Related

VBA Rest API - DHL Return label - 401

I am trying to create a return shipping DHL parcel label with provided DHL api in the sandbox:
https://developer.dhl.com/api-reference/parcel-de-returns-post-parcel-germany#get-started-section/user-guide
With postman it works. But I would like to implement the HTTP Request in VBA.
I always receive status 401 Unauthorized
I guess it is the way how I pass the credentials.
Anyone has an idea how to get it working?
create return labels in the sandbox, with the following user data:
Username: "2222222222_customer"
Password: "uBQbZ62!ZiBiVVbhc"
Sub restAPICall()
Dim objRequest As MSXML2.ServerXMLHTTP60
Dim id_header_name As String, id_key As String, secret_header_name As String, secret_key As String
Dim strUrl As String
Dim blnAsync As Boolean
Dim strResponse As String
Dim json As Object
Dim authKey As String
Set objRequest = New ServerXMLHTTP60
strUrl = "https://api-sandbox.dhl.com/parcel/de/shipping/returns/v1/orders?labelType=BOTH" 'Endpoint Test
blnAsync = False
id_key = "2222222222_customer"
pass = "uBQbZ62!ZiBiVVbhc"
apiKey = "123456789"
body = "{""receiverId"":""deu"", " _
& " ""customerReference"":""Kundenreferenz"", " _
& " ""shipmentReference"":""Sendungsreferenz"", " _
& " ""shipper"": { " _
& " ""name1"":""Absender Retoure Zeile 1"", " _
& " ""name2"":""Absender Retoure Zeile 2"", " _
& " ""name3"":""Absender Retoure Zeile 3"", " _
& " ""addressStreet"":""Charles-de-Gaulle Str."", " _
& " ""addressHouse"":""20"", " _
& " ""city"":""Bonn"", " _
& " ""email"":""Max.Mustermann#dhl.local"", " _
& " ""phone"":""+49 421 987654321"", " _
& " ""postalCode"":""53113"", " _
& " ""state"":""NRW"", " _
& " }, " _
& " ""itemWeight"": { " _
& " ""uom"": ""g"", " _
& " ""value"":""1000"", " _
& " }, " _
& " ""itemValue"": { " _
& " ""currency"": ""EUR"", " _
& " ""value"":""100"", " _
& " }, " _
& "}"
With objRequest
.Open "POST", strUrl, blnAsync ', gkpuser, gkpass
.setRequestHeader "Authorization", "Basic " + EncodeBase64(id_key + ":" + pass)
.setRequestHeader "Content-Type", "application/json"
.setRequestHeader "Accept", "application/json"
.setRequestHeader "dhl-api-key", "apiKey"
.Send body
While objRequest.readyState <> 4
DoEvents
Wend
strResponseHeaders = .StatusText
strResponse = .responseText
allResponseHeader = .GetAllResponseHeaders
End With
Debug.Print body
Debug.Print allResponseHeader
Debug.Print strResponse
End Sub
Function EncodeBase64(text$)
Dim b
With CreateObject("ADODB.Stream")
.Open: .Type = 2: .Charset = "utf-8"
.WriteText text: .Position = 0: .Type = 1: b = .Read
With CreateObject("Microsoft.XMLDOM").createElement("b64")
.DataType = "bin.base64": .nodeTypedValue = b
EncodeBase64 = Replace(Mid(.text, 5), vbLf, "")
End With
.Close
End With
End Function
Many thanks :)
Alex
If apiKey is a variable, then you should leave the quotes out in:
.setRequestHeader "dhl-api-key", "apiKey"

Access Denied Query XML SOAP Sharepoint

The code worked very well, but these last days just stopped to work.
The .responseText is now:
Access is denied. (Exception from HRESULT: 0x80070005
(E_ACCESSDENIED))"
I tried with and without the line: objXMLHTTP.setRequestHeader "Authorization" And got the same Error.
With and without User and Password at line objXMLHTTP.Open, and still the same problem, Access Denied.
Can you guys help me please?
Sub selectSharepoint()
Dim objXMLHTTP As MSXML2.XMLHTTP
Dim strBatchXml As String
Dim strSoapBody As String
UserName = "john#email.com"
Password = "123456"
Set objXMLHTTP = New MSXML2.XMLHTTP
objXMLHTTP.Open "POST", "https://ts.sharepoint.com/sites/2018_teste/_vti_bin/lists.asmx", False, UserName, Password
'objXMLHTTP.Open "POST", "https://ts.sharepoint.com/sites/2018_teste/_vti_bin/lists.asmx", False 'This way worked the same, and got the same error.
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=UTF-8"
objXMLHTTP.setRequestHeader "Content-Length", "length"
'objXMLHTTP.setRequestHeader "Authorization", "Basic " + Base64Encode(UserName & ":" & Password) 'makes no effect, with or without Base64Encode
objXMLHTTP.setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems"
strSoapBody = "<?xml version='1.0' encoding='utf-8'?>" & _
" <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" & _
" <soap:Body>" & _
" <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>" & _
" <listName>AllNames</listName>" & _
" <query>" & _
" <Query xmlns=''>" & _
" <Where>" & _
" <Eq>" & _
" <FieldRef Name='Name' />" & _
" <Value Type='Text'>Cloe</Value>" & _
" </Eq>" & _
" </Where>" & _
" <OrderBy>" & _
" <FieldRef Name='ID' />" & _
" </OrderBy>" & _
" </Query>" & _
" </query>"
strSoapBody = strSoapBody & _
" <rowLimit>1</rowLimit>" & _
" <viewFields><ViewFields>" & _
" <FieldRef xsi:type='s:string' Name='Name'></FieldRef>" & _
" </ViewFields></viewFields>" & _
" </GetListItems>" & _
" </soap:Body>" & _
" </soap:Envelope>"
objXMLHTTP.send strSoapBody
If objXMLHTTP.Status <> 200 Then
MsgBox ("Error! " & Chr(10) & objXMLHTTP.responseText)
End
Else
tudo = objXMLHTTP.responseText
End If
End Sub
MsgBox Error:
MsgBox Error

vb.net webclient class throw an out of memory exception

I use VB.Net with VisualStudio 2015 and .net 4.5.2.
I use the System.Net.WebClient class to UPLOAD ASYNC FILES into a webserver with the methode UploadFileAsync(address as URI, fileName as string) but a System.OutOfMemoryException accured when the fileSize is too large...
Any idea?
Thank you!
Resolved.
There was an error here :
postStreamHeaders = boundary & vbCrLf & "Content-Disposition: form-data; name=""var1""" & vbCrLf & vbCrLf & "val1" & vbCrLf
postStreamHeaders = boundary & vbCrLf & "Content-Disposition: form-data; name=""var2""" & vbCrLf & vbCrLf & "val2" & vbCrLf
postStreamFooters = boundary & "--"
The good syntax is :
postStreamHeaders = "--" & boundary & vbCrLf & "Content-Disposition: form-data; name=""var1""" & vbCrLf & vbCrLf & "val1" & vbCrLf
postStreamHeaders &= "--" & boundary & vbCrLf & "Content-Disposition: form-data; name=""var2""" & vbCrLf & vbCrLf & "val2" & vbCrLf
postStreamFooters = "--" & boundary & "--" & vbCrLf
Hope this may help someone else ...

Converting from GoogleApp Provisioning API to new SDKs

We have been creating and managing our GoogleApps accounts for a couple years by simply generating a block of XML code for the Provisioning API, and then using VBScript to do a POST. Now GoogleApps is requiring that we move to the new Administrative SDKs, and I'm not understanding how, or even if, we can do something similar with the new system.
Here is an example of the code we use to first get an authentication token:
' Create and send XML message to GoogleApps requesting Authentication Token
Set objXMLHTTP = CreateObject("Microsoft.XmlHttp")
objXMLHTTP.open "POST", "https://www.google.com/accounts/ClientLogin", FALSE
objXMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objXMLHTTP.send "&Email=Administrator%40company%2Ecom%2Eedu&Passwd=P#ssw0rd&accountType=HOSTED&service=apps"
If Err.Number <> 0 Then
WScript.Echo "Error: send request for GoogleApp Authentication Token failed"
WScript.Quit(1)
End If
' Get response from GoogleApps
strGGAATAuthToken = objXMLHTTP.responseText
If Err.Number <> 0 Then
WScript.Echo "ERROR: Getting GoogleApp Authentication Token (XMLHTTP.responseText) "
WScript.Quit(1)
End If
' Check for known errors in response text
If LCase(Left(strGGAATAuthToken, 6)) = "error=" Then
WScript.Echo "ERROR: GoogleApp replied with Error when asking for Authentication Token"
WScript.Quit(1)
Else
' Extract and return Authentication Token from response text
strGGAATToken = Mid(strGGAATAuthToken, InStr(strGGAATAuthToken, "Auth=") + 5)
GetGAAuthToken = True
End If
Here is a sample of the code we then use to create the account:
' Create XML Record that will be sent to GoogleApps
strXMLRecord = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & _
"?>" & vbCRLF
strXMLRecord = strXMLRecord & "<atom:entry xmlns:atom=" & Chr(34) & "http://www.w3.org/2005/Atom" & Chr(34) & _
vbCRLF
strXMLRecord = strXMLRecord & " xmlns:apps=" & Chr(34) & "http://schemas.google.com/apps/2006" & Chr(34) & _
">" & vbCRLF
strXMLRecord = strXMLRecord & " <atom:category scheme=" & Chr(34) & "http://schemas.google.com/g/2005#kind" & _
Chr(34) & vbCRLF
strXMLRecord = strXMLRecord & " term=" & Chr(34) & "http://schemas.google.com/apps/2006#user" & Chr(34) & _
"/>" & vbCRLF
strXMLRecord = strXMLRecord & " <apps:login userName=" & Chr(34) & strCGAAUsername & Chr(34) & vbCRLF
strXMLRecord = strXMLRecord & " password=" & Chr(34) & strCGAAPwd & Chr(34) & vbCRLF
strXMLRecord = strXMLRecord & " changePasswordAtNextLogin=" & Chr(34) & "true" & Chr(34) & vbCRLF
strXMLRecord = strXMLRecord & " suspended=" & Chr(34) & "false" & Chr(34) & "/>" & vbCRLF
' The following line is just so we have the syntax if we need to set quotas
'*****strXMLRecord = strXMLRecord & " <apps:quota limit=" & Chr(34) & "2048" & Chr(34) & "/>" & vbCRLF*****
strXMLRecord = strXMLRecord & " <apps:name familyName=" & Chr(34) & strCGAALastName & Chr(34) & " givenName=" & _
Chr(34) & strCGAAFirstName & Chr(34) & "/>"
strXMLRecord = strXMLRecord & vbCRLF & "</atom:entry>" & vbCRLF
' Create XML object, set headers, and send to GoogleApps
Set objXMLHTTP = CreateObject("Microsoft.XmlHttp")
objXMLHTTP.open "POST", "https://apps-apis.google.com/a/feeds/company.com/user/2.0", FALSE
objXMLHTTP.setRequestHeader "Content-type", "application/atom+xml"
objXMLHTTP.setRequestHeader "Authorization", "GoogleLogin auth=" & strGAAuthToken
objXMLHTTP.send strXMLRecord
If Err.Number <> 0 Then
WScript.Echo "ERROR: unable to XMLHTTP.send for GoogleApps acct creation"
CreateGAAccount = False
WScript.Quit(1)
End If
' Get response from GoogleApps
strResponseText = objXMLHTTP.responseText
If Err.Number <> 0 Then
WScript.Echo "ERROR: unable to get objXMLHTTP.responseText during GoogleApps acct creation"
CreateGAAccount = False
WScript.Quit(1)
End If
' If response reports an error exit function returning False
If InStr(Lcase(strResponseText), "errorcode=") <> 0 Then
WScript.Echo "ERROR: unable to create GoogleApps account"
CreateGAAccount = False
WScript.Quit(1)
End If
' Log GoogleApps account information returned from creation
WScript.Echo "GoogleApp account created for: " & strCGAAUsername
It's probably obvious, but I have a Windows background, not Linux; and I've done scripting, but not real programming. (And I have no experience doing Java and/or other Web programming at all.)
Thanks for any help!!
The steps to use the Admin SDK are very similar.
First you will get authenticated, now google uses Oauth 2 here you can find the documentation on that https://developers.google.com/accounts/docs/OAuth2
here you can test how Oauth works: https://developers.google.com/oauthplayground/
After being authenticated you can now call the Directory API to create a new user. Here is the documentation related to the insert method https://developers.google.com/admin-sdk/directory/v1/reference/users/insert
As you can see in the Doc, you will be sending the same parameters (name, password, etc.) but now it won't be formatted as xml, instead those parameter will be formatted as json (here is a little information on json formatting: http://www.w3schools.com/json/)
I know it's a lot of information, I hope it helps.

How to evaluate stored functions?

I have the following saved in a database.
Function SearchFileForName()
SearchFileForName = False
Set fso = CreateObject("Scripting.FileSystemObject")
Set csvFile = fso.OpenTextFile("ListOfUsers.csv", 1)
Do Until csvFile.AtEndOfStream
if app.userID = csvFile.ReadLine then
SearchFileForName = true
end if
loop
end Function
Function WriteNameToFile()
Set fso = CreateObject("Scripting.FileSystemObject")
Set csvFile = fso.OpenTextFile("ListOfUsers.csv", 8)
csvFile.WriteLine app.userID
end function
Function theMessage()
if weekday(Now()) = vbfriday then
response = msgbox ("Great Job "& split(app.userid, ".")(0) & "!" & _
vbnewline & vbnewline & _
"Keep up the good work and keep that morale high." & _
vbnewline & vbnewline & _
"Would you like a cookie for your efforts?", vbyesno)
if response = vbyes then
msgbox "Enjoy =)" & _
vbnewline & _
vbnewline & _
vbnewline & _
" _ . : : : : : . _" & vbnewline & _
" . : : : ` _ | _ ` : : : ." & vbnewline & _
" / : : ` - - | - - ` : : \" & vbnewline & _
" | : ` . - - - ` - - - . ` : |" & vbnewline & _
" | : ( O R E O ) : |" & vbnewline & _
" | : : ` - - - - - - - ` : : |" & vbnewline & _
" \ : : : . . . . . . . : : : /" & vbnewline & _
" ` : : : : : : : : : : : `" & vbnewline & _
" ` ` ` ` ` ` `" & vbnewline
elseif response = vbno then
msgbox "That is too bad." & vbnewline & _
"Here is a cookie anyways." & vbnewline & _
"Enjoy =)" & _
vbnewline & _
vbnewline & _
vbnewline & _
" _ . : : : : : . _" & vbnewline & _
" . : : : ` _ | _ ` : : : ." & vbnewline & _
" / : : ` - - | - - ` : : \" & vbnewline & _
" | : ` . - - - ` - - - . ` : |" & vbnewline & _
" | : ( O R E O ) : |" & vbnewline & _
" | : : ` - - - - - - - ` : : |" & vbnewline & _
" \ : : : . . . . . . . : : : /" & vbnewline & _
" ` : : : : : : : : : : : `" & vbnewline & _
" ` ` ` ` ` ` `" & vbnewline
end if
end if
End Function
Function easterEgg()
if not SearchFileForName() then
WriteNameToFile
theMessage
end if
end Function
So I call it with the following sql query
Function easterEgg0()
Set rseasterEgg = CreateObject("ADODB.RecordSet")
rseasterEgg.Open _
" SELECT dyCode " & _
" FROM DDCode " & _
" WHERE dyName = 'EasterEggScript'", _
Connection, adOpenStatic, adLockBatchOptimistic, adCmdText
Execute rseasterEgg.fields("dyCode").value
Call easterEgg
End Function
When I print it out it looks exactly as expected. But when I try to run it I get an error saying Typemismatch: 'SearchFileForName'?
What am I doing wrong?
From MSDN - Execute Statement
The context in which the Execute statement is invoked determines what
objects and variables are available to the code being run. In-scope
objects and variables are available to code running in an Execute
statement. However, it is important to understand that if you execute
code that creates a procedure, that procedure does not inherit the
scope of the procedure in which it occurred.
Like any procedure, the new procedure's scope is global, and it
inherits everything in the global scope. Unlike any other procedure,
its context is not global scope, so it can only be executed in the
context of the procedure where the Execute statement occurred.
However, if the same Execute statement is invoked outside of a
procedure (i.e., in global scope), not only does it inherit everything
in global scope, but it can also be called from anywhere, since its
context is global.
To overcome this use ExecuteGlobal instead.
Function easterEgg0()
Set rseasterEgg = CreateObject("ADODB.RecordSet")
rseasterEgg.Open _
" SELECT dyCode " & _
" FROM DDCode " & _
" WHERE dyName = 'EasterEggScript'", _
Connection, adOpenStatic, adLockBatchOptimistic, adCmdText
ExecuteGlobal rseasterEgg.fields("dyCode").value
Call easterEgg
End Function