# Order ändern per API

**URL:** <https://forum.shopware.com/t/order-andern-per-api/59185>\
**Category:** Programmierung\
**Created:** [22. April 2019 um 20:56 UTC](https://forum.shopware.com/t/order-andern-per-api/59185 "2019-04-22T20:56:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nu\_81](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@nu\_81](https://forum.shopware.com/u/nu_81)\
**Post date:** [22. April 2019 um 20:56 UTC](https://forum.shopware.com/t/order-andern-per-api/59185/1 "2019-04-22T20:56:46Z")

</div>

Hallo,

ich versuche über eine C# Implementierung den Trackingcode und den Bestellstatus zu verändern.

Ich bekomme immer die&nbsp;Response zurück: success":true,„data“:{„id“:2,„location“:"http:\/\/localhost\/shopware5\/api\/orders\/2\

Die Bestellung wird jedoch nicht verändert.

Habe nun versucht das ganze per Restlet zu machen um zu prüfen ob es an der Programmierung liegt.

Dies hier „[http://localhost/shopware5/api/orders/2?orderStatusId=7](http://localhost/shopware5/api/orders/2?orderStatusId=7)“ liefert auch wieder eine&nbsp;positive Antwort ohne das die Bestellung geändert wird:&nbsp;(„success“:true,„data“:{„id“:2,„location“:„[http://localhost/shopware5/api/orders/2](http://localhost/shopware5/api/orders/2)“).

&nbsp;

Habe es nun per curl hiermit versucht:

```
curl -X PUT --digest --user ApiUser:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --header "Content-Type: application/json; charset=utf-8" --data '{"trackingCode":"4711", "comment":"API Kommentar"}' http://localhost/shopware5/api/orders/2

```

Dabei bekomme ich folgenden Fehler:

curl: (3) [globbing] unmatched close brace/bracket in column 24  
{„success“:false,„message“:„Invalid method or invalid json string.“}

&nbsp;

Es wäre nett wenn mich jemand mal auf den richtigen Weg schubsen könnte, bzw. mir sagen könnte über welches Log, etc. ich weiterführende Informationen zu meinen Request erhalten kann.

Vielen Dank!

---

<div class="post-metadata">

**Author:** ![ahmadsaad](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@ahmadsaad](https://forum.shopware.com/u/ahmadsaad)\
**Post date:** [23. April 2019 um 18:00 UTC](https://forum.shopware.com/t/order-andern-per-api/59185/2 "2019-04-23T18:00:31Z")

</div>

Hallo @nu\_81‍,

über C# Request kannst du Ihre Code eitragen, damit kann man weiß was ist das Probleme hier.

über&nbsp;[http://localhost/shopware5/api/orders/2?orderStatusId=7](http://localhost/shopware5/api/orders/2?orderStatusId=7)&nbsp;es würde in jeden fall nicht funktioniert weil PUT Aktion benutzen das POST data nicht GET data.

über Ihre Curl request dass ist ein bekannte Probleme mit Json Data in inline Request schaue mal :

[https://stackoverflow.com/questions/7172784/how-do-i-post-json-data-with-curl-from-a-terminal-commandline-to-test-spring-res](https://stackoverflow.com/questions/7172784/how-do-i-post-json-data-with-curl-from-a-terminal-commandline-to-test-spring-res)

[https://stackoverflow.com/questions/18314796/couchdb-curl-windows-command-line-invalid-json](https://stackoverflow.com/questions/18314796/couchdb-curl-windows-command-line-invalid-json)

VG,

Tel.: +49 755&nbsp;- 183 990 00 | Web:&nbsp;[http://enbit.de/](http://enbit.de/)

---

<div class="post-metadata">

**Author:** ![nu\_81](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@nu\_81](https://forum.shopware.com/u/nu_81)\
**Post date:** [23. April 2019 um 19:47 UTC](https://forum.shopware.com/t/order-andern-per-api/59185/3 "2019-04-23T19:47:22Z")

</div>

> über&nbsp;[http://localhost/shopware5/api/orders/2?orderStatusId=7](http://localhost/shopware5/api/orders/2?orderStatusId=7)&nbsp;es würde in jeden fall nicht funktioniert weil PUT Aktion benutzen das POST data nicht GET data.

> Hier habe ich aber als Methode Put eingestellt:
> 
> ![](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/2X/d/da615eed3f3099cf7bc185cffb1fa3cfbe32f813.png)

Ich würde gerne außerhalb von C# das ganze&nbsp; laufen lassen um zu schauen ob es überhaupt funktioniert und nicht irgendetwas blockiert, o.ä.

Finde es aber auch ehrlich gesagt unfassbar, dass ein success Return kommt, aber nichts passiert und scheinbar auch nirgendwo etwas protokolliert, bzw. ein Fehler ausgegeben wird…

---

<div class="post-metadata">

**Author:** ![nu\_81](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@nu\_81](https://forum.shopware.com/u/nu_81)\
**Post date:** [23. April 2019 um 20:29 UTC](https://forum.shopware.com/t/order-andern-per-api/59185/4 "2019-04-23T20:29:28Z")

</div>

```
public class Order
{
  private int? id;
  private int number;
..
  private int orderStatusId;
  private string trackingCode;
..

  public int? Id
  {
    get { return this.id; }
    set { this.id = value; }
  }

  public int Number
  {
    get { return this.number; }
    set { this.number = value; }
  }
}

public class Put
{
  RestClient client = new RestClient("http://localhost/shopware5/api");
  client.Authenticator = new DigestAuthenticator("ApiUser", "xxxxxxxxxxxxxxxxxxx");

  string id = 2;
  Order orderNew = new Order();
  
  orderNew.OrderStatusId = 7;
  orderNew.Comment = "Ueber API";
  orderNew.TrackingCode = "4711";

  String json = JsonConvert.SerializeObject(orderNew, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });

  List> parameters = new List>();
  parameters.Add(new KeyValuePair("id", id));

  var request = new RestRequest("orders/{id}", Method.PUT);
  request.RequestFormat = DataFormat.Json;

  foreach (KeyValuePair parameter in parameters)
  {
    request.AddUrlSegment(parameter.Key, parameter.Value); 
  }

  request.AddParameter("application/json; charset=utf-8", json, ParameterType.RequestBody);

  IRestResponse response = client.Execute(request);

  string content = response.Content;
  //{\"success\":true,\"data\":{\"id\":2,\"location\":\"http:\\/\\/localhost\\/shopware5\\/api\\/orders\\/2\"}}
  

  
  
  

}

```

Dies ist der C# Code (vereinfacht).

Die Put Methode liefert eine success Meldung, es wird jedoch keine Änderung an der Bestellung ausgeführt.

&nbsp;

---

<div class="post-metadata">

**Author:** ![ahmadsaad](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@ahmadsaad](https://forum.shopware.com/u/ahmadsaad)\
**Post date:** [24. April 2019 um 12:51 UTC](https://forum.shopware.com/t/order-andern-per-api/59185/5 "2019-04-24T12:51:45Z")

</div>

> [@nu\_81 schrieb:](https://forum.shopware.com/profile/31368/nu_81 "nu\_81")
> 
> > über&nbsp;[http://localhost/shopware5/api/orders/2?orderStatusId=7](http://localhost/shopware5/api/orders/2?orderStatusId=7)&nbsp;es würde in jeden fall nicht funktioniert weil PUT Aktion benutzen das POST data nicht GET data.
> 
> > Hier habe ich aber als Methode Put eingestellt:
> > 
> > [![image](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/2X/d/da615eed3f3099cf7bc185cffb1fa3cfbe32f813.png)](https://i.imgur.com/YHLFvMI.png)
> 
> Ich würde gerne außerhalb von C# das ganze&nbsp; laufen lassen um zu schauen ob es überhaupt funktioniert und nicht irgendetwas blockiert, o.ä.
> 
> Finde es aber auch ehrlich gesagt unfassbar, dass ein success Return kommt, aber nichts passiert und scheinbar auch nirgendwo etwas protokolliert, bzw. ein Fehler ausgegeben wird…

&nbsp;

Hallo @nu_81,

ich meine das Putaction funktion beim Shopware accept the data , die in $\_POST also &nbsp;das RequestBoday und nicht die Data kommt von $\_GET (querystring), deshalb er hat deine ‚orderStatusId‘&nbsp; value ignoriert .  
&nbsp;

VG,

Tel.: +49 755&nbsp;- 183 990 00 | Web:&nbsp;[http://enbit.de/](http://enbit.de/)

---

<div class="post-metadata">

**Author:** ![ahmadsaad](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@ahmadsaad](https://forum.shopware.com/u/ahmadsaad)\
**Post date:** [24. April 2019 um 12:56 UTC](https://forum.shopware.com/t/order-andern-per-api/59185/6 "2019-04-24T12:56:31Z")

</div>

> [@nu\_81 schrieb:](https://forum.shopware.com/profile/31368/nu_81 "nu\_81")
> 
> public class Order  
> {  
> private int? id;  
> private int number;  
> …  
> private int orderStatusId;  
> private string trackingCode;  
> …
> 
> public int? Id  
> {  
> get { return this.id; }  
> set { this.id = value; }  
> }
> 
> public int Number  
> {  
> get { return this.number; }  
> set { this.number = value; }  
> }  
> }
> 
> public class Put  
> {  
> RestClient client = new RestClient(„[http://localhost/shopware5/api](http://localhost/shopware5/api)“;  
> client.Authenticator = new DigestAuthenticator(„ApiUser“, „xxxxxxxxxxxxxxxxxxx“);
> 
> string id = 2;  
> Order orderNew = new Order();
> 
> orderNew.OrderStatusId = 7;  
> orderNew.Comment = „Ueber API“;  
> orderNew.TrackingCode = „4711“;
> 
> String json = JsonConvert.SerializeObject(orderNew, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
> 
> List\> parameters = new List\>();  
> parameters.Add(new KeyValuePair(„id“, id));
> 
> var request = new RestRequest(„orders/{id}“, Method.PUT);  
> request.RequestFormat = DataFormat.Json;
> 
> foreach (KeyValuePair parameter in parameters)  
> {  
> request.AddUrlSegment(parameter.Key, parameter.Value);  
> }
> 
> request.AddParameter(„application/json; charset=utf-8“, json, ParameterType.RequestBody);
> 
> IRestResponse response = client.Execute(request);
> 
> string content = response.Content;  
> //{"success":true,"data":{"id":2,"location":"http:\/\/localhost\/shopware5\/api\/orders\/2"}}
> 
> }
> 
> Dies ist der C# Code (vereinfacht).
> 
> Die Put Methode liefert eine success Meldung, es wird jedoch keine Änderung an der Bestellung ausgeführt.
> 
> &nbsp;

&nbsp;

&nbsp;

also ich bin nicht ein C# Programmierer aber wie ich sehe Ihre Json werde wie so gezeigt:

&nbsp;

```
{
  "OrderStatusId": 7,
  "Comment": "Ueber API",
  "TrackingCode": "4711",
  "Number": 0
}

```

&nbsp; bitte überprüfen ob es ist wie so , dann Ihre probleme ist mit die erste Buchstaben.

Shopware Api code wartet auf ‚ **o** rderStatusId‘ nicht ‚ **O** rderStatusId‘

bitte Überprüfen und gib mir Bescheid , ob es ist das Probleme , dann vielleicht ich darf C# lernen&nbsp; ![Wink](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/b3785da0cbf2c8566cb535dcf55b2730b5224899.png "Wink").

VG,

Tel.: +49 755&nbsp;- 183 990 00 | Web:&nbsp;[http://enbit.de/](http://enbit.de/)

---

<div class="post-metadata">

**Author:** ![nu\_81](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@nu\_81](https://forum.shopware.com/u/nu_81)\
**Post date:** [25. April 2019 um 20:18 UTC](https://forum.shopware.com/t/order-andern-per-api/59185/7 "2019-04-25T20:18:25Z")

</div>

Hallo&nbsp;ahmadsaad,

vielen Dank, genau das war es.

In C# muss natürlich auch auf die klein/groß Schreibung geachtet werden.

Das hat mein Problem gelöst.

Gruß
