Project

General

Profile

anyone can give me an example how to create version by rest api with json?

Added by Steven Wong about 7 years ago

How to create version by rest api with json?

I tried as what the wiki said, but failed.
http://www.redmine.org/projects/redmine/wiki/Rest_Versions#POST

anyone could give me an example? Thanks so much.


Replies (3)

RE: anyone can give me an example how to create version by rest api with json? - Added by Seung Soo Mun over 6 years ago

Working syntax for Issues

Invoke-RestMethod -Headers @{ 'X-Redmine-API-Key'='0123456789abcdef0123456789abcdef01234567'} -ContentType 'application/xml' -Method GET -URI http://redmine.domain/issues/12345.xml
Invoke-RestMethod -Headers @{ 'X-Redmine-API-Key'='0123456789abcdef0123456789abcdef01234567'} -ContentType 'application/xml' -Method PUT -URI http://redmine.domain/issues/12345.xml -Body '<issue><notes>Add comment to the issue</notes></issue>'

However, it seems that Versions only accepts GET method for now

Invoke-RestMethod -Headers @{ 'X-Redmine-API-Key'='0123456789abcdef0123456789abcdef01234567'} -ContentType 'application/xml' -Method GET -URI http://redmine.domain/versions/123.xml

I guess the correct syntax for POST and PUT methods would be something like this

Invoke-RestMethod -Headers @{ 'X-Redmine-API-Key'='0123456789abcdef0123456789abcdef01234567'} -ContentType 'application/xml' -Method POST -URI http://redmine.domain/projects/testprj/versions.xml -Body '<version><project id="1" name="testprj" /><name>Test version</name></version>'
Invoke-RestMethod -Headers @{ 'X-Redmine-API-Key'='0123456789abcdef0123456789abcdef01234567'} -ContentType 'application/xml' -Method PUT -URI http://redmine.domain/versions/123.xml -Body '<version><project id="1" name="testprj" /><name>Test</name></version>'

Wiki page Rest_api shows the status of each resource

RE: anyone can give me an example how to create version by rest api with json? - Added by Mayama Takeshi over 6 years ago

Here is an example with curl:

takeshi@takeshi-desktop:~$ curl --silent -x '' -u ccea1c56b61c91be1f5db7faffe76f950eadf656:fake http://192.168.1.1/projects/1/versions.json -X POST -H 'Content-Type: application/json' -d '{"version": {"name": "some_version", "description": "bla bla bla"}}' | jq .
{
  "version": {
    "updated_on": "2017-12-22T00:34:17Z",
    "created_on": "2017-12-22T00:34:17Z",
    "sharing": "none",
    "status": "open",
    "description": "bla bla bla",
    "name": "some_version",
    "project": {
      "name": "sales",
      "id": 1
    },
    "id": 2
  }
}

RE: anyone can give me an example how to create version by rest api with json? - Added by Seung Soo Mun over 6 years ago

Below test worked just fine with Redmine 3.3.1.stable from Powershell / Windows 10 Pro 1607

Invoke-RestMethod -Headers @{ 'X-Redmine-API-Key'='0123456789abcdef0123456789abcdef01234567'} -Method POST -ContentType 'application/json' -URI http://redmine.domain/projects/testprj/versions.json -Body '{"version": {"name": "Test ver", "description": "did it work?"}}'

The syntax was correct. The problem was the permission.
Since we enabled LDAP authentication, only the valid user could POST or PUT.

    (1-3/3)