filling custom fields via soap api

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
alan
Posts: 3
Joined: 07 Nov 2012, 11:44

filling custom fields via soap api

Post by alan »

Hello

Im trying to add issues via soap api but it looks like im either doing something wrong (plausible, i have to admit, since its my first time ever using soap or mantis), or there is a bug.
Ill add way to reproduce what im doing so you can confirm if im stupid or there is a bug.

I am using python soap client called suds which everybody could download here (https://fedorahosted.org/releases/s/u/s ... 4.1.tar.gz)

If you have downloaded it and unpacked do something like this in (linux) shell:

python #opens python shell

in python shell:

Code: Select all

import sys
sys.path.append('/path/to/unpacked/python-suds-0.4.1')
user = 'youusername'
pwd = 'yourpassword'
wdsl = 'http://domain/mantisbt/api/soap/mantisconnect.php?wsdl'
from suds.client import Client #if this lane raises error, then the path you used to append to pythonpath was wrong.
client = Client(wdsl)
result = client.service.mc_version() # for me this is 1.2.10. I also tested it with 1.3-dev - got same results
issue = client.factory.create('IssueData')
project = client.factory.create('ObjectRef')
project.id = 19
project.name = "your project name"
issue = client.factory.create('IssueData')
issue.project = project
reporter = client.factory.create('AccountData')
reporter.name = 'name'
reporter.real_name = 'random text'
reporter.email = 'you@domain.com'
issue.reporter = reporter
issue.summary = 'test test test'
issue.description = u'just testing'
issue.category = 'Bug'
customfields = client.factory.create('CustomFieldValueForIssueDataArray')
client_field = client.factory.create('ObjectRef')
contact_field = client.factory.create('ObjectRef')
client_field.id = 1
client_field.name = 'Client'
contact_field.id = 4
contact_field.name = 'Contact'
contact_data = client.factory.create('CustomFieldValueForIssueData')
contact_data.field = contact_field
contact_data.value = 'random@domain.com'
client_data = client.factory.create('CustomFieldValueForIssueData')
client_data.field = client_field
client_data.value = 'something'
customfields.items = [client_data, contact_data]
issue.custom_fields = customfields
client.service.mc_issue_add(user, pwd, issue)

then i get error from php side:
WebFault: Server raised fault: 'Error Type: SYSTEM NOTICE,
Error Description:
Undefined index:  field,
Stack Trace:
mc_issue_api.php L663 mci_issue_set_custom_fields(<string>'1992', <Array> { ['items'] => <Array> { [0] => <Array> { ['field'] => <Array> { ['id'] => 4, ['name'] => 'Contact' }, ['value'] => 'random@domain.com' }, [1] => <Array> { ['field'] => <Array> { ['id'] => 1, ['name'] => 'Client' }, ['value'] => 'Testing' } } }, <boolean>false)
UnknownFile L? mc_issue_add(<string>'yoursername', <string>'yourpassword', <Array> { ['project'] => <Array> { ['id'] => 19, ['name'] => 'yourproject' }, ['category'] => 'Support', ['reporter'] => <Array> { ['name'] => 'test-from-web', ['real_name'] => 'yoursername tests adding use via soap', ['email'] => 'random@domain.com' }, ['summary'] => 'test test test', ['description'] => 'just testing SOAP api', ['custom_fields'] => <Array> { ['items'] => <Array> { [0] => <Array> { ['field'] => <Array> { ['id'] => 4, ['name'] => 'Contact' }, ['value'] => 'random@domain.com' }, [1] => <Array> { ['field'] => <Array> { ['id'] => 1, ['name'] => 'Client' }, ['value'] => 'Testing' } } } })
nusoap.php L4087 call_user_func_array(<string>'mc_issue_add', <Array> { [0] => 'yoursername', [1] => 'yourpassword', [2] => <Array> { ['project'] => <Array> { ['id'] => 19, ['name'] => 'yourproject' }, ['category'] => 'Support', ['reporter'] => <Array> { ['name'] => 'test-from-web', ['real_name'] => 'yoursername tests adding use via soap', ['email'] => 'random@domain.com' }, ['summary'] => 'test test test', ['description'] => 'just testing SOAP api', ['custom_fields'] => <Array> { ['items'] => <Array> { [0] => <Array> { ['field'] => <Array> { ['id'] => 4, ['name'] => 'Contact' }, ['value'] => 'random@domain.com' }, [1] => <Array> { ['field'] => <Array> { ['id'] => 1, ['name'] => 'Client' }, ['value'] => 'Testing' } } } } })
nusoap.php L3718 invoke_method()
mantisconnect.php L1717 service(<string>'<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:ns3="http://futureware.biz/mantisconnect" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Header/><ns1:Body><ns3:mc_issue_add><username xsi:type="ns2:string">yoursername</username><password xsi:type="ns2:string">yourpassword</password><issue xsi:type="ns3:IssueData"><project xsi:type="ns3:ObjectRef"><id xsi:type="ns2:integer">19</id><name xsi:type="ns2:string">yourproject</name></project><category xsi:type="ns2:string">Support</category><reporter xsi:type="ns3:AccountData"><name xsi:type="ns2:string">test-from-web</name><real_name xsi:type="ns2:string">yoursername tests adding use via soap</real_name><email xsi:type="ns2:string">random@domain.com</email></reporter><summary xsi:type="ns2:string">test test test</summary><description xsi:type="ns2:string">just testing SOAP api</description><custom_fields xsi:type="ns3:CustomFieldValueForIssueDataArray"><items xsi:type="ns3:CustomFieldValueForIssueData"><field xsi:type="ns3:ObjectRef"><id xsi:type="ns2:integer">4</id><name xsi:type="ns2:string">Contact</name></field><value xsi:type="ns2:string">random@domain.com</value></items><items xsi:type="ns3:CustomFieldValueForIssueData"><field xsi:type="ns3:ObjectRef"><id xsi:type="ns2:integer">1</id><name xsi:type="ns2:string">Client</name></field><value xsi:type="ns2:string">Testing</value></items></custom_fields></issue></ns3:mc_issue_add></ns1:Body></SOAP-ENV:Envelope>')
With version 1.3.dev i got:

WebFault: Server raised fault: 'Error Type: SYSTEM NOTICE,
Error Description: Undefined index: field'


By the way - if i use soap api to post SINGLE custom field like:

Code: Select all

customfields.items = [client_data]
issue.custom_fields = customfields
client.service.mc_issue_add(user, pwd, issue)
Then it works just fine. it adds issue and everything is in place.

If anyone could provide some feedback then i would appreciate it alot.

Thanks,
Alan
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: filling custom fields via soap api

Post by atrol »

Try also to write e-mail to mantisbt-soap-dev mailing list http://www.mantisbt.org/mailinglists.php
Please use Search before posting and read the Manual
alan
Posts: 3
Joined: 07 Nov 2012, 11:44

Re: filling custom fields via soap api

Post by alan »

Hi and thanks for your suggestion. I have to ask though - is def mailinglist the best place for such question. Such question seems to be out of topic there as most of the talk revolves versions and development priorities...

I could just file this as bugreport instead. What was my goal was to understand if im stupid or this is a bug. If i get no such answer here then i would rather file it as bug and then if its not a bug it will be rejected and ill get my answer from there :D

Alan
rombert
Posts: 66
Joined: 05 Nov 2009, 08:43

Re: filling custom fields via soap api

Post by rombert »

Hi Alan,

First of all we welcome posts like yours on the mantisbt-soap-dev mailing list ; it's not only for the MantisBT developers working on the SOAP API. I wouldn't open a mailing list just for myself :-)

Second of all, can you paste the xml snippet that your script generates ( minus username/password, of course) ?

Thanks,

Robert
alan
Posts: 3
Joined: 07 Nov 2012, 11:44

Re: filling custom fields via soap api

Post by alan »

Hi!

Hmmm hmm hmm. Since the suds script that i use there is not created by me im not sure what you mean. but i will find out. In the end of the code that i posted there is bunch of xml that mantisconnect.php recieved - is that not enough:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://futureware.biz/mantisconnect" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header/>
<ns1:Body>
	<ns3:mc_issue_add>
		<username xsi:type="ns2:string">yoursername</username>
		<password xsi:type="ns2:string">yourpassword</password>
		<issue xsi:type="ns3:IssueData">
			<project xsi:type="ns3:ObjectRef">
				<id xsi:type="ns2:integer">19</id>
				<name xsi:type="ns2:string">yourproject</name>
			</project>
		<category xsi:type="ns2:string">Support</category>
		<reporter xsi:type="ns3:AccountData">
			<name xsi:type="ns2:string">test-from-web</name>
			<real_name xsi:type="ns2:string">yoursername tests adding use via soap</real_name>
			<email xsi:type="ns2:string">random@domain.com</email>
		</reporter>
		<summary xsi:type="ns2:string">test test test</summary>
		<description xsi:type="ns2:string">just testing SOAP api</description>
		<custom_fields xsi:type="ns3:CustomFieldValueForIssueDataArray">
			<items xsi:type="ns3:CustomFieldValueForIssueData">
				<field xsi:type="ns3:ObjectRef">
					<id xsi:type="ns2:integer">4</id>
					<name xsi:type="ns2:string">Contact</name>
				</field>
				<value xsi:type="ns2:string">random@domain.com</value>
			</items>
			<items xsi:type="ns3:CustomFieldValueForIssueData">
				<field xsi:type="ns3:ObjectRef">
					<id xsi:type="ns2:integer">1</id>
					<name xsi:type="ns2:string">Client</name>
				</field>
				<value xsi:type="ns2:string">Testing</value>
			</items>
		</custom_fields>
		</issue>
	</ns3:mc_issue_add>
</ns1:Body>
</SOAP-ENV:Envelope>
Thing is - since the php of mantis could parse this xml and create correct arrays of this xml which match this xml's structure (those are also posted in my original post) i dont think this error is related to xml but rather to how php tries to handle the arrays parsed.
rombert
Posts: 66
Joined: 05 Nov 2009, 08:43

Re: filling custom fields via soap api

Post by rombert »

Hi,

I tried to look at the errors that you were getting, and I noticed two things:

1. The stack trace indicates an error - mc_issue_api.php L663 - but that location does not match the access to the 'field' index in the latest code from master.
2. You're running MantisBT 1.3-dev

I verified your code and it works for me using code from the 1.2.x branch. My suggestion would be to try this code on the latest MantisBT stable and see if that works.

BTW, I see that you're passing both ids and names for some fields ( e.g. project.id and project.name ) . That's typically not necessary as MantisBT will try to use first the id and then the name to look up an object.

Cheers,

Robert
iMaysoN
Posts: 3
Joined: 09 Oct 2014, 09:07

Re: filling custom fields via soap api

Post by iMaysoN »

Hi!
I got this problem too.
Error in customfields.items = [var1, var2]
Need - customfields = [var1, var2]

And all will be OK :)
Post Reply