0

I am using a batch file to run a cURL command that uses a dynamically created json file as the payload. I am looping through each file in a directory, and setting the filename variable, and using that for the resp variable. However it seems that it's iterating for each file, but not resetting the filename and resp values. See Script Below

@echo on
for %%f in ("C:\po_responses\*.json") do (
    set filename=@%%f
    set resp=%%~nf_response.json
    curl -g -H "Authorization:Bearer Token"  -H "content-type:application/json" -H "accept:application/json" -X POST -d "%filename%" https://api.clientsite.com/ -o "%resp%"
) 
AlliDeacon
  • 1,365
  • 3
  • 21
  • 35
  • In your instance there is no need to create those two environmental variables. Just use the `FOR` variable directly with your curl command. That way you don't have to deal with delayed expansion which is explained in the duplicate question I linked to. – Squashman Nov 05 '18 at 18:24
  • Also you must put `@` in front of the filename if you want its contents to be posted: `-d @c:\po_responses\request1.json -o c:\po_responses\request1_response.json` – Stavr00 Nov 05 '18 at 18:28
  • Also note, if you run this batch, it will attempt to post the responses back as well, creating a kind of infinite loop. – Stavr00 Nov 05 '18 at 18:30
  • Perfect, thank you so much for the help and the guidance – AlliDeacon Nov 05 '18 at 19:04

0 Answers0