OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Azure DevOps Rest API - Creating Iteration don't work

  • Thread starter Thread starter askldq
  • Start date Start date
A

askldq

Guest
First I call all iterations that I have in my project - and it works fine and then I want to create a new one via the API. , but the method doesn't work, I get the error:

The remote server returned an error: (400) Invalid request.

Is there an issue with this not really working properly or am I doing something wrong?

Code:
# *the Powershell code:*

# Variables
$organization = "x"
$project = "y"
$pat = "z"

$baseUrl = "https://dev.azure.com/$organization/$project/_apis/work/teamsettings/iterations?api-version=6.0"

# authentication
$headers = @{
    Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
}

# HTTP GET
$response = Invoke-RestMethod -Uri $baseUrl -Method Get -Headers $headers

# list iterations
$response.value | ForEach-Object {
    Write-Output "Iteration Name: $($_.name)"
    Write-Output "Start Date: $($_.attributes.startDate)"
    Write-Output "End Date: $($_.attributes.finishDate)"
    Write-Output "Path: $($_.path)"
    Write-Output "----------------------------------"
}

# data for new iteration
$body = @{
    name = "blabla"
    attributes = @{
        startDate = (Get-Date).AddDays(1).ToString("yyyy-MM-ddTHH:mm:ssZ")
        finishDate = (Get-Date).AddDays(14).ToString("yyyy-MM-ddTHH:mm:ssZ")
    }
} | ConvertTo-Json 

# HTTP POST
function Add-Iteration {
    param (
        [string]$url,
        [hashtable]$headers,
        [string]$body
    )
    try {
        $response = Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body $body
        Write-Output "Iteration successfully added:"
        Write-Output $response
    }
    catch {
        Write-Output "Error adding iteration:"
        Write-Output $_.Exception.Message
    }
}

# add iteration
Add-Iteration -url $baseUrl -headers $headers -body $iterationData
<p>First I call all iterations that I have in my project - and it works fine and then I want to create a new one via the API. , but the method doesn't work, I get the error:</p>
<blockquote>
<p>The remote server returned an error: <strong>(400) Invalid request</strong>.</p>
</blockquote>
<p>Is there an issue with this not really working properly or am I doing something wrong?</p>
<pre><code># *the Powershell code:*

# Variables
$organization = "x"
$project = "y"
$pat = "z"

$baseUrl = "https://dev.azure.com/$organization/$project/_apis/work/teamsettings/iterations?api-version=6.0"

# authentication
$headers = @{
Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
}

# HTTP GET
$response = Invoke-RestMethod -Uri $baseUrl -Method Get -Headers $headers

# list iterations
$response.value | ForEach-Object {
Write-Output "Iteration Name: $($_.name)"
Write-Output "Start Date: $($_.attributes.startDate)"
Write-Output "End Date: $($_.attributes.finishDate)"
Write-Output "Path: $($_.path)"
Write-Output "----------------------------------"
}

# data for new iteration
$body = @{
name = "blabla"
attributes = @{
startDate = (Get-Date).AddDays(1).ToString("yyyy-MM-ddTHH:mm:ssZ")
finishDate = (Get-Date).AddDays(14).ToString("yyyy-MM-ddTHH:mm:ssZ")
}
} | ConvertTo-Json

# HTTP POST
function Add-Iteration {
param (
[string]$url,
[hashtable]$headers,
[string]$body
)
try {
$response = Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body $body
Write-Output "Iteration successfully added:"
Write-Output $response
}
catch {
Write-Output "Error adding iteration:"
Write-Output $_.Exception.Message
}
}

# add iteration
Add-Iteration -url $baseUrl -headers $headers -body $iterationData
</code></pre>
Continue reading...
 

Latest posts

L
Replies
0
Views
1
lagnaoui jihane
L
E
Replies
0
Views
1
Eduard Dubilyer
E
Top