2

I need to convert the following command from bash curl to powershell syntax:

curl -s --head --header "PRIVATE-TOKEN:XXXXXX" "https://gitlab.XXXXXX/api/v4/projects/${id}/issues?state=all&per_pages=100"

This one in particular to get value of X-Total-Page from results.

I've tried to convert with this, but doesn't works:

function getPageNumbers ($myId)
    {

        $privateToken = "myToken" 

        $headers = @{"PRIVATE-TOKEN"="$privateToken"}

        $url = "https://gitlab.XXXXXX/api/v4/projects/$myId/issues?state=all&per_pages=100"

        $result = Invoke-RestMethod -Method Head -Uri "$url" -Header $headers  -ContentType "text/json" 


        return $result
    }

maybe because the "Head" method is used only for Invoke-Webrequest ?

Any suggestions?

Thank you in advance!

2
  • what about Invoke-webrequest? Commented Mar 6, 2018 at 12:39
  • ok I'll try to move on Invoke-webRequest Commented Mar 6, 2018 at 15:33

1 Answer 1

2

I am not seeing the body. But you can add that. You can do something like this:

$privateToken = "myToken" 
$headers = @{"PRIVATE-TOKEN"="$privateToken"}

Invoke-WebRequest -Uri "https://gitlab.XXXXXX/api/v4/projects/$myId/issues?state=all&per_pages=100" -ContentType "application/json" -Headers $headers -Method Post

I would also suggest you to go through the CURL to Invoke-WebRequest

Hope it helps.

Sign up to request clarification or add additional context in comments.

7 Comments

I tried this: $R= Invoke-WebRequest -Uri $url -Headers $headers -ContentType "application/json" -Method Get -UseBasicParsing and with $R.Content I can see the whole text but I'm now trying to parse it ...
you can convert that to json using $R.Content | Convertto-Json -Depth 3. You can handle the parsing part in multiple ways. But atleast your curl got converted to Invoke-webrequest now
yes I found it, but this is the right one that I need $x = $R.Content | Out-String | ConvertFrom-Json
@ClaudioM: That makes better sense if the content is already in json;)
why do you suggest Invoke-WebRequest over Invoke-RestMethod
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.