Using curl to deploy/post/get requests on Microservice APIs

I am looking for a solution where I can use curl commands in a powershell script to execute api (GET/POST) for deploying json formatted data to another API and I want to use this script in jenkins pipeline to automate deployment.

One of the requirement is to generate a Authentication Bearer token using curl on our custom authentication service and subsequently use that token to run other APIs.

Currently I am using a batch script, I am exporting the auth token in a temp file and passing the content of that file in a variable referenced in Authentication header to run the API successfully. Since the batch’s “set /p token=< temp.txt” is limited to reading 1021 characters from file, the api requests are failing with 401 errors.

Is there a similar limitation with powershell too? Since the auth token generated is has more than 10k characters in single line.

Please advice/suggest a solution to accomplish this use case in Windows OS.

Thanks in advance.

@vpillai Welcome to PowerShell.org forums.

When you use PowerShell, you should be using Invoke-Restmethod instead of curl and AFAIK there is no limitation to the token length with Invoke-Command

See Invoke-RestMethod (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Docs

@kvprasoon Thanks for the welcome message.

Sure I will use invoke command for this task. Thanks again.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.