0

I have created a project on parse.com with cloud code.

Now I want to create a VBScript to call CURL as below.

curl -X POST \
  -H "X-Parse-Application-Id: myAppId" \
  -H "Content-Type: application/json" \
  -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
  http://localhost:1337/parse/classes/GameScore

curl -X POST \
  -H "X-Parse-Application-Id: myAppId" \
  -H "Content-Type: application/json" \
  -d '{}' \
  http://localhost:1337/parse/functions/hello

In javascript we can achieve it by following code.

Parse.initialize('myAppId','unused');
Parse.serverURL = 'https://whatever.herokuapp.com';

var obj = new Parse.Object('GameScore');
obj.set('score',1337);
obj.save().then(function(obj) {
  console.log(obj.toJSON());
  var query = new Parse.Query('GameScore');
  query.get(obj.id).then(function(objAgain) {
    console.log(objAgain.toJSON());
  }, function(err) {console.log(err); });
}, function(err) { console.log(err); });

How can I achieve it using VBScript for .vbs file?

Jignesh Patel
  • 189
  • 1
  • 16
  • This example is Classic ASP which uses VBScript but can be adapted - [How can I post data using cURL in asp classic?](http://stackoverflow.com/a/37462944/692942) – user692942 Jul 06 '16 at 07:14

1 Answers1

2

Please try the following code.

strRequest="{""eventId"":""TOaDAOqueV""}"
EndPointLink = "http://X.X.X.X:1337/parse/functions/method"

dim http
set http=createObject("Microsoft.XMLHTTP")
http.open "POST",EndPointLink,false
http.setRequestHeader "Content-Type","application/json"
http.setRequestHeader "X-Parse-Application-Id","XXXXXXXXXXXXXXXXXXXXX"

msgbox "REQUEST : " & strRequest
http.send strRequest

If http.Status = 200 Then
    msgbox "RESPONSE : " & http.responseText
    responseText=http.responseText
else
    msgbox "ERRCODE : " & http.status
End If

Answer partially taken from HTTP GET in VBS by @rajkumar-joshua-m

Community
  • 1
  • 1
  • Hi Kaludi, there was some syntax error in your code I have edited. But your solution just worked for me. Thanks a lot for the solution :). – Jignesh Patel Jul 06 '16 at 07:35
  • Bear in mind that just checking for HTTP status of `200` means `HTTP 203 Created` would not be classed as a success, ideally you should check you receive any 2xx response as they are all success codes. Something like `Left(http.Status, 1) = 2` should be enough. – user692942 Jul 06 '16 at 08:30
  • When you use someone else's code please provide attribution - See [HTTP GET in VBS](http://stackoverflow.com/a/37813009/692942) *(direct copy / paste slightly modified with the same variables and output)*. – user692942 Jul 06 '16 at 09:22