Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How can I update a work item VIA api?

 I am trying to update the tags field, removing one tag and adding another. I followed the instructions on this wiki

had no luck i am getting response: 400.

code:
print(self._req.headers)
URL= self._url+'oslc/workitems/' + str(workitem_id) + '?oslc.properties=dc:subject' 

request headers
{'User-Agent': 'python-requests/2.20.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'text/json', 'Connection': 'keep-alive', 'Content-Type': 'application/json; charset=utf-8', 'If-Match': '"987654331-1234-1234-1234-123456789"'}

Do you guys have a working python example of updating a work item VIA api

0 votes



One answer

Permanent link
Did you do authentication step first? The first time you need to authenticate, then you can do GET, from that you can obtain the E-Tag to put in If-Match from the headers and then use that in the PUT.

I'm afraid I don't have a python example. If you can use curl, there are some useful examples.




The below doesn't do partial updates, but it might be easier to get something working which updates the whole work item first.

#First I run this script to authenticate

URL=https://servername:9443/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/1

COOKIES=./cookies.txt

USER=xxxx
PASSWORD=yyyy
HOST="https://servername:9443/ccm"

curl -k -c $COOKIES "$HOST/authenticated/identity"

curl -k -L -b $COOKIES -c $COOKIES -d j_username=$USER -d j_password=$PASSWORD "$HOST/authenticated/j_security_check"

#Then do a GET to obtain the work item in xml (or json)
curl -D - -k -b cookies.txt -o "wi1.xml" -H "Content-Type: application/rdf+xml" -H "Accept: application/rdf+xml " -H "OSLC-Core-Version: 2.0" $URL

#Because I put -D - it will output headers to standard output.. and this gives me the E-Tag value

/1.1 200 OK
X-Powered-By: Servlet/3.0
x-com-ibm-team-scenario: 9.192.137.58
ETag: "c89b2e49-1a4c-3dcf-94d1-34738d80997d"
Last-Modified: Fri, 21 Sep 2018 05:04:53 GMT
Cache-Control: private, max-age=0, must-revalidate
Expires: Wed, 07 Nov 2018 06:57:37 GMT
OSLC-Core-Version: 2.0
Vary: Accept, OSLC-Core-Version
Content-Type: application/rdf+xml;charset=UTF-8
Content-Language: en-US
Transfer-Encoding: chunked
Date: Wed, 07 Nov 2018 06:57:37 GMT

#Then I update the wi1.xml to add tags
    <dcterms:subject rdf:datatype="http://www.w3.org/2001/XMLSchema#string">install, idea, test, warehouse</dcterms:subject>

#Then I update the actual work item using the E-Tag value obtained in the GET

curl -D - -k -b cookies.txt -H "If-Match:c89b2e49-1a4c-3dcf-94d1-34738d80997d" -H "Content-Type: application/rdf+xml" -H "Accept: application/rdf+xml " -H "OSLC-Core-Version: 2.0" -X PUT --data-binary @wi1.xml $URL

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 61

Question asked: Nov 02 '18, 3:18 p.m.

Question was seen: 1,558 times

Last updated: Nov 07 '18, 9:16 p.m.

Confirmation Cancel Confirm