# Rest-API Post Order

**URL:** <https://forum.shopware.com/t/rest-api-post-order/59739>\
**Category:** Programmierung\
**Created:** [27. Mai 2019 um 11:46 UTC](https://forum.shopware.com/t/rest-api-post-order/59739 "2019-05-27T11:46:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rtuzth](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rtuzth](https://forum.shopware.com/u/rtuzth)\
**Post date:** [27. Mai 2019 um 11:46 UTC](https://forum.shopware.com/t/rest-api-post-order/59739/1 "2019-05-27T11:46:08Z")

</div>

Hi,  
ich schraube mit wachsender Verzweiflung an einem kleinen Ruby-Wrapper für die Api. Leider scheitere ich trotz Copy-Paste der Doku Beispiele daran eine Bestellung anzulegen. So versuche ich die Bestellung anzulegen:

```
require 'httparty'
require 'pp'

class SwApiWrapper

  include HTTParty
  base_uri '192.168.33.10/shopware/api'
  digest_auth 'root', 'key'

  def post_order()
    self.class.post('/orders', :body => {'customerId' => 1,
                                         'paymentId' => 4,
                                         'dispatchId' => 9,
                                         'partnerId' => '',
                                         'shopId' => 1,
                                         'invoiceAmount' => 201.86,
                                         'invoiceAmountNet' => 169.63,
                                         'invoiceShipping' => 0,
                                         'invoiceShippingNet' => 0,
                                         'orderTime' => '2012-08-31 08:51:46',
                                         'net' => 0,
                                         'taxFree' => 0,
                                         'languageIso' => '1',
                                         'currency' => 'EUR',
                                         'currencyFactor' => 1,
                                         'remoteAddress' => '192.168.33.10',
                                         'details' => [
                                                           'articleId' => 2,
                                                           'taxId' => 1,
                                                           'taxRate' => 19,
                                                           'statusId' => 0,
                                                           'articleNumber' => 'SW10002.3',
                                                           'price' => 35.99,
                                                           'quantity' => 1,
                                                           'articleName' => 'Versandkostenfreier Artikel',
                                                           'shipped' => 0,
                                                           'shippedGroup' => 0,
                                                           'mode' => 0,
                                                           'esdArticle' => 0,
                                                       ],
                                         'documents' => [],
                                         'billing' => [
                                             'id' => 2,
                                             'customerID' => 1,
                                             'countryID' => 2,
                                             'stateId' => 3,
                                             'company' => 'shopware AG',
                                             'salutation' => 'mr',
                                             'firstName' => 'Max',
                                             'lastName' => 'Mustermann',
                                             'street' => 'Mustermannstra\u00dfe 92',
                                             'zipCode' => '48624',
                                             'city' => 'Sch\u00f6ppingen',
                                         ],
                                         'shipping' => [
                                             'id' => 2,
                                             'countryId' => 2,
                                             'stateId' => 3,
                                             'customerId' => 1,
                                             'company' => 'shopware AG',
                                             'salutation' => 'mr',
                                             'firstName' => 'Max',
                                             'lastName' => 'Mustermann',
                                             'street' => 'Mustermannstra\u00dfe 92',
                                             'zipCode' => '48624',
                                             'city' => 'Sch\u00f6ppingen'
                                         ],
                                         'paymentStatusId' => 17,
                                         'orderStatusId' => 0
                                            }.to_json)
  end
end

```

Leider bekomme ich obwohl die countryID im Billing eindeutig gesetzt wird dies zurück:

```
{"success"=>false,
 "code"=>400,
 "message"=>"A required parameter is missing: billing.countryId"}

```

Was mache ich hier falsch? Der Datensatz kommt wie gesagt aus der Doku:  
[https://developers.shopware.com/developers-guide/rest-api/examples/order/#search-results](https://developers.shopware.com/developers-guide/rest-api/examples/order/#search-results)

Herzlichen Dank für eure Hilfe!

---

<div class="post-metadata">

**Author:** ![Jumpstep](https://avatars.discourse-cdn.com/v4/letter/j/9fc348/32.png) [@Jumpstep](https://forum.shopware.com/u/Jumpstep)\
**Post date:** [27. Mai 2019 um 16:43 UTC](https://forum.shopware.com/t/rest-api-post-order/59739/2 "2019-05-27T16:43:44Z")

</div>

Der Key muss&nbsp;“countryId” und nicht “countryI **D** ” heissen, sonst wird die Exception geworfen. “customerI **D** ” sollte auch in&nbsp;“customerId” umbenannt werden.

---

<div class="post-metadata">

**Author:** ![rtuzth](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rtuzth](https://forum.shopware.com/u/rtuzth)\
**Post date:** [27. Mai 2019 um 22:39 UTC](https://forum.shopware.com/t/rest-api-post-order/59739/3 "2019-05-27T22:39:30Z")

</div>

Hi,

vielen Dank für deine Hilfe. Leider bekomme ich egal in welcher Schreibweise den gleichen Fehler - ich war auf diesen Thread gestoßen:  
[https://forum.shopware.com/discussion/38017/sw-5-2-api-kundenimport-country](https://forum.shopware.com/discussion/38017/sw-5-2-api-kundenimport-country)

und hatte daher mit mannigfaltigen Schreibweisen von country, countryID,… gespielt, hatte vergessen das wieder anzupassen, sorry.

---

<div class="post-metadata">

**Author:** ![Jumpstep](https://avatars.discourse-cdn.com/v4/letter/j/9fc348/32.png) [@Jumpstep](https://forum.shopware.com/u/Jumpstep)\
**Post date:** [28. Mai 2019 um 06:51 UTC](https://forum.shopware.com/t/rest-api-post-order/59739/4 "2019-05-28T06:51:14Z")

</div>

Wenn du den Key auf „countryId“ änderst, sollte aber zumindest eine andere Fehlermeldung erscheinen.

Auch wenn es sich nur um einen Artikel handelt, kann über „details“ in deinem Beispiel nicht richtig iteriert werden. Es sollte so aussehen:

```
...
'details' => [
              ['articleId' => 2,
               'taxId' => 1,
               'taxRate' => 19,
               'statusId' => 0,
               'articleNumber' => 'SW10002.3',
               'price' => 35.99,
               'quantity' => 1,
               'articleName' => 'Versandkostenfreier Artikel',
               'shipped' => 0,
               'shippedGroup' => 0,
               'mode' => 0,
               'esdArticle' => 0,
              ]
             ],
...

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![rtuzth](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rtuzth](https://forum.shopware.com/u/rtuzth)\
**Post date:** [28. Mai 2019 um 07:40 UTC](https://forum.shopware.com/t/rest-api-post-order/59739/5 "2019-05-28T07:40:58Z")

</div>

Hi,

wenn ich die details wie von dir angegeben einbinde bekomme ich tatsächlich eine neue Fehlermeldung:

```
require 'httparty'
require 'pp'

class SwApiWrapper

  include HTTParty
  base_uri '192.168.33.10/shopware/api'
  digest_auth 'sample', 'data'

  def get_orders
    self.class.get('/orders')['data']
  end

  def get_articles
    self.class.get('/articles')['data']
  end

  def get_countries
    self.class.get('/countries')
  end

  def post_order()
    self.class.post('/orders', :body => {'customerId' => 1,
                                         'paymentId' => 4,
                                         'dispatchId' => 9,
                                         'partnerId' => '',
                                         'shopId' => 1,
                                         'invoiceAmount' => 201.86,
                                         'invoiceAmountNet' => 169.63,
                                         'invoiceShipping' => 0,
                                         'invoiceShippingNet' => 0,
                                         'orderTime' => '2012-08-31 08:51:46',
                                         'net' => 0,
                                         'taxFree' => 0,
                                         'languageIso' => '1',
                                         'currency' => 'EUR',
                                         'currencyFactor' => 1,
                                         'remoteAddress' => '192.168.33.10',
                                         'details' => [
                                             ['articleId' => 2,
                                              'taxId' => 1,
                                              'taxRate' => 19,
                                              'statusId' => 0,
                                              'articleNumber' => 'SW10002.3',
                                              'price' => 35.99,
                                              'quantity' => 1,
                                              'articleName' => 'Versandkostenfreier Artikel',
                                              'shipped' => 0,
                                              'shippedGroup' => 0,
                                              'mode' => 0,
                                              'esdArticle' => 0,
                                             ]
                                                       ],
                                         'documents' => [],
                                         'billing' => [
                                             'id' => 2,
                                             'customerId' => 1,
                                             'company' => 'shopware AG',
                                             'salutation' => 'mr',
                                             'firstName' => 'Max',
                                             'lastName' => 'Mustermann',
                                             'street' => 'Mustermannstra\u00dfe 92',
                                             'zipCode' => '48624',
                                             'city' => 'Sch\u00f6ppingen',
                                             'countryId' => 2,
                                             'stateId' => 3,
                                         ],
                                         'shipping' => [
                                             'id' => 2,
                                             'countryId' => 2,
                                             'stateId' => 3,
                                             'customerId' => 1,
                                             'company' => 'shopware AG',
                                             'salutation' => 'mr',
                                             'firstName' => 'Max',
                                             'lastName' => 'Mustermann',
                                             'street' => 'Mustermannstra\u00dfe 92',
                                             'zipCode' => '48624',
                                             'city' => 'Sch\u00f6ppingen'
                                         ],
                                         'paymentStatusId' => 17,
                                         'orderStatusId' => 0
                                            }.to_json)
  end

  def get_customers
    self.class.get('/customers')['data']
  end

  def post_customer()
    self.class.post('/customers', :body => {'email' => 'meier@meiermail.de',
                                            'firstname' => 'Max',
                                            'lastname' => 'Meier',
                                            'salutation' => 'mr',
                                            'billing' => {
                                                'firstname' => 'Max',
                                                'lastname' => 'Meier',
                                                'salutation' => 'mr',
                                                'street' => 'Mustergasse 55',
                                                'city' => 'Musterstadt',
                                                'zipcode' => '12345',
                                                'country' => 2
                                            }}.to_json)
  end
end

Shopware=SwApiWrapper.new
pp Shopware.post_order

```

resultiert in&nbsp;  
&nbsp;

```
{"success"=>false, "message"=>"details.statusId"}

Process finished with exit code 0

```

Wenn ich die Details wie vorher aus der Doku übernehme und das billing so umsetze:

```
 'details' => [
                                                           'articleId' => 2,
                                                           'taxId' => 1,
                                                           'taxRate' => 19,
                                                           'statusId' => 0,
                                                           'articleNumber' => 'SW10002.3',
                                                           'price' => 35.99,
                                                           'quantity' => 1,
                                                           'articleName' => 'Versandkostenfreier Artikel',
                                                           'shipped' => 0,
                                                           'shippedGroup' => 0,
                                                           'mode' => 0,
                                                           'esdArticle' => 0,
                                                       ],
                                         'documents' => [],
                                         'billing' => [
                                             'id' => 2,
                                             'customerId' => 1,
                                             'company' => 'shopware AG',
                                             'salutation' => 'mr',
                                             'firstName' => 'Max',
                                             'lastName' => 'Mustermann',
                                             'street' => 'Mustermannstra\u00dfe 92',
                                             'zipCode' => '48624',
                                             'city' => 'Sch\u00f6ppingen',
                                             'countryId' => 2,
                                             'stateId' => 3,
                                         ],

```

bin ich wieder da wo ich angefangen habe:

```
{"success"=>false,
 "code"=>400,
 "message"=>"A required parameter is missing: billing.countryId"}

Process finished with exit code 0

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![Jumpstep](https://avatars.discourse-cdn.com/v4/letter/j/9fc348/32.png) [@Jumpstep](https://forum.shopware.com/u/Jumpstep)\
**Post date:** [28. Mai 2019 um 08:04 UTC](https://forum.shopware.com/t/rest-api-post-order/59739/6 "2019-05-28T08:04:49Z")

</div>

Deine Daten konnte ich mit den oben beschriebenen Änderungen&nbsp;problemlos (Shopware 5.5.8)&nbsp;importieren.

```
 1,
        'paymentId' => 4,
        'dispatchId' => 9,
        'partnerId' => '',
        'shopId' => 1,
        'invoiceAmount' => 201.86,
        'invoiceAmountNet' => 169.63,
        'invoiceShipping' => 0,
        'invoiceShippingNet' => 0,
        'orderTime' => '2012-08-31 08:51:46',
        'net' => 0,
        'taxFree' => 0,
        'languageIso' => '1',
        'currency' => 'EUR',
        'currencyFactor' => 1,
        'remoteAddress' => '192.168.33.10',
        'details' => [
            ['articleId' => 2,
            'taxId' => 1,
            'taxRate' => 19,
            'statusId' => 0,
            'articleNumber' => 'SW10002.3',
            'price' => 35.99,
            'quantity' => 1,
            'articleName' => 'Versandkostenfreier Artikel',
            'shipped' => 0,
            'shippedGroup' => 0,
            'mode' => 0,
            'esdArticle' => 0,
            ]
        ],
        'documents' => [],
        'billing' => [
            'id' => 2,
            'customerId' => 1,
            'countryId' => 2,
            'stateId' => 3,
            'company' => 'shopware AG',
            'salutation' => 'mr',
            'firstName' => 'Max',
            'lastName' => 'Mustermann',
            'street' => 'Mustermannstra\u00dfe 92',
            'zipCode' => '48624',
            'city' => 'Sch\u00f6ppingen',
        ],
        'shipping' => [
            'id' => 2,
            'countryId' => 2,
            'stateId' => 3,
            'customerId' => 1,
            'company' => 'shopware AG',
            'salutation' => 'mr',
            'firstName' => 'Max',
            'lastName' => 'Mustermann',
            'street' => 'Mustermannstra\u00dfe 92',
            'zipCode' => '48624',
            'city' => 'Sch\u00f6ppingen'
        ],
        'paymentStatusId' => 17,
        'orderStatusId' => 0
    ];

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![rtuzth](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rtuzth](https://forum.shopware.com/u/rtuzth)\
**Post date:** [28. Mai 2019 um 08:12 UTC](https://forum.shopware.com/t/rest-api-post-order/59739/7 "2019-05-28T08:12:01Z")

</div>

Bei mir tritt der fehler selbst bei einem curl auf:

```
curl -X POST --digest --user root:Jb9TsOZkIGnZx6NcugOauWlmemecuUWDPE7m5I8v --header "Content-Type: application/json; charset=utf-8" --data '{
> "customerId":1,"paymentId":4,"dispatchId":9,"partnerId":"","shopId":1,"invoiceAmount":201.86,"invoiceAmountNet":169.63,"invoiceShipping":0,"invoiceShippingNet":0,"orderTime":"2012-08-31 08:51:46","net":0,"taxFree":0,"languageIso":"1","currency":"EUR","currencyFactor":1,"remoteAddress":"192.168.33.10",
> "details":[{"articleId":2,"taxId":1,"taxRate":19,"statusId":0,"articleNumber":"SW10002.3","price":35.99,"quantity":1,"articleName":"Versandkostenfreier Artikel","shipped":0,"shippedGroup":0,"mode":0,"esdArticle":0}],
> "documents":[],
> "billing":[{"id":2,"customerId":1,"company":"shopware AG","salutation":"mr","firstName":"Max","lastName":"Mustermann","street":"Mustermannstra\\u00dfe 92","zipCode":"48624","city":"Sch\\u00f6ppingen","countryId":2,"stateId":3}],
> "shipping":[{"id":2,"countryId":2,"stateId":3,"customerId":1,"company":"shopware AG","salutation":"mr","firstName":"Max","lastName":"Mustermann","street":"Mustermannstra\\u00dfe 92","zipCode":"48624","city":"Sch\\u00f6ppingen"}],"paymentStatusId":17,"orderStatusId":0}
> ' http://192.168.33.10/shopware/api/orders
{"success":false,"code":400,"message":"A required parameter is missing: billing.countryId"}

```

Ich installiere mal mein Shopware neu und melde mich nochmal. Vielen Dank bis auf jeden Fall!

---

<div class="post-metadata">

**Author:** ![Jumpstep](https://avatars.discourse-cdn.com/v4/letter/j/9fc348/32.png) [@Jumpstep](https://forum.shopware.com/u/Jumpstep)\
**Post date:** [28. Mai 2019 um 08:29 UTC](https://forum.shopware.com/t/rest-api-post-order/59739/8 "2019-05-28T08:29:04Z")

</div>

Es müsste so aussehen (ohne eckige Klammern):

```
...
"billing":{"id":2,"customerId":1,"company":"shopware AG","salutation":"mr","firstName":"Max","lastName":"Mustermann","street":"Mustermannstra\\u00dfe 92","zipCode":"48624","city":"Sch\\u00f6ppingen","countryId":2,"stateId":3},
...

```

Bei “shipping” übrigens auch.

---

<div class="post-metadata">

**Author:** ![rtuzth](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rtuzth](https://forum.shopware.com/u/rtuzth)\
**Post date:** [28. Mai 2019 um 09:00 UTC](https://forum.shopware.com/t/rest-api-post-order/59739/9 "2019-05-28T09:00:22Z")

</div>

Was ein Mist, ich hatte mich blind auf .to\_json von httparty verlassen. Tausend Dank! Falls jemand durch googlen auf diesen Thread stößt, so macht es auch in Ruby Spaß:  
&nbsp;

```
require 'net/http'
require 'uri'
require 'json'
require 'pp'

uri = URI.parse("http://192.168.33.10/shopware/api/orders")
req_options = {
    use_ssl: uri.scheme == "https",
}
request = Net::HTTP::Post.new(uri)
request.basic_auth("root", "data")
request.content_type = "application/json; charset=utf-8"

request.body = JSON.dump({
                             "customerId" => 1,
                             "paymentId" => 4,
                             "dispatchId" => 9,
                             "partnerId" => "",
                             "shopId" => 1,
                             "invoiceAmount" => 20100.86,
                             "invoiceAmountNet" => 169.63,
                             "invoiceShipping" => 0,
                             "invoiceShippingNet" => 0,
                             "orderTime" => "2012-08-31 08:51:46",
                             "net" => 0,
                             "taxFree" => 0,
                             "languageIso" => "1",
                             "currency" => "EUR",
                             "currencyFactor" => 1,
                             "remoteAddress" => "192.168.33.10",
                             "details" => [
                                 {
                                     "articleId" => 2,
                                     "taxId" => 1,
                                     "taxRate" => 19,
                                     "statusId" => 0,
                                     "articleNumber" => "SW10002.3",
                                     "price" => 35.99,
                                     "quantity" => 1,
                                     "articleName" => "Versandkostenfreier Artikel",
                                     "shipped" => 0,
                                     "shippedGroup" => 0,
                                     "mode" => 0,
                                     "esdArticle" => 0
                                 }
                             ],
                             "documents" =>[],
                             "billing" => {
                                 "id" => 2,
                                 "customerId" => 1,
                                 "company" => "shopware AG",
                                 "salutation" => "mr",
                                 "firstName" => "Max",
                                 "lastName" => "Mustermann",
                                 "street" => "Mustermannstra\u00dfe 92",
                                 "zipCode" => "48624",
                                 "city" => "Sch\u00f6ppingen",
                                 "countryId" => 2,
                                 "stateId" => 3
                             },
                             "shipping" => {
                                 "id" => 2,
                                 "countryId" => 2,
                                 "stateId" => 3,
                                 "customerId" => 1,
                                 "company" => "shopware AG",
                                 "salutation" => "mr",
                                 "firstName" => "Max",
                                 "lastName" => "Musterma",
                                 "street" => "Mustermannstra\u00dfe 92",
                                 "zipCode" => "48624",
                                 "city" => "Sch\u00f6ppingen"
                             },
                             "paymentStatusId" => 17,
                             "orderStatusId" => 0
                         })

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
  http.request(request)
end
 
pp JSON.parse(response.body)

```

Nochmal danke für die Hilfe!
