C
C#3w ago
Dachi

✅ Api request matching issue

i have this method
public async Task<ActionResult<ApiServiceResponse<CommissionDto>>> AutomaticOperationSave(
[FromBody] AutomaticOperation request, CancellationToken cancellationToken)
public async Task<ActionResult<ApiServiceResponse<CommissionDto>>> AutomaticOperationSave(
[FromBody] AutomaticOperation request, CancellationToken cancellationToken)
and then api respons comes it cannot match with the AutomaticOperation. that class extends class operation that looks like this
[DisplayName("ოპერაცია")]
public class Operation : JDateTimesAndSelectable.
[DisplayName("ოპერაცია")]
public class Operation : JDateTimesAndSelectable.
and error looks like this:
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "00-2d09e0cccda2990b5453fa03ae4749e6-03b1d5d212e40e2d-00",
"errors": {
"request": [
"The ოპერაცია field is required."
],
"$.OperationDate": [
"The JSON value could not be converted to System.DateTime. Path: $.OperationDate | LineNumber: 19 | BytePositionInLine: 42."
]
}
}
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "00-2d09e0cccda2990b5453fa03ae4749e6-03b1d5d212e40e2d-00",
"errors": {
"request": [
"The ოპერაცია field is required."
],
"$.OperationDate": [
"The JSON value could not be converted to System.DateTime. Path: $.OperationDate | LineNumber: 19 | BytePositionInLine: 42."
]
}
}
Can you please help me?
17 Replies
Dachi
Dachi3w ago
all fields in the Operation class are nullable
Salman
Salman3w ago
$code
MODiX
MODiX3w ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Salman
Salman3w ago
$codegif
Salman
Salman3w ago
Apparently the request isn't structured properly . Can you show complete AutomaticOperation class
Dachi
Dachi3w ago
sure
c#
public class AutomaticOperation : Operation
{
[LogField]
[DisplayName("ანგარიშის ნომერი")]
public int? AccountId { get; set; }

[DisplayName("ვალუტის Id")] public int? CurrencyTypeId { get; set; }

[LogField] [DisplayName("ვალუტა")] public string? CurrencyType { get; set; }

[DisplayName("ვალუტა სიტყვიერად")] public string? Currency { get; set; }

[LogField]
[FormatField(FieldTypeFormat.Decimal2)]
[DisplayName("თანხა")]
public decimal? Amount { get; set; }

[DisplayName("საკომისიოს ოპერაციის Id")]
public long? CommissionOperationId { get; set; }

[DisplayName("საკომისიოს ოპერაციის ტიპის Id")]
public int? CommissionOperationTypeId { get; set; }

[DisplayName("პროდუქტი")] public int? ProductId { get; set; }

[DisplayName("წყარო")] public int? Source { get; set; }

[DisplayName("თანხა სიტყვიერად")] public string? AmountVerbally => NumberHelper.DecimalToWord(Amount.Value, CurrencyType);

[DisplayName("დანიშნულების Id")] public int? DescriptionTypeId { get; set; }
}
c#
public class AutomaticOperation : Operation
{
[LogField]
[DisplayName("ანგარიშის ნომერი")]
public int? AccountId { get; set; }

[DisplayName("ვალუტის Id")] public int? CurrencyTypeId { get; set; }

[LogField] [DisplayName("ვალუტა")] public string? CurrencyType { get; set; }

[DisplayName("ვალუტა სიტყვიერად")] public string? Currency { get; set; }

[LogField]
[FormatField(FieldTypeFormat.Decimal2)]
[DisplayName("თანხა")]
public decimal? Amount { get; set; }

[DisplayName("საკომისიოს ოპერაციის Id")]
public long? CommissionOperationId { get; set; }

[DisplayName("საკომისიოს ოპერაციის ტიპის Id")]
public int? CommissionOperationTypeId { get; set; }

[DisplayName("პროდუქტი")] public int? ProductId { get; set; }

[DisplayName("წყარო")] public int? Source { get; set; }

[DisplayName("თანხა სიტყვიერად")] public string? AmountVerbally => NumberHelper.DecimalToWord(Amount.Value, CurrencyType);

[DisplayName("დანიშნულების Id")] public int? DescriptionTypeId { get; set; }
}
and many more fields but i cant paste cuz of restriction but if needed i can post seperatly @Salmon
Salman
Salman3w ago
why your PK which is AccountId is nullable, it shouldn't be nullable..also I don't understand those Displayname like whatever language that's. But the point is that you're getting two errors. 1.
The "ოპერაცია" (Operation) field is required, but it's not being provided in the request.
The "ოპერაცია" (Operation) field is required, but it's not being provided in the request.
2.
The "OperationDate" field is not being parsed correctly as a DateTime value.
The "OperationDate" field is not being parsed correctly as a DateTime value.
Dachi
Dachi3w ago
fotger OPerationDate for now forget* i am curios about the Operation error cuz the displaymethod is just the naming and error comes from it it says though
Salman
Salman3w ago
Have you checked your class if Operation is nullable and not required ?
Dachi
Dachi3w ago
if class is nullable? how is that
Salman
Salman3w ago
nope that ოპერაცია property
Dachi
Dachi3w ago
that is just a name nothing more and its on top of a class not a filed
Salman
Salman3w ago
it's not only name, the error is saying that it's a field the class will get this name that you specified on the top of it
Dachi
Dachi3w ago
yeah wait i'll check something
Salman
Salman3w ago
so you need to pass this field in the request object as well with that name that you specified match the request with the request object that api is expecting and see what are you missing
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server
More Posts