Error throwing when connecting api with client I'd and key - excel

I'm trying to access data through an API that takes in a X-client-id and x-api-key. I've tried the following so far but it's not working. Can anyone help?
Dim request as new winhttprequest
Request.open "Get", url, False
Request.setrequestheader "Accept", "application/json"
Request.setrequestheader "X-client-id", "[Id]"
Request.setrequestheader "x-api-key", "[key]"

Related

return results via express with lighthouse npm library

https://googlechrome.github.io/lighthouse/viewer/?psiurl=https%3A%2F%2Fwww.zfcakademi.com%2F&strategy=mobile&category=performance&category=accessibility&category=best-practices&category=seo&category=pwa&utm_source=lh-chrome-ext&output=json
In inquiries we made over the address
https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://run-fix.com/&strategy=mobile&utm_source=lh-chrome-ext&category=performance&category=accessibility&category=best-practices&category=seo&category=pwa
The results are returned to us by using the API. However, when using this api, a token is sent via the github page. Access is provided by this token. In order to send a request without a token, you need to refresh the page with the help of cookies created after opening the page. Otherwise, it gives 403 access permissions error.
axios.get(`https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://www.zfcakademi.com/&strategy=desktop&utm_source=lh-chrome-ext&category=performance&category=accessibility&category=best-practices&category=seo&category=pwa`, {
"headers": {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36',
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-language": "tr,en-US;q=0.9,en;q=0.8,tr-TR;q=0.7,ru;q=0.6",
"cache-control": "max-age=0",
"sec-ch-dpr": "1.5",
"sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"101\", \"Google Chrome\";v=\"101\"",
"sec-ch-ua-arch": "\"x86\"",
"sec-ch-ua-bitness": "\"64\"",
"sec-ch-ua-full-version": "\"101.0.4951.64\"",
"sec-ch-ua-full-version-list": "\" Not A;Brand\";v=\"99.0.0.0\", \"Chromium\";v=\"101.0.4951.64\", \"Google Chrome\";v=\"101.0.4951.64\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-model": "\"\"",
"sec-ch-ua-platform": "\"Windows\"",
"sec-ch-ua-platform-version": "\"10.0.0\"",
"sec-ch-ua-wow64": "?0",
"sec-ch-viewport-width": "853",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "same-origin",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1",
"x-client-data": "CIS2yQEIorbJAQjEtskBCKmdygEI9eHKAQiTocsBCNvvywEInvnLAQjmhMwBCJmazAEI2qnMAQiJq8wBCOurzAEIwqzMARirqcoB"
},
"referrerPolicy": "origin",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
})
.then(resp => {
resolve(resp.data)
})
When I send a request in this way, I get a 403 error as in the picture below and I cannot access it. They have set up a cookie system. In the Lighthouse npm library, only getting data with commands is shown. I'm trying to create an api with express, but I couldn't find the slightest resource how to use it with lighthouse express. Everyone has used it with the help of command line. Can you please help? How can I combine express and lighthouse? For my client, this seo data is very important.
https://www.npmjs.com/package/lighthouse?activeTab=readme

XMLHttpRequest from VBA returns error 406 "Not Accepted"

I'm trying to do some scraping using Excel VBA, specifically, to get a JSON from a server.
I'm using exactly the same request headers that show on the browsers dev tools, but when I do this request from Excel I always get a 406 ("Not accepted") answer from the server.
What am I missing?
Sub getJSON()
Dim XHR As New MSXML2.ServerXMLHTTP60
XHR.Open "GET", "https://www.magazineluiza.com.br/produto/calculo-frete/08226021/615254900/frigelar.json", False
XHR.setRequestHeader "Host", "www.magazineluiza.com.br"
XHR.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0"
XHR.setRequestHeader "Accept", "application/json, text/javascript, */*; q=0.01"
XHR.setRequestHeader "Accept-Language", "pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3"
XHR.setRequestHeader "Accept-Encoding", "gzip, deflate, br"
XHR.setRequestHeader "X-Requested-With", "XMLHttpRequest"
XHR.setRequestHeader "Connection", "keep-alive"
XHR.setRequestHeader "Referer", "https://www.magazineluiza.com.br/refrigerador-expositor-para-bebidas-metalfrio-com-controlador-eletronico-497-litros-vb52r-220v/p/6152549/pi/expb/"
XHR.setRequestHeader "TE", "Trailers"
XHR.send
Debug.Print XHR.responseText
End Sub
This is the answer I get on the browser:
{"address":{"address":"18 DE ABRIL","area":"CIDADE ANTONIO ESTEVAO DE CARVALHO","city":"SAO PAULO","state":"SP","zip_code":"08226021"},"delivery":[{"description":"Entrega padrĂ£o","distribution_center":0,"is_deadline":true,"price":"263.91","time":13,"zip_code_restriction":false}],"is_delivery_unavailable":false,"zip_code":"08226021"}
Edit: This JSON is retrieved by the browser when I add the zip code "08226021" on the right side of this page and click "Ok".
Try this to get the required response:
Sub FetchJsonResponse()
Const Url$ = "https://www.magazineluiza.com.br/produto/calculo-frete/08226021/615254900/frigelar.json"
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", Url, False
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
.setRequestHeader "Referer", "https://www.magazineluiza.com.br/refrigerador-expositor-para-bebidas-metalfrio-com-controlador-eletronico-497-litros-vb52r-220v/p/6152549/pi/expb/"
.setRequestHeader "x-requested-with", "XMLHttpRequest"
.send
Debug.Print .responseText
End With
End Sub
This is the output it produces:
{"address": {"address": "18 DE ABRIL", "area": "CIDADE ANTONIO ESTEVAO DE CARVALHO", "city": "SAO PAULO", "state": "SP", "zip_code": "08226021"}, "delivery": [{"description": "Entrega padr\u00e3o", "distribution_center": 0, "is_deadline": true, "price": "263.91", "time": 13, "zip_code_restriction": false}], "is_delivery_unavailable": false, "zip_code": "08226021"}

VBA HTTP Request showing runtime error in different system

I am facing error for my VBA(HTTP Request) code. while in my another system it is working fine.
system(windows-8 /office-365): Problem (runtime error:'-2147024809 (80070057)': The Parameter is incorrect.)
system(windows-10 /office-16): No Problem
References are same in both systems.
Please help me..!!
enter image description here
Here is the Code:
Dim cook As String
Dim body1 As String
Dim xmlhttp As Object
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
cook = Worksheets("Action").Range("I2").Value
body1 = Worksheets("Action").Range("I3").Value
URL = "https://trade.xxxxxxx.in/ITSStreamer/streamer/UserManagementServlet"
xmlhttp.Open "POST", URL, False
xmlhttp.setRequestHeader "Host", "trade.xxxxxxx.in"
xmlhttp.setRequestHeader "Connection", "keep-alive"
xmlhttp.setRequestHeader "Content-Length", "700"
xmlhttp.setRequestHeader "Accept", "application/json, text/javascript, */*; q=0.01"
xmlhttp.setRequestHeader "Origin", "https://trade.xxxxxxx.in"
xmlhttp.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
xmlhttp.setRequestHeader "Referer", "https://trade.xxxxxxx.in/NEWITS/InterfaceToValidateToken.do?"
xmlhttp.setRequestHeader "Accept-Encoding", "gzip, deflate, br"
xmlhttp.setRequestHeader "Accept-Language", "en-US,en;q=0.9"
xmlhttp.setRequestHeader "Cookie", cook
xmlhttp.send body1
Debug.Print xmlhttp.ResponseText

Is it possible to convert a cURL request to a VBA winHttpRequest?

I have the request below, trying to get a paypal auth token to retrieve a transaction list from my account.
curl -v https://api.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "client_id:secret" \
-d "grant_type=client_credentials"
And I have gone this far:
Set objHTTP = New WinHttp.WinHttpRequest
sURL = "https://api.sandbox.paypal.com/v1/oauth2/token"
objHTTP.Open "POST", sURL, False
'what should go here? is the POST request correct? Are -H in cURL for headers?
objHTTP.send (sBody)
Can you help me get this working? Is there maybe an easier way to have the cURL requests "converted"?
EDIT:
sURL = "https://api.sandbox.paypal.com/v1/oauth2/token"
objHTTP.Open "POST", sURL, False
objHTTP.SetRequestHeader "Content-Type", "application/json"
objHTTP.SetRequestHeader "Accept", "application/json"
User = "user"
Password = "password"
objHTTP.SetRequestHeader "Authorization", "Basic " & Base64Encode(User + ":" + Password)
Runtime Error 5
Invalid procedure call or arguement. Any ideas?
Here's a working example. I don't run Excel anymore so I can't get at the code but it's in there, just open the macro editor. This uses the MSXML library to do an XHR fetch from a REST API.
https://rack.pub/cdn/miles.xlam

MSXML2.XMLHTTP not working in company network

I've built a macro for a client that POSTs some data to an external URL which requires basic authentication (get/save data in cloud database via api). When I'm running the macro from home (or basically anywhere) it works perfectly. However, when my client runs it (while in his company network), he gets a timeout error message after a few seconds. Any suggestions on what the cause could be?
Here is my code:
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
With objHTTP
.Open "POST", url, False
.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
.SetRequestHeader "Content-Type", "application/json"
.SetRequestHeader "Accept", "application/json"
.SetRequestHeader "Authorization", "Basic " + Base64EncodeString(apiKey + ":" + apiPw)
.Send (data)
End With

Resources