Error While Getting Response from SOAP Webservice [duplicate] - java

This question already has answers here:
Not Getting Correct Response of SOAP Web service Programatically
(2 answers)
Closed 10 years ago.
For Getting the Response from SOAP Webservice i have do the Following as Needed.
SOAPUI Request :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://test.login/">
<soapenv:Header/>
<soapenv:Body>
<test:Login>
<!--Optional:-->
<arg0>best_buyer_editor</arg0>
<!--Optional:-->
<arg1>welcome</arg1>
<!--Optional:-->
<arg2>Mobile</arg2>
</test:Login>
</soapenv:Body>
</soapenv:Envelope>
SOAPUI Response :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:LoginResponse xmlns:ns2="http://test.login/">
<return>{"LoginDetails":{"Result":"Success","UserName":"Best Buyer Editor","token":"M7M5RMQU6","rolelist":["buyer_editor","admin_role"],"parties":[{"partynumber":"BEST","type":"self","sites":[{"companyname":"www.bestmanufacture.com","sitecode":"BESTTXUSA-1","siteaddress":"225 E Industrial Blvd Waco USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYUSA-5","siteaddress":"20 Milburn St Buffalo USA"},{"companyname":"Best Engineers Manufacturing USA Inc","sitecode":"BESTHQ","siteaddress":"8976, Hope vision Lane Simple City USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYUSA-6","siteaddress":"Cedar & Ellicott Sts Batavia USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTTXUSA-2","siteaddress":"9700 Richmond Ave Ste 201 Houston USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTTXUSA-4","siteaddress":"3315 Ashlock Dr Houston USA"},{"companyname":"Best Engineers Manufacturing USA Inc","sitecode":"BESTWH","siteaddress":"1021, Industrial Bolevar San Macros City USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYMEX-10","siteaddress":"271 Madison Ave Ste 1003 New York USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYUSA-8","siteaddress":"271 Madison Ave Ste 1003 New York USA"},{"companyname":"Best Engineers Manufacturing Europe Inc","sitecode":"BESTMO","siteaddress":"789,Future Vision Towers London GBR"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYUSA-7","siteaddress":"1580 Columbia Tpke Ste 5 Castleton On Hudson USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTNYMEX-9","siteaddress":"271 Madison Ave Ste 1003 New York USA"},{"companyname":"www.bestmanufacture.com","sitecode":"BESTTXUSA-3","siteaddress":"2821 Lackland Rd Ste 340 Fort Worth USA"}]},{"partynumber":"DHL","type":"sponsors","sites":[{"companyname":"www.dhl.com","sitecode":"DHLTXUSA-2","siteaddress":"11311 N Central Expy Dallas USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYUSA-7","siteaddress":"150 W 22nd St Fl 5 New York USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYMEX-9","siteaddress":"One Markin Lane Wyoming USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYUSA-6","siteaddress":"12685 State Route 38 Berkshire USA"},{"companyname":"www.dhl.com","sitecode":"DHLTXUSA-4","siteaddress":"2221 Canada Dry St Houston USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYUSA-5","siteaddress":"521 5th Ave Rm 2130 New York USA"},{"companyname":"www.dhl.com","sitecode":"DHLTXUSA-1","siteaddress":"6505 N Houston Rosslyn Rd Houston USA"},{"companyname":"www.dhl.com","sitecode":"DHLTXUSA-3","siteaddress":"9405 N County Road 2000 Lubbock USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYMEX-10","siteaddress":"One Markin Lane Wyoming USA"},{"companyname":"www.dhl.com","sitecode":"DHLNYUSA-8","siteaddress":"One Markin Lane Wyoming USA"}]},{"partynumber":"UPS","type":"sponsors","sites":[{"companyname":"www.ups.com","sitecode":"UPSTXUSA-3","siteaddress":"1455 West Loop S Houston USA"},{"companyname":"www.ups.com","sitecode":"UPSNYUSA-8","siteaddress":"1050 Hook Rd Farmington USA"},{"companyname":"www.ups.com","sitecode":"UPSNYMEX-10","siteaddress":"1050 Hook Rd Farmington USA"},{"companyname":"www.ups.com","sitecode":"UPSNYUSA-7","siteaddress":"1400 Broadway Fl 2 New York USA"},{"companyname":"www.ups.com","sitecode":"UPSTXUSA-4","siteaddress":"14902 Sommermeyer St Ste 100 Houston USA"},{"companyname":"www.ups.com","sitecode":"UPSNYMEX-9","siteaddress":"1050 Hook Rd Farmington USA"},{"companyname":"www.ups.com","sitecode":"UPSNYUSA-6","siteaddress":"101 Cranbrook Ext Tonawanda USA"},{"companyname":"www.ups.com","sitecode":"UPSNYUSA-5","siteaddress":"290 Barrett Hill Rd Mahopac USA"},{"companyname":"www.ups.com","sitecode":"UPSTXUSA-2","siteaddress":"11308 Midmorning Dr Austin USA"},{"companyname":"www.ups.com","sitecode":"UPSTXUSA-1","siteaddress":"3900 Harrisburg Blvd Houston USA"}]},{"partynumber":"HDEPO","type":"sponsors","sites":[{"companyname":"Home Depot USA.","sitecode":"HDEPOWH","siteaddress":"55031 Hdepo WH Road Bossier City USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYUSA-8","siteaddress":"166 Haverford Rd Hicksville USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPOTXUSA-4","siteaddress":"4901 Blaffer St Houston USA"},{"companyname":"Home Depot USA.","sitecode":"HDEPOHQ","siteaddress":"5031 Hdepo HQ Road Bossier City USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYMEX-9","siteaddress":"166 Haverford Rd Hicksville USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYUSA-6","siteaddress":"1790 Broadway Ste 702 New York USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPOTXUSA-3","siteaddress":"2203 Timberloch Pl Ste 252 The Woodlands USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYMEX-10","siteaddress":"166 Haverford Rd Hicksville USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYUSA-5","siteaddress":"1040 Avenue Of The Americas New York USA"},{"companyname":"Home Depot USA.","sitecode":"HDEPOMO","siteaddress":"5031 Hdepo MO Road Bossier City USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPOTXUSA-1","siteaddress":"14603 Chrisman Rd Houston USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPOTXUSA-2","siteaddress":"16103 University Oak San Antonio USA"},{"companyname":"www.homeDepot.com","sitecode":"HDEPONYUSA-7","siteaddress":"392 Pulteney St Corning USA"}]},{"partynumber":"GWILL","type":"sponsors","sites":[{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYMEX-9","siteaddress":"3300 Northern Blvd Fl 2 Long Island City USA"},{"companyname":"GoodWill Supplies and Construction","sitecode":"GWILLHQ","siteaddress":"543, Light Ray Street Wellknown city In"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYMEX-10","siteaddress":"3300 Northern Blvd Fl 2 Long Island City USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYUSA-7","siteaddress":"1800 New Hwy Farmingdale USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYUSA-8","siteaddress":"3300 Northern Blvd Fl 2 Long Island City USA"},{"companyname":"GoodWill Supplies and Construction","sitecode":"GWILLMO","siteaddress":"6789, Engineering Laner Large city GBR"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLTXUSA-2","siteaddress":"945 McKinney St # 237 Houston USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYUSA-6","siteaddress":"580 Broadway Menands USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLTXUSA-3","siteaddress":"6921 Olson Ln Pasadena USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLTXUSA-1","siteaddress":"7075 Ranch Road 2338 Georgetown USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLTXUSA-4","siteaddress":"3839 Dilido Rd Dallas USA"},{"companyname":"www.goodwillconstruct.com","sitecode":"GWILLNYUSA-5","siteaddress":"1 Radisson Plz Ste 803 New Rochelle USA"},{"companyname":"GoodWill Supplies and Construction","sitecode":"GWILLHQ","siteaddress":"543, Light Ray Street Wellknown city USA"},{"companyname":"GoodWill Supplies and Construction","sitecode":"GWILLWH","siteaddress":"2345, Well formed lane Hope in city USA"}]},{"partynumber":"FEDEX","type":"sponsors","sites":[{"companyname":"www.fedex.com","sitecode":"FEDEXTXUSA-2","siteaddress":"400 Langford St Clint USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYUSA-8","siteaddress":"3736 Kellogg Rd Cortland USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXTXUSA-4","siteaddress":"5025 East Business 20 Abilene USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYUSA-5","siteaddress":"637 New Loudon Rd Ste 2 Latham USA"},{"companyname":"Fedex USA.","sitecode":"FEDEXWH","siteaddress":"6754 Fedex WH Road Fedex City USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXTXUSA-1","siteaddress":"4305 N Interstate 35 Denton USA"},{"companyname":"Fedex USA.","sitecode":"FEDEXHQ","siteaddress":"7800 Fedex HQ Road Bossier City USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXTXUSA-3","siteaddress":"14444 Stuebner Airline Rd Houston USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYMEX-10","siteaddress":"3736 Kellogg Rd Cortland USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYUSA-7","siteaddress":"65 Old Indian Rd Milton USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYMEX-9","siteaddress":"3736 Kellogg Rd Cortland USA"},{"companyname":"Fedex USA.","sitecode":"FEDEXMO","siteaddress":"9600 Fedex MO Road Bossier City USA"},{"companyname":"www.fedex.com","sitecode":"FEDEXNYUSA-6","siteaddress":"1254 Erie Ave North Tonawanda USA"}]}]}}</return>
</ns2:LoginResponse>
</soap:Body>
</soap:Envelope>
MY Code :
URL = "http://test.tpsynergy.com:8080/tpsynergy/services/login";
SOAP_ACTION = "http://test.tpsynergy.com:8080/tpsynergy/services/login";
METHOD = "Login";
NAMESPACE = "http://test.login/";
SoapObject request = new SoapObject(NAMESPACE, "Login");
request.addProperty("arg0", "best_buyer_editor");
request.addProperty("arg1", "welcome");
request.addProperty("arg2", "Mobile");
Log.i(TAG, "Request for getting airport list" + request.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
if (envelope.bodyIn instanceof SoapFault) {
String str= ((SoapFault) envelope.bodyIn).faultstring;
Log.i("", str);
} else {
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
response = resultsRequestSOAP.getProperty(0).toString();
Log.i(" Login Webservice Response", "Responce ---->"
+ (resultsRequestSOAP.getProperty(0).toString()));
}
} catch (Exception e) {
Log.i(TAG, "Exception e" + e.toString());
}
After Executing the above code i am getting Following Error:
Unmarshalling Error: unexpected element (uri:"http://test.login/", local:"arg0"). Expected elements are <{}arg2>,<{}arg1>,<{}arg0>
Can Anyone Tell me why i am getting Success in SOAPUI bt not through my code.
I have referred many SO link but not able to solve my Problem.
What My Question : I really Do not understand Know what the Error is Trying to say by Expected elements are <{}arg2>,<{}arg1>,<{}arg0>. What is the Solution to Get out of this Problem?
Thanks in Advance.

Use TCP monitor to check what is the SOAP request that is sent. I suspect based on error message, the elements arg* are qualified with the namespace where as the webservice does not expect them that way.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://test.login/">
<soapenv:Header/>
<soapenv:Body>
<test:Login>
<!--Optional:-->
<test:arg0>best_buyer_editor</test:arg0>
<!--Optional:-->
<test:arg1>welcome</test:arg1>
<!--Optional:-->
<test:arg2>Mobile</test:arg2>
</test:Login>
</soapenv:Body>
</soapenv:Envelope>

Related

How to search inside an String array for Names using created database

Total noob here.
I just started learning java and would like to create a program so my teacher does not need to count everyone just to figure out who is missing.
For this, I would need input data.
We use teams to learn java so the people who are attending could write something in chat so the teacher can copy/paste this as input data for my program.
This is what I already have:
String names = "Tupac Shakur,Randy Bobandy,Michael Scott,Randy Marsh,Leslie Knope,you mum gey,no u";
String[] arr = names.split(",");
System.out.println("Bot NaniPoonani: Who is here Tool v1 ");
System.out.println("Bot NaniPoonani: Copy/paste the chat data here: ");
Scanner inputNames = new Scanner(System.in);
String ScanNames = inputNamen.next();
String[] FilterdInputNames = ScanNamen.split(Arrays.toString(arr));
String[] FilterdNames = names.split(",");
for (String ss : arr);
System.out.println(" ");
System.out.println(" ");
System.out.println(" ");
System.out.println(" ");
System.out.println(Arrays.toString(FilterdInputNames));
}
This code did not work how I expected and I'm kinda blocked.
The second problem is the chat input is filled with not need data, here is an example:
> [Yesterday 4:44 PM] Tupac Shakur
Ja Patrick..
​[Yesterday 4:45 PM] James Bond
cya
​[Yesterday 4:45 PM] Nikola Tesla
laters
​[Yesterday 4:45 PM] Pewdie Pie
ok
​[Yesterday 4:45 PM] Huge Anus
Bedankt, MabOI!
​[Yesterday 4:45 PM] Humong Gus
Dank u wel !! (smile)
​[Yesterday 4:45 PM] Boby Lee
Tot morgen
​[Yesterday 4:45 PM] Mister Lahey
tot donderdag
<https://teams.microsoft.com/l/message/19:10fe21fc866846639f2e669602bbb1b5#thread.tacv2/1617115470132?tenantId=73c18a3-ce77-4292-94ad-b1ce04645b22&parentMessageId=1617089369488&teeatedTime=1617115470132>
> Blockquote
My first thought was that I could use .split to fill an array with each name using the not needed data
[Yesterday 4:44 PM] Tupac Shakur (enter or /n )
something like this: String[] FilterdInputNames = ScanNamen.split("M]" + "/n");
But clearly, that's not how slipt works.
All advice is welcome since I am not even sure if I need to filter the not needed data.
Thank you in advance

RestAssured - How to read an array element from the json response

#Test
public void getFirstRequestVerifyResponse()
{
String idToValidate= "5ea6fe53e4b09a8de7aeb19d";
System.out.println("Response :" + response.asString());
System.out.println("id : " + response.asString().contains(idToValidate));
}
I am getting the following response.
Response :[{"id":"5ea6fe53e4b09a8de7aeb19d","contents":[{"pageSize":6,"source":"BE","packageId":"ATV_PACKAGE_1538998610009"}],"name":"FEATURE BANNER","format":{"lsTy":"DEFAULT","showAll":false,"autoCarousel":false,"ty":"BANNER","action":{"source":"BE","contentId":"ATV_PACKAGE_1538998610009","t":"Play","st":"PLAY"},"contentAction":{"meta":{}}}},{"id":"5ac37644e4b03f23a4a705dc","contents":[],"name":"MastheadAd","format":{"lsTy":"DEFAULT","ty":"NATIVE_MASTHEAD_AD","action":{"source":"BE","st":"CUSTOM","sTy":"CUSTOM_AMAZON"},"contentAction":{"sTy":"CUSTOM_AMAZON","meta":{}},"lds":[],"adId":"/417241724/tv_native_masthead_plain_prod","tId":["11767767","11768950"]}},{"id":"5d63ca1de4b088013a6236b3","contents":[{"pageSize":50,"source":"RM","packageId":"dummy"}],"name":"Recommended Movies","format":{"lsTy":"DEFAULT","showAll":false,"ty":"MOVIE_NOLOGO","contentAction":{"meta":{"sourceName":"cf_movies_home"}}}},{"id":"5d63ca1de4b088013a6236b2","contents":[{"pageSize":50,"source":"RM","packageId":"dummy"}],"name":"Recommended TV Shows","format":{"lsTy":"DEFAULT","showAll":false,"ty":"MOVIE_NOLOGO","contentAction":{"meta":{"sourceName":"cf_tvshow_home"}}}},{"id":"5ae6b962e4b088c1fe893389","contents":[{"pageSize":20,"source":"MW","packageId":"ATV_PACKAGE_1524207345077","ty":"LIVE"}],"name":"LIVE NEWS","format":{"lsTy":"DEFAULT","showAll":false,"bgImgUrl":"","ty":"TVSHOW_LOGO_43","action":{"color":"#ff0000","pageId":"live_TV","t":"More","st":"LANDING"},"contentAction":{"meta":{}},"t":"LIVE NEWS"}},{"id":"5e74bffce4b0e60befa24bbb","contents":[{"pageSize":10,"source":"BE","packageId":"ATV_PACKAGE_1568185919253"}],"name":"Your Daily News in 30 Secs HIndi","format":{"lsTy":"DEFAULT","showAll":false,"bgImgUrl":"https://image.airtel.tv/pages/rails/5d2d6945e4b06e55de6b8cfe/editorji_highlightrail_background.jpg","ty":"TVSHOW_BIG_43","action":{"source":"BE","packageId":"ATV_PACKAGE_1568185919253","listingType":"TVSHOW_BIG_43","t":"More","st":"LISTING"},"contentAction":{"meta":{}},"t":"Your Daily News in 30 Secs"}},{"id":"5d9ec624e4b0499e024c99c6","contents":[{"pageSize":10,"source":"BE","packageId":"ATV_PACKAGE_1570605272423"}],"name":"Learn with Xstream","format":{"lsTy":"EXPLORE","ty":"CUSTOM","action":{"st":"DEFAULT"},"contentAction":{"source":"BE","pageId":"ATV_PACKAGE_1570605272423","st":"CUSTOM","sTy":"LISTING","meta":{}},"lds":[],"t":"Learn with Xstream"}},{"id":"5c78ce19e4b0d4a057339b17","contents":[{"pageSize":25,"source":"BE","packageId":"ATV_PACKAGE_1540027201907"}],"name":"MOST WATCHED HOLLYWOOD MOVIES","format":{"lsTy":"DEFAULT","showAll":false,"ty":"MOVIE_NOLOGO","action":{"color":"#a1ec00","source":"BE","packageId":"ATV_PACKAGE_1540027201907","listingType":"MOVIE_NOLOGO","t":"More","st":"LISTING"},"contentAction":{"meta":{}},"t":"Most Watched Hollywood Movies"}},{"id":"5e789319e4b032c54a8f0646","contents":[],"name":"Family Movie Card - English + Hindi","format":{"lsTy":"DEFAULT","ty":"CARD_NOTITILE_169","action":{"source":"MW","channelId":"MWTV_LIVETVCHANNEL_10000000060880000","t":"Play","st":"PLAY","meta":{"k":"1"},"ty":"LIVE"},"contentAction":{"meta":{}},"lds":[],"img":"https://image.airtel.tv/pages/rails/5e9083e8e4b0cff1aeeb2d58/Swami_Ramdev_New.jpg"}},{"id":"5d64b170e4b067b667714913","contents":[{"pageSize":12,"source":"BE","packageId":"ATV_PACKAGE_1566817268865"}],"name":"BEST HOLLYWOOD Series","format":{"lsTy":"DEFAULT","showAll":false,"ty":"MOVIE_NOLOGO","action":{"source":"BE","packageId":"ATV_PACKAGE_1566817268865","listingType":"MOVIE_NOLOGO","t":"More","st":"LISTING"},"contentAction":{"meta":{}},"t":"Best Hollywood Movie Series"}},{"id":"5e7892e6e4b032c54a8f0645","contents":[],"name":"Nostalgia Movie Card - English + Hindi","format":{"lsTy":"DEFAULT","ty":"CARD_NOTITILE_169","hIcon":"https://image.airtel.tv/pages/rails/5e7892e6e4b032c54a8f0645/ic_cplogo_hooq.png","action":{"source":"BE","packageId":"ATV_PACKAGE_1584939335512","listingType":"MOVIE_NOLOGO","t":"More","st":"LISTING","meta":{"A":"1"}},"contentAction":{"meta":{}},"lds":[],"img":"https://image.airtel.tv/pages/rails/5e7892e6e4b032c54a8f0645/NOSTALGIA-MOVIES-1032X576_(1).jpg"}},{"id":"5e99b557e4b0c3a92edf1ee7","contents":[],"name":"Wynk Music - Vishal Mishra - Live Concert Card Testing","format":{"lsTy":"DEFAULT","ty":"CARD_NOTITILE_169","action":{"source":"BE","contentId":"MWTV_LIVETVCHANNEL_10000000060880000","t":"Play","st":"PLAY","meta":{"k":"1"}},"contentAction":{"meta":{}},"lds":[],"img":"https://image.airtel.tv/pages/rails/5e99b010e4b03c81436668d3/1-Lohri-1032X576.jpg"}},{"id":"5ea70c25e4b0cea120315672","contents":[],"name":"Astha Gill Type Form Card Test","format":{"lsTy":"DEFAULT","ty":"PRODUCT_CARD","action":{"url":"https://wynkproduct.typeform.com/to/DesNW4","t":"Play","st":"WEBVIEW","meta":{"redirectType":"REDIRECT_TV","redirectDeeplink":"https://wynkproduct.typeform.com/to/DesNW4"}},"contentAction":{"meta":{}},"lds":[],"img":"https://image.airtel.tv/pages/rails/5ea70c25e4b0cea120315672/2-Badla-1032X576_(1).jpg"}},{"id":"5ea711a0e4b0cea120315674","contents":[],"name":"Aastha Gill - Card - Test","format":{"lsTy":"DEFAULT","ty":"CARD_NOTITILE_169","action":{"source":"MW","channelId":"MWTV_LIVETVCHANNEL_10000000060880000","t":"Play","st":"PLAY","ty":"LIVE"},"contentAction":{"meta":{}},"lds":[],"img":"https://image.airtel.tv/pages/rails/5ea711a0e4b0cea120315674/2-Badla-1032X576_(1).jpg"}},{"id":"5ea70fcfe4b0cea120315673","contents":[],"name":"test_card_ndtv","format":{"lsTy":"DEFAULT","ty":"CARD_NOTITILE_169","action":{"source":"MW","channelId":"MWTV_LIVETVCHANNEL_10000000060880000","t":"NDTV","st":"PLAY","ty":"LIVE"},"contentAction":{"meta":{}},"lt":"","ds":"","lds":[],"img":"https://image.airtel.tv/pages/rails/5ea70fcfe4b0cea120315673/photo-1549465220-1a8b9238cd48.jpeg"}}]
How can I get the "packageId" from the response for this idToValidate. Please help me on it.
You can use JsonPath
String res = "Response :[{"id":"5ea6fe53e4b09a8de7aeb19d","contents":[{"pageSize":6,"source":"BE","packageId":"ATV_PACKAGE_1538998610009"}],"name":"FEATURE BANNER","format":{"lsTy":"DEFAULT","showAll":false,"autoCarousel":false,"ty":"BANNER","action":{"source":"BE","contentId":"ATV_PACKAGE_1538998610009","t":"Play","st":"PLAY"},"contentAction":{"meta":{}}}},{"id":"5ac37644e4b03f23a4a705dc","contents":[],"name":"MastheadAd","format":{"lsTy":"DEFAULT","ty":"NATIVE_MASTHEAD_AD","action":{"source":"BE","st":"CUSTOM","sTy":"CUSTOM_AMAZON"},"contentAction":{"sTy":"CUSTOM_AMAZON","meta":{}},"lds":[],"adId":"/417241724/tv_native_masthead_plain_prod","tId":["11767767","11768950"]}},{"id":"5d63ca1de4b088013a6236b3","contents":[{"pageSize":50,"source":"RM","packageId":"dummy"}],"name":"Recommended Movies","format":{"lsTy":"DEFAULT","showAll":false,"ty":"MOVIE_NOLOGO","contentAction":{"meta":{"sourceName":"cf_movies_home"}}}},{"id":"5d63ca1de4b088013a6236b2","contents":[{"pageSize":50,"source":"RM","packageId":"dummy"}],"name":"Recommended TV Shows","format":{"lsTy":"DEFAULT","showAll":false,"ty":"MOVIE_NOLOGO","contentAction":{"meta":{"sourceName":"cf_tvshow_home"}}}},{"id":"5ae6b962e4b088c1fe893389","contents":[{"pageSize":20,"source":"MW","packageId":"ATV_PACKAGE_1524207345077","ty":"LIVE"}],"name":"LIVE NEWS","format":{"lsTy":"DEFAULT","showAll":false,"bgImgUrl":"","ty":"TVSHOW_LOGO_43","action":{"color":"#ff0000","pageId":"live_TV","t":"More","st":"LANDING"},"contentAction":{"meta":{}},"t":"LIVE NEWS"}},{"id":"5e74bffce4b0e60befa24bbb","contents":[{"pageSize":10,"source":"BE","packageId":"ATV_PACKAGE_1568185919253"}],"name":"Your Daily News in 30 Secs HIndi","format":{"lsTy":"DEFAULT","showAll":false,"bgImgUrl":"https://image.airtel.tv/pages/rails/5d2d6945e4b06e55de6b8cfe/editorji_highlightrail_background.jpg","ty":"TVSHOW_BIG_43","action":{"source":"BE","packageId":"ATV_PACKAGE_1568185919253","listingType":"TVSHOW_BIG_43","t":"More","st":"LISTING"},"contentAction":{"meta":{}},"t":"Your Daily News in 30 Secs"}},{"id":"5d9ec624e4b0499e024c99c6","contents":[{"pageSize":10,"source":"BE","packageId":"ATV_PACKAGE_1570605272423"}],"name":"Learn with Xstream","format":{"lsTy":"EXPLORE","ty":"CUSTOM","action":{"st":"DEFAULT"},"contentAction":{"source":"BE","pageId":"ATV_PACKAGE_1570605272423","st":"CUSTOM","sTy":"LISTING","meta":{}},"lds":[],"t":"Learn with Xstream"}},{"id":"5c78ce19e4b0d4a057339b17","contents":[{"pageSize":25,"source":"BE","packageId":"ATV_PACKAGE_1540027201907"}],"name":"MOST WATCHED HOLLYWOOD MOVIES","format":{"lsTy":"DEFAULT","showAll":false,"ty":"MOVIE_NOLOGO","action":{"color":"#a1ec00","source":"BE","packageId":"ATV_PACKAGE_1540027201907","listingType":"MOVIE_NOLOGO","t":"More","st":"LISTING"},"contentAction":{"meta":{}},"t":"Most Watched Hollywood Movies"}},{"id":"5e789319e4b032c54a8f0646","contents":[],"name":"Family Movie Card - English + Hindi","format":{"lsTy":"DEFAULT","ty":"CARD_NOTITILE_169","action":{"source":"MW","channelId":"MWTV_LIVETVCHANNEL_10000000060880000","t":"Play","st":"PLAY","meta":{"k":"1"},"ty":"LIVE"},"contentAction":{"meta":{}},"lds":[],"img":"https://image.airtel.tv/pages/rails/5e9083e8e4b0cff1aeeb2d58/Swami_Ramdev_New.jpg"}},{"id":"5d64b170e4b067b667714913","contents":[{"pageSize":12,"source":"BE","packageId":"ATV_PACKAGE_1566817268865"}],"name":"BEST HOLLYWOOD Series","format":{"lsTy":"DEFAULT","showAll":false,"ty":"MOVIE_NOLOGO","action":{"source":"BE","packageId":"ATV_PACKAGE_1566817268865","listingType":"MOVIE_NOLOGO","t":"More","st":"LISTING"},"contentAction":{"meta":{}},"t":"Best Hollywood Movie Series"}},{"id":"5e7892e6e4b032c54a8f0645","contents":[],"name":"Nostalgia Movie Card - English + Hindi","format":{"lsTy":"DEFAULT","ty":"CARD_NOTITILE_169","hIcon":"https://image.airtel.tv/pages/rails/5e7892e6e4b032c54a8f0645/ic_cplogo_hooq.png","action":{"source":"BE","packageId":"ATV_PACKAGE_1584939335512","listingType":"MOVIE_NOLOGO","t":"More","st":"LISTING","meta":{"A":"1"}},"contentAction":{"meta":{}},"lds":[],"img":"https://image.airtel.tv/pages/rails/5e7892e6e4b032c54a8f0645/NOSTALGIA-MOVIES-1032X576_(1).jpg"}},{"id":"5e99b557e4b0c3a92edf1ee7","contents":[],"name":"Wynk Music - Vishal Mishra - Live Concert Card Testing","format":{"lsTy":"DEFAULT","ty":"CARD_NOTITILE_169","action":{"source":"BE","contentId":"MWTV_LIVETVCHANNEL_10000000060880000","t":"Play","st":"PLAY","meta":{"k":"1"}},"contentAction":{"meta":{}},"lds":[],"img":"https://image.airtel.tv/pages/rails/5e99b010e4b03c81436668d3/1-Lohri-1032X576.jpg"}},{"id":"5ea70c25e4b0cea120315672","contents":[],"name":"Astha Gill Type Form Card Test","format":{"lsTy":"DEFAULT","ty":"PRODUCT_CARD","action":{"url":"https://wynkproduct.typeform.com/to/DesNW4","t":"Play","st":"WEBVIEW","meta":{"redirectType":"REDIRECT_TV","redirectDeeplink":"https://wynkproduct.typeform.com/to/DesNW4"}},"contentAction":{"meta":{}},"lds":[],"img":"https://image.airtel.tv/pages/rails/5ea70c25e4b0cea120315672/2-Badla-1032X576_(1).jpg"}},{"id":"5ea711a0e4b0cea120315674","contents":[],"name":"Aastha Gill - Card - Test","format":{"lsTy":"DEFAULT","ty":"CARD_NOTITILE_169","action":{"source":"MW","channelId":"MWTV_LIVETVCHANNEL_10000000060880000","t":"Play","st":"PLAY","ty":"LIVE"},"contentAction":{"meta":{}},"lds":[],"img":"https://image.airtel.tv/pages/rails/5ea711a0e4b0cea120315674/2-Badla-1032X576_(1).jpg"}},{"id":"5ea70fcfe4b0cea120315673","contents":[],"name":"test_card_ndtv","format":{"lsTy":"DEFAULT","ty":"CARD_NOTITILE_169","action":{"source":"MW","channelId":"MWTV_LIVETVCHANNEL_10000000060880000","t":"NDTV","st":"PLAY","ty":"LIVE"},"contentAction":{"meta":{}},"lt":"","ds":"","lds":[],"img":"https://image.airtel.tv/pages/rails/5ea70fcfe4b0cea120315673/photo-1549465220-1a8b9238cd48.jpeg"}}]";
Code :
JsonPath js = new JsonPath(res);
String idToValidate = "5ae6b962e4b088c1fe893389";
System.out.println("id : " + res.contains(idToValidate));
String packageId = js.get("find {it.id =='"+idToValidate+"'}.contents.packageId").toString();
System.out.println("PackageID : " + packageId);
Output :
ID : true
PackageID : [ATV_PACKAGE_1524207345077]
Alternative :
String output = given().when().get(url).then().extract().body().jsonPath().get("find {it.id =='"+idToValidate+"'}.contents.packageId").toString();
System.out.println(output);

SoapUI: response with CDATA is giving null. searched various article but no luck

Hello I have below SOAP reponse.
`
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetWeatherResponse xmlns="http://www.webserviceX.NET">
<GetWeatherResult><![CDATA[<?xml version="1.0" encoding="utf-16"?>
<CurrentWeather>
<Location>Cape Town, Cape Town International Airport, South Africa (FACT) 33-59S 018-36E 0M</Location>
<Time>Jun 04, 2016 - 05:00 AM EDT / 2016.06.04 0900 UTC</Time>
<Wind> from the SE (130 degrees) at 21 MPH (18 KT):0</Wind>
<Visibility> greater than 7 mile(s):0</Visibility>
<SkyConditions> mostly clear</SkyConditions>
<Temperature> 60 F (16 C)</Temperature>
<DewPoint> 44 F (7 C)</DewPoint>
<RelativeHumidity> 55%</RelativeHumidity>
<Pressure> 30.39 in. Hg (1029 hPa)</Pressure>
<Status>Success</Status>
</CurrentWeather>]]></GetWeatherResult>
</GetWeatherResponse>
</soap:Body>
</soap:Envelope>"`
for the following request: http://www.webservicex.net/globalweather.asmx.
I want to read XML Data in above response using script. but it is giving null.
I have tried script as below
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(messageExchange.responseContent)
holder.namespaces["ns"] = "http://www.webserviceX.NET/" def
weatherinfo= holder.getNodeValue("//ns:GetWeatherResult/text()")
log.info weatherinfo
bit Instead of getting above reponse I am getting NULL. I have read the SOAPUI documentation on CDATA but its not working.
I got answer. It was just one extra slash in namespace that was giving me null.
Both the below scripts are working now.
> def respXmlHolder = new
> com.eviware.soapui.support.XmlHolder(messageExchange.getResponseContentAsXml())
> respXmlHolder.namespaces["ns1"] ="http://www.webserviceX.NET" def
> CDATAXml= respXmlHolder.getNodeValue("//ns1:GetWeatherResult/text()")
> log.info CDATAXml
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(messageExchange.responseContent)
holder.namespaces["ns"] = "http://www.webserviceX.NET"
def weatherinfo= holder.getNodeValue("//ns:GetWeatherResult/text()")
log.info weatherinfo

JsonParser ArrayIndexOutOfBoundsException when parsing json

The following code should work as a JsonParser but it is returning an ArrayIndexOutOfBoundsException even though I check that there are still elements to parse.
public void parseJson(String url) {
try {
InputStream is = new URL(url).openStream();
JsonParser parser = Json.createParser(is);
while (parser.hasNext()) {
Event e = parser.next();
if (e == Event.KEY_NAME) {
if (parser.getString().equals("name") && parser.hasNext()) {
parser.next();
writer = new BufferedWriter(new FileWriter("names.txt"));
writer.write(parser.getString());
}
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
The error produced is such:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4096
at org.glassfish.json.JsonTokenizer.readChar(JsonTokenizer.java:388)
at org.glassfish.json.JsonTokenizer.read(JsonTokenizer.java:98)
at org.glassfish.json.JsonTokenizer.readString(JsonTokenizer.java:124)
at org.glassfish.json.JsonTokenizer.nextToken(JsonTokenizer.java:310)
at org.glassfish.json.JsonParserImpl$StateIterator.nextToken(JsonParserImpl.java:157)
at org.glassfish.json.JsonParserImpl$StateIterator.next(JsonParserImpl.java:182)
at org.glassfish.json.JsonParserImpl.next(JsonParserImpl.java:150)
at proj.Proj2.parseJson(Proj2.java:43)
at proj.Proj1.main(Proj1.java:78)
It parses everything up to when the error is thrown.
Sample JSON that produces error:
[{"id":774,"na":"Hungry Leaf","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1200,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Sandwiches"],"addr":"2608 Erwin Rd, Durham, NC","full_addr":{"addr":"2608 Erwin Rd","addr2":"","city":"Durham","state":"NC","postal_code":"27705-3843"},"city":"Durham","latitude":36.008621,"longitude":-78.94474,"del":1200,"mino":100,"is_delivering":0},{"id":780,"na":"Armadillo Grill","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1080,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["Mexican","Tex-Mex"],"addr":"439 Glenwood Ave, Raleigh, NC","full_addr":{"addr":"439 Glenwood Ave","addr2":"","city":"Raleigh","state":"NC","postal_code":"27603-1219"},"city":"Raleigh","latitude":35.785754,"longitude":-78.647293,"del":1080,"mino":100,"is_delivering":0},{"id":783,"na":"Chef Mario's Bistro","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":2880,"mino":150,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Sandwiches"],"addr":"2610 Wycliff Rd, Raleigh, NC","full_addr":{"addr":"2610 Wycliff Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27607-3060"},"city":"Raleigh","latitude":35.818683,"longitude":-78.692145,"del":2880,"mino":150,"is_delivering":0},{"id":784,"na":"Chef Mario's Catering","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":4320,"mino":150,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Catering","Italian","Sandwiches"],"addr":"2610 Wycliff Rd, Raleigh, NC","full_addr":{"addr":"2610 Wycliff Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27607-3060"},"city":"Raleigh","latitude":35.818683,"longitude":-78.692145,"del":4320,"mino":150,"is_delivering":0},{"id":786,"na":"D'Nardys Caterers","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1320,"mino":6.55,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Catering","Italian","Sandwiches"],"addr":"314 Madison Grove Pl, Cary, NC","full_addr":{"addr":"314 Madison Grove Pl","addr2":"","city":"Cary","state":"NC","postal_code":"27519-8161"},"city":"Cary","latitude":35.82135,"longitude":-78.854469,"del":1320,"mino":6.55,"is_delivering":0},{"id":787,"na":"Danny's Bar-B-Que","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":2640,"mino":100,"can":1}},"allow_tip":1,"allow_asap":1,"cu":["American","Barbecue"],"addr":"9561 Chapel Hill Rd, Morrisville, NC","full_addr":{"addr":"9561 Chapel Hill Rd","addr2":"","city":"Morrisville","state":"NC","postal_code":"27560-7359"},"city":"Morrisville","latitude":35.805972,"longitude":-78.809315,"del":2640,"mino":100,"is_delivering":1},{"id":792,"na":"Flying Biscuit","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1440,"mino":150,"can":1}},"allow_tip":1,"allow_asap":1,"cu":["Breakfast","Sandwiches"],"addr":"2016 Clark Ave, Raleigh, NC","full_addr":{"addr":"2016 Clark Ave","addr2":"","city":"Raleigh","state":"NC","postal_code":"27605-1604"},"city":"Raleigh","latitude":35.788996,"longitude":-78.659642,"del":1440,"mino":150,"is_delivering":1},{"id":793,"na":"Gateway Restaurant","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1320,"mino":50,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast"],"addr":"2411 Crabtree Blvd, Raleigh, NC","full_addr":{"addr":"2411 Crabtree Blvd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27604-2232"},"city":"Raleigh","latitude":35.805222,"longitude":-78.611873,"del":1320,"mino":50,"is_delivering":0},{"id":796,"na":"Hibachi Xpress","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":720,"mino":150,"can":0}},"allow_tip":1,"allow_asap":1,"addr":"2470 Walnut St, Cary, NC","full_addr":{"addr":"2470 Walnut St","addr2":"","city":"Cary","state":"NC","postal_code":"27518-9212"},"city":"Cary","latitude":35.75113,"longitude":-78.741205,"del":720,"mino":150,"is_delivering":0},{"id":798,"na":"HoneyBaked Ham","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1080,"mino":60,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Sandwiches"],"addr":"5275 Six Forks Rd, Raleigh, NC","full_addr":{"addr":"5275 Six Forks Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27609-4431"},"city":"Raleigh","latitude":35.85326,"longitude":-78.642593,"del":1080,"mino":60,"is_delivering":0},{"id":804,"na":"Moe's Southwest Grill","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1080,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["Mexican","Tex-Mex"],"addr":"506 Daniels St, Raleigh, NC","full_addr":{"addr":"506 Daniels St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27605-1317"},"city":"Raleigh","latitude":35.791061,"longitude":-78.66118,"del":1080,"mino":100,"is_delivering":0},{"id":806,"na":"Ole Time Barbecue","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1080,"mino":75,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["Barbecue"],"addr":"6309 Hillsborough St, Raleigh, NC","full_addr":{"addr":"6309 Hillsborough St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27606-1148"},"city":"Raleigh","latitude":35.787922,"longitude":-78.73851,"del":1080,"mino":75,"is_delivering":0},{"id":811,"na":"The Q Shack","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":180,"mino":40,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Barbecue"],"addr":"North Hills, Raleigh, NC","full_addr":{"addr":"North Hills","addr2":"","city":"Raleigh","state":"NC","postal_code":"27609"},"city":"Raleigh","latitude":35.837521,"longitude":-78.64312,"del":180,"mino":40,"is_delivering":0},{"id":812,"na":"We Cook For You","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":720,"mino":125,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Caribbean","Catering","Sandwiches"],"addr":"1125 Fuller St, Raleigh, NC","full_addr":{"addr":"1125 Fuller St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27603-2217"},"city":"Raleigh","latitude":35.765381,"longitude":-78.650581,"del":720,"mino":125,"is_delivering":0},{"id":813,"na":"WhichWich Superior Sandwiches","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1080,"mino":75,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Sandwiches"],"addr":"4025 Lake Boone Trl, Raleigh, NC","full_addr":{"addr":"4025 Lake Boone Trl","addr2":"","city":"Raleigh","state":"NC","postal_code":"27607-2928"},"city":"Raleigh","latitude":35.815604,"longitude":-78.696541,"del":1080,"mino":75,"is_delivering":0},{"id":820,"na":"Greens","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1080,"mino":6.55,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Italian","Seafood"],"addr":"4120 Main at North Hills St, Raleigh, NC","full_addr":{"addr":"4120 Main at North Hills St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27609-5754"},"city":"Raleigh","latitude":35.837546,"longitude":-78.642515,"del":1080,"mino":6.55,"is_delivering":0},{"id":861,"na":"Catering By Design","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":240,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Catering","Italian","Pizza","Sandwiches"],"addr":"132 Kilmayne Dr, Cary, NC","full_addr":{"addr":"132 Kilmayne Dr","addr2":"","city":"Cary","state":"NC","postal_code":"27511-4465"},"city":"Cary","latitude":35.769451,"longitude":-78.783912,"del":240,"mino":100,"is_delivering":0},{"id":3498,"na":"Z Pizza","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":900,"mino":75,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Pizza","Sandwiches"],"addr":"421 Fayetteville St, Raleigh, NC","full_addr":{"addr":"421 Fayetteville St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27601-1778"},"city":"Raleigh","latitude":35.77467,"longitude":-78.639389,"del":900,"mino":75,"is_delivering":0},{"id":3500,"na":"Artisan Sandwiches & Salads","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":900,"mino":50,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Sandwiches"],"addr":"421 Fayetteville St, Raleigh, NC","full_addr":{"addr":"421 Fayetteville St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27601-1778"},"city":"Raleigh","latitude":35.77467,"longitude":-78.639389,"del":900,"mino":50,"is_delivering":0},{"id":3795,"na":"Chef Mario's Catering Dinner","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":4320,"mino":150,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Asian","Barbecue","Breakfast","Catering","Italian","Jamaican","Mediterranean","Sandwiches","Seafood","Thai"],"addr":"2610 Wycliff Rd, Raleigh, NC","full_addr":{"addr":"2610 Wycliff Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27607-3060"},"city":"Raleigh","latitude":35.818683,"longitude":-78.692145,"del":4320,"mino":150,"is_delivering":0},{"id":3895,"na":"A Catered Affair","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":720,"mino":125,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Asian","Breakfast","Catering","Italian","Jamaican","Sandwiches"],"addr":"1125 Fuller St, Raleigh, NC","full_addr":{"addr":"1125 Fuller St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27603-2217"},"city":"Raleigh","latitude":35.765381,"longitude":-78.650581,"del":720,"mino":125,"is_delivering":0},{"id":4011,"na":"Neomonde Mediterranean","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1260,"mino":125,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["Breakfast","Mediterranean","Sandwiches"],"addr":"9650 Strickland Rd, Raleigh, NC","full_addr":{"addr":"9650 Strickland Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27615-1937"},"city":"Raleigh","del":1260,"mino":125,"is_delivering":0},{"id":4425,"na":"Dorry's Downtown Deli","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1320,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Sandwiches"],"addr":"211 E Chatham St, Cary, NC","full_addr":{"addr":"211 E Chatham St","addr2":"","city":"Cary","state":"NC","postal_code":"27511-3427"},"city":"Cary","latitude":35.787534,"longitude":-78.777666,"del":1320,"mino":100,"is_delivering":0},{"id":4427,"na":"Pogo","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":180,"mino":40,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Sandwiches"],"addr":"201 E Hargett St, Raleigh, NC","full_addr":{"addr":"201 E Hargett St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27601-1437"},"city":"Raleigh","latitude":35.778141,"longitude":-78.635834,"del":180,"mino":40,"is_delivering":0},{"id":4428,"na":"Chick-fil-A","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1200,"mino":200,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Sandwiches"],"addr":"1803 N Harrison Ave, Cary, NC","full_addr":{"addr":"1803 N Harrison Ave","addr2":"","city":"Cary","state":"NC","postal_code":"27513-2408"},"city":"Cary","latitude":35.828831,"longitude":-78.769402,"del":1200,"mino":200,"is_delivering":0},{"id":6142,"na":"Spartacus Restaurant","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1200,"mino":300,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["Mediterranean","Sandwiches"],"addr":"4139 Old Chapel Hill Rd, Durham, NC","full_addr":{"addr":"4139 Old Chapel Hill Rd","addr2":"","city":"Durham","state":"NC","postal_code":"27707-5057"},"city":"Durham","del":1200,"mino":300,"is_delivering":0},{"id":7776,"na":"Firehouse Subs","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":120,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Sandwiches"],"addr":"1539 Us Highway 70 E, Garner, NC","full_addr":{"addr":"1539 Us Highway 70 E","addr2":"","city":"Garner","state":"NC","postal_code":"27529"},"city":"Garner","del":120,"mino":100,"is_delivering":0},{"id":7985,"na":"Ben & Jerry's Ice Cream","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":2880,"mino":200,"can":1}},"allow_tip":1,"allow_asap":1,"cu":["American","Bakery","Ice Cream"],"addr":"102 W Franklin St, Chapel Hill, NC","full_addr":{"addr":"102 W Franklin St","addr2":"","city":"Chapel Hill","state":"NC","postal_code":"27516-2516"},"city":"Chapel Hill","latitude":35.91304,"longitude":-79.056091,"del":2880,"mino":200,"is_delivering":1},{"id":10509,"na":"Catering By Design - Dinner","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":240,"mino":6.55,"can":1}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Catering","Italian","Sandwiches","Seafood"],"addr":"132 Kilmayne Dr, Cary, NC","full_addr":{"addr":"132 Kilmayne Dr","addr2":"","city":"Cary","state":"NC","postal_code":"27511-4465"},"city":"Cary","latitude":35.769451,"longitude":-78.783912,"del":240,"mino":6.55,"is_delivering":1},{"id":12715,"na":"Top This Cafe # The Atrium","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":45,"mino":0,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Breakfast","Sandwiches"],"addr":"2501 Blue Ridge Rd, Raleigh, NC","full_addr":{"addr":"2501 Blue Ridge Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27607-6436"},"city":"Raleigh","latitude":35.814449,"longitude":-78.705399,"del":45,"mino":0,"is_delivering":0},{"id":12724,"na":"Donovan's Dish","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1200,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Catering","Sandwiches"],"addr":"1040 Buck Jones Rd, Raleigh, NC","full_addr":{"addr":"1040 Buck Jones Rd","addr2":"","city":"Raleigh","state":"NC","postal_code":"27606-3323"},"city":"Raleigh","latitude":35.770224,"longitude":-78.739941,"del":1200,"mino":100,"is_delivering":0},{"id":12739,"na":"Lubrano's Ristorante Italiano","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1200,"mino":125,"can":1}},"allow_tip":1,"allow_asap":1,"cu":["Italian"],"addr":"101 Keybridge Dr, Morrisville, NC","full_addr":{"addr":"101 Keybridge Dr","addr2":"","city":"Morrisville","state":"NC","postal_code":"27560-5911"},"city":"Morrisville","latitude":35.819771,"longitude":-78.822189,"del":1200,"mino":125,"is_delivering":1},{"id":23709,"na":"DeMarco's Restaurant & Bar","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":1260,"mino":125,"can":1}},"allow_tip":1,"allow_asap":1,"cu":["Italian"],"addr":"3607 Falls River Ave, Raleigh, NC","full_addr":{"addr":"3607 Falls River Ave","addr2":"","city":"Raleigh","state":"NC","postal_code":"27614-7359"},"city":"Raleigh","latitude":35.930141,"longitude":-78.564522,"del":1260,"mino":125,"is_delivering":1},{"id":23710,"na":"Green Planet Catering","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":4200,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Catering","Sandwiches"],"addr":"218 S Blount St, Raleigh, NC","full_addr":{"addr":"218 S Blount St","addr2":"","city":"Raleigh","state":"NC","postal_code":"27601-1408"},"city":"Raleigh","latitude":35.777495,"longitude":-78.63662,"del":4200,"mino":100,"is_delivering":0},{"id":23815,"na":"Capital Center Catering","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":960,"mino":150,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Bakery","Catering","Italian","Sandwiches"],"addr":"217 E Main St, Clayton, NC","full_addr":{"addr":"217 E Main St","addr2":"","city":"Clayton","state":"NC","postal_code":"27520-2449"},"city":"Clayton","latitude":35.652088,"longitude":-78.458515,"del":960,"mino":150,"is_delivering":0},{"id":23817,"na":"Firewurst","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":960,"mino":100,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["American","Sandwiches"],"addr":"8531 Brier Creek Pky, Raleigh, NC","full_addr":{"addr":"8531 Brier Creek Pky","addr2":"","city":"Raleigh","state":"NC","postal_code":"27617-7333"},"city":"Raleigh","latitude":35.905433,"longitude":-78.786068,"del":960,"mino":100,"is_delivering":0},{"id":32244,"na":"Don Rio's Southwest Catering","cs_phone":"919-234-7755","rds_info":{"id":125,"name":"Triangle Food Guy","logo":""},"services":{"deliver":{"time":720,"mino":125,"can":0}},"allow_tip":1,"allow_asap":1,"cu":["Mexican","Tex-Mex"],"addr":"3607 Falls River Ave, Raleigh, NC","full_addr":{"addr":"3607 Falls River Ave","addr2":"","city":"Raleigh","state":"NC","postal_code":"27614-7359"},"city":"Raleigh","latitude":35.930141,"longitude":-78.564522,"del":720,"mino":125,"is_delivering":0}]
It seems this was a bug in version 1.0.1. Here's another thread that talks about it. The JsonTokenizer class has changed pretty dramatically since then. Upgrade to 1.0.2 and you will be fine.

How do I create a product with additional attributes in Magento via Soap/Java

Good day!
I would like to use the Magento’s SOAP API to manage the product catalog, attributes etc. I'm running following configuration:-
Magento 1.6
Soap API WS-I compliance
Mac OSX Lion
Mamp 2.0.5
In case someone wants to create a new product, it is necessary to set a few properties of the product object.
Following code will demonstrate my approach to do this :
public int createProduct(DatabaseProduct product) {
ArrayOfString categories = new ArrayOfString();
categories.getComplexObjectArray().add(categoryID);
createEntity.setCategoryIds(categories);
CatalogProductCreateEntity createEntity = populateCreateOrUpdateEntity(product);
CatalogProductCreateRequestParam param = new CatalogProductCreateRequestParam();
param.setSessionId(sessionId);
param.setSet(setId);
param.setSku(product.getSku());
param.setType("simple");
param.setStore(storeId);
param.setProductData(createEntity);
CatalogProductCreateResponseParam response = service.catalogProductCreate(param);
return response.getResult();
}
private CatalogProductCreateEntity populateCreateOrUpdateEntity(DatabaseProduct product) {
CatalogProductCreateEntity createEntity = new CatalogProductCreateEntity();
createEntity.setShortDescription(product.getDescription().substring(0, 20) + "...");
createEntity.setDescription(product.getDescription());
createEntity.setName(product.getName());
createEntity.setPrice(String.valueOf(product.getPrice()));
createEntity.setStatus("1"); //active
createEntity.setVisibility("4"); //visible in search/catalog
createEntity.setWeight("70"); //some value
createEntity.setTaxClassId("2"); //standard
AssociativeArray attributes = new AssociativeArray();
AssociativeEntity attr1 = new AssociativeEntity();
attr1.("attribute1_key";
attr1.("attribute1_value");
attributes.getComplexObjectArray().add(attr1);
AssociativeEntity attr2 = new AssociativeEntity();
attr2.("attribute2_key");
attr2.("attribute2_value");
attributes.getComplexObjectArray().add(attr2);
createEntity.setAdditionalAttributes(attributes);
return createEntity;
}
I realized that I get an error written to the "system.log" of Magento.
2012-01-21T09:41:01+00:00 DEBUG (7): First parameter must either be an object or the name of an existing class/opt/website/magento/app/code/core/Mage/Catalog/Model/Product/Api/V2.php
I could localize the error in the "V2.php" file on line 265.
According to the php.net documentation the "property_exists()" method only can check for fields in objects.
As a matter of fact the "$productData" variable holds a property called "additional_attributes" which is of the type array.
Therefore the execution of this code will lead to an error.
Moreover I don’t know to reproduce the object the structure of the "$productData" object through the use of Magento’s SOAP API V2.
If I examine this code ("foreach" loop) in line 270, it indicates that there is an object ("$productData") holding an array ("additional_attributes") which again shall encapsulate a set of key/value pairs (if I am right)
253 protected function _prepareDataForSave ($product, $productData)
254 {
255 if (property_exists($productData, 'website_ids') && is_array($productData->website_ids)) {
256 $product->setWebsiteIds($productData->website_ids);
257 }
258
259 Mage::log("debug1");
260 Mage::log(property_exists($productData, 'additional_attributes'));
261
262 Mage::log($productData);
263
264 if (property_exists($productData, 'additional_attributes')) {
265 if (property_exists($productData->additional_attributes, 'single_data')) {
266
267 Mage::log("---> single");
268 Mage::log($productData->additional_attributes);
269
270 foreach ($productData->additional_attributes->single_data as $_attribute) {
271 $_attrCode = $_attribute->key;
272 $productData->$_attrCode = $_attribute->value;
273 }
274 }
275 if (property_exists($productData->additional_attributes, 'multi_data')) {
276
277 Mage::log("---> multi");
278 Mage::log($productData->additional_attributes);
279
280 foreach ($productData->additional_attributes->multi_data as $_attribute) {
281 $_attrCode = $_attribute->key;
282 $productData->$_attrCode = $_attribute->value;
283 }
284 }
285
286 Mage::log("debugXXX");
287 unset($productData->additional_attributes);
288 }
289
290 Mage::log("debug2");
291
292 foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
293 $_attrCode = $attribute->getAttributeCode();
294 if ($this->_isAllowedAttribute($attribute) && (isset($productData->$_attrCode))) {
295 $product->setData(
296 ... etc ...
This seems to be a bug. So here is my question.
Am I going right to call this an programming issue which shall be posted in the bug base?
Is there a way to get over this issue?
Shall I rewrite parts of the php.code from above to satisfy my need to handle product information to create a product properly ?
Thanks in advance
$productData
(
[name] => testname
[description] => testdescription
[short_description] => shorttestdescription
[weight] => 70
[status] => 1
[visibility] => 4
[price] => 359.0
[tax_class_id] => 2
[additional_attributes] => Array
(
[attribute1] => 999.0
[attribute2] => testcontent
)
)
the CatalogProductCreate-Call from the WSDL generated by SoapUI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
<soapenv:Header/>
<soapenv:Body>
<urn:catalogProductCreateRequestParam>
<sessionId>?</sessionId>
<type>?</type>
<set>?</set>
<sku>?</sku>
<productData>
<!--Optional:-->
<categories>
<!--Zero or more repetitions:-->
<complexObjectArray>?</complexObjectArray>
</categories>
<!--Optional:-->
<websites>
<!--Zero or more repetitions:-->
<complexObjectArray>?</complexObjectArray>
</websites>
<!--Optional:-->
<name>?</name>
<!--Optional:-->
<description>?</description>
<!--Optional:-->
<short_description>?</short_description>
<!--Optional:-->
<weight>?</weight>
<!--Optional:-->
<status>?</status>
<!--Optional:-->
<url_key>?</url_key>
<!--Optional:-->
<url_path>?</url_path>
<!--Optional:-->
<visibility>?</visibility>
<!--Optional:-->
<category_ids>
<!--Zero or more repetitions:-->
<complexObjectArray>?</complexObjectArray>
</category_ids>
<!--Optional:-->
<website_ids>
<!--Zero or more repetitions:-->
<complexObjectArray>?</complexObjectArray>
</website_ids>
<!--Optional:-->
<has_options>?</has_options>
<!--Optional:-->
<gift_message_available>?</gift_message_available>
<!--Optional:-->
<price>?</price>
<!--Optional:-->
<special_price>?</special_price>
<!--Optional:-->
<special_from_date>?</special_from_date>
<!--Optional:-->
<special_to_date>?</special_to_date>
<!--Optional:-->
<tax_class_id>?</tax_class_id>
<!--Optional:-->
<tier_price>
<!--Zero or more repetitions:-->
<complexObjectArray>
<!--Optional:-->
<customer_group_id>?</customer_group_id>
<!--Optional:-->
<website>?</website>
<!--Optional:-->
<qty>?</qty>
<!--Optional:-->
<price>?</price>
</complexObjectArray>
</tier_price>
<!--Optional:-->
<meta_title>?</meta_title>
<!--Optional:-->
<meta_keyword>?</meta_keyword>
<!--Optional:-->
<meta_description>?</meta_description>
<!--Optional:-->
<custom_design>?</custom_design>
<!--Optional:-->
<custom_layout_update>?</custom_layout_update>
<!--Optional:-->
<options_container>?</options_container>
<!--Optional:-->
<additional_attributes>
<!--Zero or more repetitions:-->
<complexObjectArray>
<key>?</key>
<value>?</value>
</complexObjectArray>
</additional_attributes>
<!--Optional:-->
<stock_data>
<!--Optional:-->
<qty>?</qty>
<!--Optional:-->
<is_in_stock>?</is_in_stock>
<!--Optional:-->
<manage_stock>?</manage_stock>
<!--Optional:-->
<use_config_manage_stock>?</use_config_manage_stock>
<!--Optional:-->
<min_qty>?</min_qty>
<!--Optional:-->
<use_config_min_qty>?</use_config_min_qty>
<!--Optional:-->
<min_sale_qty>?</min_sale_qty>
<!--Optional:-->
<use_config_min_sale_qty>?</use_config_min_sale_qty>
<!--Optional:-->
<max_sale_qty>?</max_sale_qty>
<!--Optional:-->
<use_config_max_sale_qty>?</use_config_max_sale_qty>
<!--Optional:-->
<is_qty_decimal>?</is_qty_decimal>
<!--Optional:-->
<backorders>?</backorders>
<!--Optional:-->
<use_config_backorders>?</use_config_backorders>
<!--Optional:-->
<notify_stock_qty>?</notify_stock_qty>
<!--Optional:-->
<use_config_notify_stock_qty>?</use_config_notify_stock_qty>
</stock_data>
</productData>
<!--Optional:-->
<store>?</store>
</urn:catalogProductCreateRequestParam>
</soapenv:Body>
</soapenv:Envelope>
For the V2 SOAP API it appears that we need to nest the additional_attributes in a multi_data or single_data layer?
Looking at app/code/core/Mage/Catalog/Model/Product/Api/V2.php #256 I think we need to use
$manufacturer = new stdClass();
$manufacturer->key = "manufacturer";
$manufacturer->value = "20";
$additionalAttrs['single_data'][] = $manufacturer;
or
$manufacturer = new stdClass();
$manufacturer->key = "manufacturer";
$manufacturer->value = "20";
$additionalAttrs['multi_data'][] = $manufacturer;
to be used like:
$productData = new stdClass();
$additionalAttrs = array();
// manufacturer from one of the two above ^
$productData->name = $data['name'];
$productData->description = $data['description'];
$productData->short_description = $data['short_description'];
$productData->weight = 0;
$productData->status = 2; // 1 = active
$productData->visibility = 4; //visible in search/catalog
$productData->category_ids = $data['categories'];
$productData->price = $data['price'];
$productData->tax_class_id = 2; // 2=standard
$productData->additional_attributes = $additionalAttrs;
// Create new product
try {
$proxy->catalogProductCreate($sessionId, 'virtual', 9, $sku, $productData); // 9 is courses
} catch (SoapFault $e) {
print $e->getMessage(); //Internal Error. Please see log for details.
exit();
}
I actually had to patch app/code/core/Mage/Catalog/Model/Product/Api/V2.php to get this call to work in version 1.6.2.0.
The existing code checks for either a "single_data" or "multi_data" attribute under the 'additional_attributes' property and tries to iterate over the those as an associative array:
if (property_exists($productData, 'additional_attributes')) {
if (property_exists($productData->additional_attributes, 'single_data')) {
foreach ($productData->additional_attributes->single_data as $_attribute) {
$_attrCode = $_attribute->key;
$productData->$_attrCode = $_attribute->value;
}
}
if (property_exists($productData->additional_attributes, 'multi_data')) {
foreach ($productData->additional_attributes->multi_data as $_attribute) {
$_attrCode = $_attribute->key;
$productData->$_attrCode = $_attribute->value;
}
}
}
I think that the issue is that since we're passing the associative array structure:
<item>
<key>...</key>
<value>...</value>
</item>
<item>
<key>...</key>
<value>...</value>
</item>
directly under the additional_attribtutes block then it's really the additional_attributes property that must be iterated over to pull the attribute key/values, so I added third if block:
if (gettype($productData->additional_attributes) == 'array') {
foreach ($productData->additional_attributes as $k => $v) {
$_attrCode = $k;
$productData->$_attrCode = $v;
}
}
With that code in place my custom attributes are being added/updated.
Here's a sample request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
<soapenv:Header/>
<soapenv:Body>
<urn:catalogProductUpdateRequestParam>
<sessionId>100fe1f9d0518b0fd0ed49cc460c1fa6</sessionId>
<productId>1</productId>
<productData>
<name>product 3</name>
<!-- the custom attributes to updated....
-->
<additional_attributes>
<complexObjectArray>
<key>feed_id</key>
<value>56920</value>
</complexObjectArray>
<complexObjectArray>
<key>feed_active</key>
<value>1</value>
</complexObjectArray>
</additional_attributes>
</productData>
</urn:catalogProductUpdateRequestParam>
</soapenv:Body>
</soapenv:Envelope>
This is not a bug. I have been using this Magento SOAP API V2 for more than a year, and the concept which Magento team have applied here is absolutely correct.
First of all, every time any one using the SOAP API V2 must check the WSDL fully of that respective Magento, so that he can create / call messages correctly. The URL to load the WSDL of SOAP API V2 is "<your_magento_home_page_url>/api/v2_soap/index/wsdl/1".
Now coming back to your question, the type of the element "additional_attributes" is "associativeArray", which means its XML should look something like:-
<additional_attributes>
<!--
This XML tag "item" can be anything;
it's what I use, but can definitely be any other valid non-used literal.
-->
<item>
<key>attribute_1_code</key>
<value>attribute_1_value_as_defined_in_database</value>
</item>
<item>
<key>attribute_2_code</key>
<value>attribute_2_value_as_defined_in_database</value>
</item>
</additional_attributes>
One example of the above XML format will be:-
<additional_attributes>
<item>
<key>color</key>
<!--
I haven't provided the name / string "Blue",
because Magento's EAV database structure will only hold the option value
(which is a unique ID) and not the option literal string.
-->
<value>56</value> <!-- assuming this value for "Blue" color -->
</item>
<item>
<key>manufacturer</key>
<value>87</value> <!-- assuming this value for the manufacturer "Intel" -->
</item>
</additional_attributes>
So, your "$productData" variable must hold the values like this:-
$productData
(
[name] => testname
[description] => testdescription
[short_description] => shorttestdescription
[weight] => 70
[status] => 1
[visibility] => 4
[price] => 359.0
[tax_class_id] => 2
[additional_attributes] => Array
(
[0] => Array
(
[key] => attribute1
[value] => 999.0
)
[1] => Array
(
[key] => attribute2
[value] => testcontent
)
)
)
Hope it helps.
stroisi is almost completely correct. Just one fix to that answer:
the third condition you added will evaluate to true for the first two conditions too (thus adding those attributes twice in case you're using SOAPv2 in non-WSI-compliant mode).
That condition chain should look like this:
// ...
if (property_exists($productData->additional_attributes, 'single_data')) {
foreach ($productData->additional_attributes->single_data as $_attribute) {
$_attrCode = $_attribute->key;
$productData->$_attrCode = $_attribute->value;
}
}
if (property_exists($productData->additional_attributes, 'multi_data')) {
foreach ($productData->additional_attributes->multi_data as $_attribute) {
$_attrCode = $_attribute->key;
$productData->$_attrCode = $_attribute->value;
}
}
else if (! property_exists($productData->additional_attributes, 'single_data')) {
foreach ($productData->additional_attributes as $key => $value) {
$productData->$key = $value;
}
}
// ...
The third condition asserts that both 'single_data' and 'multi_data' are not properties of additional_attributes.
Though, in my opinion, the correct way to fix this bug is to edit the "wsi.xml" file so it is consistent with wsdl.xml (or vice versa).
I am using SOAP API for entering products in magento shops.
here is the full code
In the case of multiselect custom attribute.
$arrProductTime = explode(',', '136,139');
$result = $client->catalogProductCreate($session, 'simple', $attributeSet->set_id, 'product_sku1234', array(
'categories' => array(36),
'websites' => array(1),
'name' => 'my_pdt1008',
'description' => 'my_pdt1',
'short_description' => 'my_pdt1000',
'weight' => '11',
'status' => '1',
'url_key' => 'product-url-key1',
'url_path' => 'product-url-path1',
'visibility' => '4',
'price' => '100',
'tax_class_id' => 1,
'meta_title' => 'Product meta title1',
'meta_keyword' => 'Product meta keyword1',
'meta_description' => 'Product meta description1',
'stock_data' => array('qty'=>'100','is_in_stock'=>1,'manage_stock'=>1),
'additional_attributes' => array('multi_data' => array(array('key' => 'product_time', 'value' => $arrProductTime)))
));
Everyone, I spent a good amount of time while creating a product with multi_data additional attribute. Well finally I managed it to work with the following packet:
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
<x:Header/>
<x:Body>
<urn:catalogProductCreate>
<urn:sessionId>fa6c91d36b1fbef209b3724cf0e3b188</urn:sessionId>
<urn:type>simple</urn:type>
<urn:set>4</urn:set>
<urn:sku>147823691</urn:sku>
<urn:productData>
<urn:categories></urn:categories>
<urn:websites></urn:websites>
<urn:name>sample product-ntz-9May</urn:name>
<urn:description>sample product-ntz-8May</urn:description>
<urn:short_description>sample product-ntz-8May</urn:short_description>
<urn:weight>?</urn:weight>
<urn:status>1</urn:status>
<urn:url_key>?</urn:url_key>
<urn:url_path>?</urn:url_path>
<urn:visibility>?</urn:visibility>
<urn:category_ids></urn:category_ids>
<urn:website_ids></urn:website_ids>
<urn:has_options>?</urn:has_options>
<urn:gift_message_available>?</urn:gift_message_available>
<urn:price>?</urn:price>
<urn:tax_class_id>?</urn:tax_class_id>
<urn:tier_price></urn:tier_price>
<urn:meta_title>?</urn:meta_title>
<urn:meta_keyword>?</urn:meta_keyword>
<urn:meta_description>?</urn:meta_description>
<urn:custom_design>?</urn:custom_design>
<urn:custom_layout_update>?</urn:custom_layout_update>
<urn:options_container>?</urn:options_container>
<urn:additional_attributes>
```<urn:multi_data>
<item>
<key>cert</key>
<value>
<item>12300</item>//keys of multiselect dropdown
<item>201690</item>
</value>
</item>
</urn:multi_data>```
<urn:single_data>
<item>
<key>finish</key>
<value>22534</value>
</item>
</urn:single_data>
</urn:additional_attributes>
<urn:stock_data>
<urn:qty>?</urn:qty>
<urn:is_in_stock>0</urn:is_in_stock>
<urn:manage_stock>0</urn:manage_stock>
<urn:use_config_manage_stock>0</urn:use_config_manage_stock>
<urn:min_qty>0</urn:min_qty>
<urn:use_config_min_qty>0</urn:use_config_min_qty>
<urn:min_sale_qty>0</urn:min_sale_qty>
<urn:use_config_min_sale_qty>0</urn:use_config_min_sale_qty>
<urn:max_sale_qty>0</urn:max_sale_qty>
<urn:use_config_max_sale_qty>0</urn:use_config_max_sale_qty>
<urn:is_qty_decimal>0</urn:is_qty_decimal>
<urn:backorders>0</urn:backorders>
<urn:use_config_backorders>0</urn:use_config_backorders>
<urn:notify_stock_qty>0</urn:notify_stock_qty>
<urn:use_config_notify_stock_qty>0</urn:use_config_notify_stock_qty>
</urn:stock_data>
</urn:productData>
<urn:storeView>0</urn:storeView>
</urn:catalogProductCreate>
</x:Body>
</x:Envelope>
Hope it will save someone's time.

Categories

Resources