Apex Restを作っていてJson の値をポストした時のエラーです。
{
"subject" : "Wingo Ducks",
"Description" : "707-555-1234",
"TaskSubtype" : "Task",
"OwnerName" : "Wingo Ducks",
"Status" : "Completed",
"Date ActivityDate" : "2024-12-18",
"supplier_code" : "10005"
"customer_code" : null,
}
400エラーですね
[{"message":"Unexpected parameter encountered during deserialization: subject at [line:3, column:16]","errorCode":"JSON_PARSER_ERROR"}]
以下の例をみると... icって定義がありますね。
https://developer.salesforce.com/docs/atlas.ja-jp.apexcode.meta/apexcode/apex_rest_methods.htm
もしかして、calss名を追加する?
{
Body053 :{
"subject" : "Wingo Ducks",
"Description" : "707-555-1234",
"TaskSubtype" : "Task",
"OwnerName" : "Wingo Ducks",
"Status" : "Completed",
"Date ActivityDate" : "2024-12-18",
"supplier_code" : "10005"
"customer_code" : null,
}
}
エラーは変わらずです。
もしかしてb53aの変数と一緒にしないといけないのかな?
@HttpPost
global static string doPost(Body053 b53a){
system.debug(Logginglevel.INFO,'==========> '+ b53a);
{
b53a :{
"subject" : "Wingo Ducks",
"Description" : "707-555-1234",
"TaskSubtype" : "Task",
"OwnerName" : "Wingo Ducks",
"Status" : "Completed",
"Date ActivityDate" : "2024-12-18",
"supplier_code" : "10005"
"customer_code" : null,
}
}
エラーが変わりました。あっ、日付型のところの項目名がおかしい
[{"message":"Unknown field: CreateTaskRESTAPI.Body053.Date ActivityDate at [line:8, column:26]","errorCode":"JSON_PARSER_ERROR"}]
"Date ActivityDate" --> "ActivityDate" に変更
[{"message":"Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries at [line:10, column:4]","errorCode":"JSON_PARSER_ERROR"}]
"10005"の後にカンマが無いな。
無事に解決です。思ったより悩みました。
List型に対応させる
@HttpPost
global static string doPost(List<Body053> b53List){
system.debug(Logginglevel.INFO,'==========> '+ b53List);
Postするデータは以下のフォーマット
{
"b53List" :[{
"subject" : "Wingo Ducks",
"Description" : "707-555-1234",
"TaskSubtype" : "Task",
"OwnerName" : "Wingo Ducks",
"Status" : "Completed",
"ActivityDate" : "2024-12-18",
"supplier_code" : "10005",
"customer_code" : null
},
{
"subject" : "Wingo Ducks2",
"Description" : "707-555-1234",
"TaskSubtype" : "Task",
"OwnerName" : "Wingo Ducks",
"Status" : "Completed",
"ActivityDate" : "2024-12-18",
"supplier_code" : "10005",
"customer_code" : null
}
]}