I want to call a Web API from a batch file. I need to send the parameters and get the response received from the API call. I have been trying various solutions, including the CALL, and the START command both of which doesn't produced the desired results.
Asked
Active
Viewed 1.7k times
-1
-
3You could use curl – pavi2410 Aug 03 '18 at 07:14
-
See [the answer](https://stackoverflow.com/questions/49543357/can-i-implement-this-rest-api-call-from-a-bat-file) here – Gerhard Aug 03 '18 at 07:53
-
2You can generate a .VBS or .JS on the fly from the batch file to do the job ! – SachaDee Aug 03 '18 at 11:22
1 Answers
1
SUGGESTION: download a copy of curl (command-line URL):
https://curl.haxx.se/download.html
Here are some notes about how to use it:
https://curl.haxx.se/docs/httpscripting.html
https://community.blackboard.com/thread/4886-using-curl-to-automate

paulsm4
- 114,292
- 17
- 138
- 190
-
great, Thanks a lot. Its just that, I want to embed the ".bat" file inside my ".Net" project that will be executed during the execution of the project. And for curl, I will have to download and install it on every machine that will be running my project. Can we do the same with the built-in commands. I just want to send a simple "Post" request, that will return with a couple of data items. – Murad Khateeb Abbasi Aug 03 '18 at 07:39
-
2There are no built-in commands for this. Batch is meant for local command line work. – SomethingDark Aug 03 '18 at 07:54
-
2@MuradKhateebAbbasi Why wouldn't you just do it with `.NET`? I am pretty sure you should be able to make a web call in `.NET`. I know my VB programmers that work for me did it back when we were still using `VB6`. We are still in the process of rewriting all of our programs to `.NET`. – Squashman Aug 03 '18 at 15:12
-
Q: I just want to send a simple "Post" request, that will return with a couple of data items. A: There are lots of ways to do this. One way is to use curl. Another way is to write a program (for example, a C# or VB.Net program). Heck, you can even use Powershell: https://stackoverflow.com/questions/17325293/invoke-webrequest-post-with-parameters – paulsm4 Aug 04 '18 at 02:18
-
@Squashman Appreciate your response, But I am working on micro-services and I have certain limitations in using .Net as I want certain procedures to be done by only the .bat file. I can't use .Net. Thanks anyways! – Murad Khateeb Abbasi Aug 06 '18 at 12:03
-
@paulsm4 I appreciate it but as I said I have certain limitations in using c#, VB or any other. I could use powershall or the CURL in .bat but for that the CURL should be packaged along with the project in order for the "curl" command to work in .bat file, which I want to avoid considering the little memory inefficiency and complexity. I do have solved it by calling the "powershall" file from a batch file and then invoking the web API from there, from where the response is returned to the .bat file. I just wanted a cleaner, less complex and memory wise efficient way to achieve this. Thanks! – Murad Khateeb Abbasi Aug 06 '18 at 12:07
-
1FORGET BAT FILES!!!!! You don't need a stupid .bat file if you're using Powershell (or, for that matter, if you're using VBS). All three are "built in" to Windows - you can use them directly. – paulsm4 Aug 06 '18 at 15:38