Project

General

Profile

Actions

Defect #29777

closed

can't create issue relation by rest API

Added by jiamin wu over 5 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
REST API
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
No feedback
Affected version:

Description

Hello everyone,

I tried to create issue relation via the REST API by Powershell.
It always returned same error "422 Unprocessable Entity"
What am I doing wrong?

Here is the software version

*Redmine 3.2
*Powershell 2.0(for programming)
*MySql

Here is my code.

try{
    $httpWebRequest = [System.Net.HttpWebRequest]::Create("http://abcdef/redmine/issues/1234/relations.xml?key=1fa2s1f21df5ef2a1dfas")
    $httpWebRequest.Method = "POST" 
    $httpWebRequest.ContentType = "application/xml" 

    $xmlStr = "<?xml version=""1.0"" encoding=""UTF-8""?><relation><issue_to_id>5678</issue_to_id><relation_type>""relates""</relation_type></relation>" 
    $rmFields = [Xml]$xmlStr
    $rmFields.PreserveWhiteSpace = $true
    $content = $rmFields.OuterXML

    # Add content
    $encodedContent = [System.Text.Encoding]::UTF8.GetBytes($content)
    $httpWebRequest.ContentLength = $encodedContent.length
    $requestStream = $httpWebRequest.GetRequestStream()
    $requestStream.Write($encodedContent, 0, $encodedContent.length)
    $requestStream.Close()

    # Send
    $response = [System.Net.HttpWebResponse]$httpWebRequest.GetResponse()
    $responseStream = [System.IO.Stream]$response.GetResponseStream()
    $readStream = New-Object System.IO.StreamReader($responseStream)
    $responseData = $readStream.ReadToEnd()

    return 0
}catch{
   write-host $_.Exception.Message
   return 2
}

XML Output

<relation>
  <issue_to_id>5678</issue_to_id>
  <relation_type>"relates"</relation_type>
</relation>

Thanks & best regards,

Actions #1

Updated by Go MAEDA over 5 years ago

  • Status changed from New to Needs feedback

You may be able to find reasons in production.log. Could you check the log?

Actions #2

Updated by Go MAEDA about 5 years ago

  • Status changed from Needs feedback to Closed
  • Resolution set to No feedback
Actions

Also available in: Atom PDF