Bukimedia / PrestaSharp

CSharp .Net client library for the PrestaShop API via web service
GNU General Public License v3.0
154 stars 152 forks source link

Add Message : parameter "message" required #385

Closed cbonnaure closed 3 years ago

cbonnaure commented 4 years ago

Library Version: 1.1.0

Prestashop version: 1.6.1.5

Describe the Bug: When trying to add a message, I get the error parameter "message" required

To Reproduce:

When I try to add a message like above

message psMessage = new message();
psMessage.id_order = 7978;
psMessage.id_cart = 19037;
psMessage.id_customer = 702;
psMessage.Message = "TEST";
psMessage.Private = 0;

MessageFactory messageFactory = new MessageFactory(PrestaShopApiUrl, PrestaShopApiKey, PrestaShopApiPwd);
messageFactory.Add(psMessage);

I get the following error :

application/xml: <prestashop>
<message>
  <id_cart>19037</id_cart>
  <id_order>7978</id_order>
  <id_customer>702</id_customer>
  <Message>TEST</Message>
  <Private>0</Private>
</message>
</prestashop>
ws_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[41]]></code>
<message><![CDATA[parameter "message" required]]></message>
</error>
</errors>
</prestashop>
  HttpStatusCode: BadRequest

The problem is the first letter uppercase in "Message" that doesn't match the required XML field. The [XmlElement(ElementName = "message")] is not used to serialize entity to XML, but only to deserialize XML to entity.

At this time, I made a workaround in the "message" entity class by adding the SerializeAsAttribute attribute on the Message property

        [SerializeAsAttribute(Name = "message")]
        [XmlElement(ElementName = "message")]
        public string Message { get; set; }

and adding the next using using RestSharp.Serializers;

Does anyone know how to fix this problem into the PrestaSharpSerializer ? That way, I would no longer have to use the SerializeAsAttribute attribute and the dependency on RestSharp.Serializers.

Best regards.

SnelGrafics commented 3 years ago

I have the same error !

Library Version: 1.2.7

Prestashop version: 1.7.6.7