cancel
Showing results for 
Search instead for 
Did you mean: 

FIXED: How to create Sales Order with multiple Line Items through the API

SOLVED

FIXED: How to create Sales Order with multiple Line Items through the API

I am attempting to create a Sales Order thru the API. The client is using Magento and SweetTooth. I am needing to add Sales Orders created outside of Magento in order to allcoate Loyalty Points.

 

I have the basic structure correct & a valid Sales Order is being created in MAgento & SweetTooth is allocating Loyalty Points. When I have a single 'Item Ordered' it is correctly added & the Order Total is correct even when I have Qty greater than 1.

 

1/- The bit I need help with is getting a second 'Item Ordered' added. I am passing it in the XML but it is being ignored without error. The response from Magento is that the Sales Order has been successfully created.

 

2/- there is a Map declaration with what looks like a size (NS2:Map[6] that I have set to be the number of following items but only guessing at this part

 

3/- what does the integer at the very end of the message control?

 

************

What is the correction I need to this XML to have the second Ordered Item added?

(this is the fragment that is not working)

<item>
  <key xsi:type="xsd:string">products</key>
  <value SOAP-ENC:arrayType="ns2:Map[6]" xsi:type="SOAP-ENC:Array">  <!-- what size does the Map need to be??? -->
    <item xsi:type="ns2:Map">
      <item>
        <key xsi:type="xsd:string">sku</key>
        <value xsi:type="xsd:string">10000703508 </value>
      </item>
    <item>
    <key xsi:type="xsd:string">qty</key>
    <value xsi:type="xsd:int">3</value>
  </item> 
  <item>
    <key xsi:type="xsd:string">price</key>
    <value xsi:type="xsd:float">127.2609</value>
  </item>
  <item>
    <key xsi:type="xsd:string">sku</key>
    <value xsi:type="xsd:string">50000001159 </value>
  </item>
  <item>
    <key xsi:type="xsd:string">qty</key>
    <value xsi:type="xsd:int">3</value>
  </item> 
  <item>
    <key xsi:type="xsd:string">price</key>
    <value xsi:type="xsd:float">31.8173</value>
  </item>
  </item>
  </value>
</item>

 

 


**************

This is the complete XML message being sent::

 

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlnsSmiley FrustratedOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlnsSmiley FrustratedOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://xml.apache.org/xml-soap" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:call>
<sessionId xsi:type="xsd:string">bbb6463d51430436fadb05cff8d29f14</sessionId>
<resourcePath xsi:type="xsd:string">customapi_order.create</resourcePath>
<args SOAP-ENC:arrayType="xsd:ur-type[2]" xsi:type="SOAP-ENC:Array">
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">customer</key>
<value xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">email</key>
<value xsi:type="xsd:string">name@domain.com</value>
</item>
<item>
<key xsi:type="xsd:string">shipping_address</key>
<value xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">first_name</key>
<value xsi:type="xsd:string">First Name</value>
</item>
<item>
<key xsi:type="xsd:string">last_name</key>
<value xsi:type="xsd:string">Last Name</value>
</item>
<item>
<key xsi:type="xsd:string">street</key>
<value xsi:type="xsd:string">Street</value>
</item>
<item>
<key xsi:type="xsd:string">city</key>
<value xsi:type="xsd:string">City</value>
</item>
<item>
<key xsi:type="xsd:string">region</key>
<value xsi:type="xsd:string">Region</value>
</item>
<item>
<key xsi:type="xsd:string">postcode</key>
<value xsi:type="xsd:string">Postcode</value>
</item>
<item>
<key xsi:type="xsd:string">telephone</key>
<value xsi:type="xsd:string">Telephone</value>
</item>
<item>
<key xsi:type="xsd:string">country_id</key>
<value xsi:type="xsd:string">Country ID</value>
</item>
</value>
</item>
<item>
<key xsi:type="xsd:string">billing_address</key>
<value xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">first_name</key>
<value xsi:type="xsd:string">First Name</value>
</item>
<item>
<key xsi:type="xsd:string">last_name</key>
<value xsi:type="xsd:string">Last Name</value>
</item>
<item>
<key xsi:type="xsd:string">street</key>
<value xsi:type="xsd:string">Street</value>
</item>
<item>
<key xsi:type="xsd:string">city</key>
<value xsi:type="xsd:string">City</value>
</item>
<item>
<key xsi:type="xsd:string">region</key>
<value xsi:type="xsd:string">Region</value>
</item>
<item>
<key xsi:type="xsd:string">postcode</key>
<value xsi:type="xsd:string">Postcode</value>
</item>
<item>
<key xsi:type="xsd:string">telephone</key>
<value xsi:type="xsd:string">Telephone</value>
</item>
<item>
<key xsi:type="xsd:string">country_id</key>
<value xsi:type="xsd:string">Country ID</value>
</item>
</value>
</item>
</value>
</item>
<item>
<key xsi:type="xsd:string">products</key>
<value SOAP-ENC:arrayType="ns2:Map[6]" xsi:type="SOAP-ENC:Array">
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">sku</key>
<value xsi:type="xsd:string">10000703508 </value>
</item>
<item>
<key xsi:type="xsd:string">qty</key>
<value xsi:type="xsd:int">3</value>
</item>
<item>
<key xsi:type="xsd:string">price</key>
<value xsi:type="xsd:float">127.2609</value>
</item>
<item>
<key xsi:type="xsd:string">sku</key>
<value xsi:type="xsd:string">50000001159 </value>
</item>
<item>
<key xsi:type="xsd:string">qty</key>
<value xsi:type="xsd:int">3</value>
</item>
<item>
<key xsi:type="xsd:string">price</key>
<value xsi:type="xsd:float">31.8173</value>
</item>
</item>
</value>
</item>
<item>
<key xsi:type="xsd:string">payment</key>
<value xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">payment_type</key>
<value xsi:type="xsd:string">SK</value>
</item>
<item>
<key xsi:type="xsd:string">transaction_id</key>
<value xsi:type="xsd:string">gngr94</value>
</item>
<item>
<key xsi:type="xsd:string">amount_paid</key>
<value xsi:type="xsd:string">454.97</value>
</item>
<item>
<key xsi:type="xsd:string">payment_date</key>
<value xsi:type="xsd:string">7/28/2015 12:15:38 PM</value>
</item>
</value>
</item>
<item>
<key xsi:type="xsd:string">misc_data</key>
<value xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">Other System Order Number</key>
<value xsi:type="xsd:string">1640</value>
</item>
</value>
</item>
</item>
<item xsi:type="xsd:int">1</item>  <!-- what's this do??? -->
</args>
</ns1:call>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

 

 

Tags (1)
2 REPLIES

Re: How to create Sales Order with multiple Line Items through the API

Moderator's Note: I've edited your post to remove any sensitive or personal information of the user. 

James Lee | Moderator • Magento Master
See My Recommended Magento Hosting & Security Tips

FIXED: How to create Sales Order with multiple Line Items through the API

Each of the Ordered Items needs to be contained in a separte Map:

 

<item>
  <key xsi:type="xsd:string">products</key>
  <value SOAP-ENC:arrayType="ns2:Map[2]" xsi:type="SOAP-ENC:Array">
    <item xsi:type="ns2:Map">
      <item>
        <key xsi:type="xsd:string">sku</key>
        <value xsi:type="xsd:string">10000703508 </value>
      </item>
    <item>
      <key xsi:type="xsd:string">qty</key>
      <value xsi:type="xsd:int">3</value>
    </item> 
    <item>
      <key xsi:type="xsd:string">price</key>
      <value xsi:type="xsd:float">127.2609</value>
    </item>
  </item>
  <item xsi:type="ns2:Map">
    <item>

      <key xsi:type="xsd:string">sku</key>
      <value xsi:type="xsd:string">50000001159 </value>
    </item>
    <item>
      <key xsi:type="xsd:string">qty</key>
      <value xsi:type="xsd:int">3</value>
    </item> 
    <item>
      <key xsi:type="xsd:string">price</key>
      <value xsi:type="xsd:float">31.8173</value>
    </item>
  </item>
  </value>
</item>