You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PowerShell 5中调用IBM Urbancode AddVersionStatus的PUT API?

Using PowerShell 5 to Call IBM Urbancode AddVersionStatus PUT API

Here's a practical, step-by-step guide to invoking the AddVersionStatus API endpoint with PowerShell 5:

Prerequisites

  • PowerShell 5.x installed and accessible
  • Access to your IBM Urbancode Deploy server with permissions to modify version statuses
  • Knowledge of required API parameters (from official docs):
    • application: Name or ID of the target application
    • version: Name or ID of the application version to update
    • status: Name of the status to add to the version
    • Optional: statusDescription for additional context

Step 1: Set Up Basic Authentication

Urbancode Deploy relies on Basic Auth for API access. Convert your credentials to a base64-encoded string for the request header:

$username = "your-urbancode-username"
$password = "your-urbancode-password"
$base64Auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))

Step 2: Define API Details & Request Body

Configure your server URL and build the JSON request body with your target parameters:

# Base URL for your Urbancode instance (adjust port/protocol as needed)
$serverUrl = "https://your-urbancode-server.com:8443"
# API endpoint path
$apiPath = "/cli/version/addStatus"
# Full request URI
$uri = $serverUrl + $apiPath

# Build the request body (customize these values to match your use case)
$requestBody = @{
    application = "MyECommerceApp"
    version = "2.3.1"
    status = "Production-Ready"
    statusDescription = "Passed all UAT tests; approved for production deployment"
} | ConvertTo-Json

Step 3: Send the PUT Request

Use Invoke-RestMethod to execute the API call, with error handling to catch issues like invalid parameters or permission errors:

try {
    $apiResponse = Invoke-RestMethod -Uri $uri `
                                     -Method Put `
                                     -Headers @{Authorization=("Basic {0}" -f $base64Auth)} `
                                     -Body $requestBody `
                                     -ContentType "application/json"
    
    Write-Host "API call succeeded! Response:"
    $apiResponse | ConvertTo-Json -Depth 10
} catch {
    Write-Host "API call failed:"
    Write-Host "Status Code: $($_.Exception.Response.StatusCode.value__)"
    Write-Host "Error Message: $($_.Exception.Message)"
    
    # Print detailed error content if available
    if ($_.ErrorDetails.Message) {
        $errorDetails = $_.ErrorDetails.Message | ConvertFrom-Json
        Write-Host "Detailed Error:"
        $errorDetails | ConvertTo-Json -Depth 10
    }
}

Key Tips

  • SSL/TLS Handling: If your server uses a self-signed certificate, you may need to bypass SSL validation (not recommended for production):
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    Add-Type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
    "@
    [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
    
  • Use IDs for Clarity: If you have duplicate application/version names, using their unique IDs instead of names avoids ambiguity.
  • Parameter Validation: Double-check that all required fields are included—missing values will trigger API errors.

内容的提问来源于stack exchange,提问作者knowdotnet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:35:47