Forums Mingle API

Python use of Mingle API#683

Subscribe to Python use of Mingle API 6 post(s), 2 voice(s)

 
Avatar Rudiger Wolf 21 post(s) #1777

Hi

I am having some problems updating a card with the Mingle API. Getting card information out of Mingle API is working. Any suggestions on how I can update card info via API?

This is python code to update that is not working:

import httplib2
import urllib
http = httplib2.Http()

mingle_user = 'user name'
mingle_pass = 'password'

http.add_credentials(mingle_user, mingle_pass)

data = {'card[name]': 'Some_new_name'}
body = urllib.urlencode(data)
print body    # card%5Bname%5D=Some_new_name

#note that database id=1617  for card #634
response, content = http.request('http://10.40.30.23:8080/projects/project/cards/1617.xml', method="POST", body=body)

print response
print content

The error I get is

Either the resource you requested does not exist or you do not have access rights to that resource

I do have rights, I think, as I able to get info from Mingle via the following code.

import httplib2
from module_xml import xml2obj

http = httplib2.Http()

mingle_user = 'user name'
mingle_pass = 'password'

http.add_credentials(mingle_user, mingle_pass)

response, content = http.request('http://10.40.30.23:8080/projects/project/cards/634.xml')
print response
print content

mingle_card = xml2obj(content) #function to converts XML data into native Python object
print mingle_card.id  # <id type="integer">1617</id>

Any Suggestions?

Regards
Rudi

 
Avatar Rudiger Wolf 21 post(s) #1778

I found that changing method=”PUT” got me past resource you requested does not exist error.

The http://studios.thoughtworks.com/mingle/2.0.1/help/mingle_api.html says that either a POST or PUT can be used to update content.

Now I have a problem where the only change that happens when I run the script to update card fields is a new updated_at value.
<updated_at type="datetime">2008-06-25T11:44:20Z</updated_at>

But the fields such as name have not actually been updated.

Any thoughts?
Thanks Rudi

 
Avatar Rudiger Wolf 21 post(s) #1786

I got something working eventually.

import httplib
import urllib
import base64

mingle_username = 'user name'
mingle_password = 'password'
base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
authheader =  "Basic %s" % base64string
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain","Authorization": authheader}

#What is it that we want to change? Note use the same card property names that are returned via the HTTP GET module.
params = urllib.urlencode({'card[cp_sprint_number]':'8','card[name]': 'Test Name','card[cp_target_release_number]':'RX','card[cp_sprint_development_complete]':'3'})  
print params

# Now connect to the webserver and get data updated
conn = httplib.HTTPConnection("10.40.30.23:8080")  # ID = 1617.xml and Card number = 634.xml
conn.request("PUT", "/projects/project/cards/1617.xml", params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
print data
conn.close()

Hope this helps someone.

-Rudiger Wolf

 
Avatar LiXiao Administrator 21 post(s) #1875

Hi rnwolf,

The updated_at is a read-only attribute, so you can’t update it and it would be updated automatically every time you updated the card.

 
Avatar Rudiger Wolf 21 post(s) #1888

Hi

I am having some problems getting information from Mingle via API for filtered card set. Would you be able to suggest how I can apply filters to the GET query?

Adding encoded parameters to the URL does not seem to work. I am using Python 2.5 on Windows XP.


import httplib2
from urllib import urlencode

http = httplib2.Http()

mingle_user = 'user'
mingle_pass = 'password'

http.add_credentials(mingle_user, mingle_pass)

uri = 'http://10.40.30.3:8080/projects/columbus3/cards.xml'
params = {'filter[]':'[Type][is][story]'}
url = uri    + '&' + urlencode(params)
print url

response, content = http.request(url,'GET')

print response
print content

When I add parameters to the url I get a ‘status’: ‘406’ error.
If I leave off paramters then I get an xml file with a limited list of all cards.

Please help me get a filtered card set back from Mingle via API.

Thanks
Rudi

 
Avatar LiXiao Administrator 21 post(s) #1941

Hi Rudi,

The param name you specified for filters is wrong, it should be “filters[]”.
And you should not encode all params.
If some param value need to be encoded, you should only encode the param value,

for example:
filters[]=[Type][is][#{urlencode('xxx&xx')}]

Forums Mingle API