Rest-API Post Order

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

Herzlichen Dank für eure Hilfe!

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

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

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

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,
              ]
             ],
...

 

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 
 

{"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

 

Deine Daten konnte ich mit den oben beschriebenen Änderungen problemlos (Shopware 5.5.8) 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
    ];

 

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!

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.

1 „Gefällt mir“

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ß:
 

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!