Id must be numeric

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
bicewer602
Posts: 1
Joined: 25 Jan 2020, 13:21

Id must be numeric

Post by bicewer602 »

Hi,
i am trying to automate some work on mantis, but for some reason api refuses to accept id(int/string). What am I doing here wrong?

Code: Select all

$ItsmHost = 'xxxxxxxxxxxxx'
$TechKey = "xxxxxxxxxxxxxxx"

$RequestListByFilter =
@{
"uri"= $ItsmHost
"Authorization"= $TechKey
}

$Header =
@{
"Authorization" = $TechKey
"ContentType" = "Content-Type: application/json"
}

$CreateNote=@"
{
"text": "Przejeto",
"view_state": {
"name": "public"
}
}
"@

$url = $ItsmHost

$GET_REQUESTS_PARAMS = @{OPERATION_NAME='ISSUES';INPUT_DATA=$RequestListByFilter;format = "json"}
    $GET_REQUESTS_RESPONSE =  Invoke-RestMethod -Uri $url -Method GET -Body $GET_REQUESTS_PARAMS -Headers $RequestListByFilter
    $IssueID = $GET_REQUESTS_RESPONSE.issues.id

##$NoteHost = 'xxxxxxxxxxxxxxxxx/api/rest/issues/:' + $IssueID + '/notes'

function CreateNote
{
Param ([int]$ID)
$NoteHost = 'xxxxxxxxxxxx/api/rest/issues/' + $id + '/notes'
$CreateNoteParams = @{OPERATION_NAME='MESSAGE';INPUT_DATA=$CreateNote;format = "json"}
$CreateNote = Invoke-RestMethod -uri $NoteHost -Method POST -Body $CreateNoteParams -Headers $Header

}

foreach ($element in $IssueID) {
CreateNote($element)
}
Error

Code: Select all

Error:
Invoke-RestMethod : {"message":"'issue_id' must be numeric","code":29,"localized":"Nieprawid\u0142owa warto\u015b\u0107 dla 'issue_id'"}
At line:44 char:23

    ... reateNote = Invoke-RestMethod -uri $NoteHost -Method POST -Body $Crea ...


    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
    Invoke-RestMethod : {"message":"'issue_id' must be numeric","code":29,"localized":"Nieprawid\u0142owa warto\u015b\u0107 dla 'issue_id'"}
    At line:44 char:23

    ... reateNote = Invoke-RestMethod -uri $NoteHost -Method POST -Body $Crea ...


    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Post Reply