Adding news via REST API
Added by Adur Seminole almost 5 years ago
Can someone provide some (or any) guidance on the XML syntax for news creation via API? Patch #13468. I am new to Redmine. Thanks.
After inspecting the link by Bernhard below, I was able to draft the following code in VBA, but still, I am not able to POST news to my localhost/Redmine.
I wonder what I am doing wrong. My Redmine Install is version 4.1.0.stable.
Example for Creating News
POST /projects/:project_id/news.xml <?xml version="1.0"?> <news> <title>Sample_title</title> <summary>Example</summary> <description>Sample Description</description> </news>
VBA Sample Code
Private Sub News() Dim req As New MSXML2.XMLHTTP60 Dim reqURL As String Dim reqBody As String reqURL = "http://localhost/redmine/projects/_0000067/news.xml" req.Open "POST", reqURL, False req.setRequestHeader "Content-Type", "application/xml" reqBody = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & "encoding=" & Chr(34) & "UTF-8" & Chr(34) & " ?>" reqBody = reqBody & "<news>" reqBody = reqBody & "<title>" & "Test_Title" & "</title>" reqBody = reqBody & "<summary>" & "Test_Summary" & "</summary>" reqBody = reqBody & "<description>" & "Test_Description" & "</description>" reqBody = reqBody & "</news>" req.send (reqBody) End Sub
Replies (3)
RE: Adding News vía Rest Api - Added by Bernhard Rohloff almost 5 years ago
I haven't tried the news API, yet. But one can find good examples in the tests for that part. There you have prototypes for all kinds of requests.
source:trunk/test/integration/api_test/news_test.rb
RE: Adding news via REST API - Added by Leonid Konov over 4 years ago
I have success with adding news
curl -v --header "Content-Type:application/xml;charset=UTF-8" -u "user:pass" --data @xmltest.xml http://host:port/projects/1/news.xml
xmltest.xml:
<news>
<title>NewsXmlApiTest</title>
<summary>News XML-API Test</summary>
<description>This is the description</description>
</news>
Redmine responds 204 No Content, but creates news entry.
RE: Adding news via REST API - Added by Jakob Maležič 12 months ago
In case someone will be searching for json version with API key:
POST https://host:port/projects/1/news.json?key=$API_KEY Content-Type: application/json;charset=UTF-8 { "news": { "title": "Created via Redmine API.", "summary": "This news was created via Redmine API.", "description": "You can create news by sending an HTTP request to Redmine API." } }
Or with curl:
curl -v -H "Content-Type: application/json;charset=UTF-8" --data @redmine.json https://host:port/projects/1/news.json\?key\=$API_KEY redmine.json: { "news": { "title": "Created via Redmine API.", "summary": "This news was created via Redmine API.", "description": "You can create news by sending an HTTP request to Redmine API." } }