Hello everyone! I'm trying to make a User Defined API, but I don't know how to access the request body values correctly, i keep getting the error " 'JobData' does not contain a definition for 'workOrderId' and no accessible extension method 'workOrderId' accepting a first argument of type 'JobData' could be found (are you missing a using directive or an assembly reference?)", and the error occurs for all accessed data. What would be the correct method of accessing and manipulating this information?
Here is my code:
public class JobData
{
[JsonProperty("jobId")]
public string JobID { get; set; }
}
var requestBody = JsonConvert.DeserializeObject<JobData>(requestData.RawBody);
string primaryKey = $"{requestBody.workOrderId}/{requestBody.serviceDefinitionName}/{requestBody.serviceDefinitionGroup}";
var requestInfo = new
{
Method = requestData.RequestMethod.ToString(),
Body = new JobData {
JobID = Guid.NewGuid().ToString(),
PrimaryKey = primaryKey,
Name = requestBody.name,
WorkOrderId = requestBody.workOrderId,
StartsAt = requestBody.startsAt,
EndsAt = requestBody.endsAt,
RecurrenceType = requestBody.recurrenceType,
Site = requestBody.site,
Type = requestBody.type,
Client = requestBody.client,
ServiceDefinitionName = requestBody.serviceDefinitionName,
ServiceDefinitionGroup = requestBody.serviceDefinitionGroup
}
};
This is the body sent in the request:
{
"name": "Fight Night",
"workOrderId": "73-1",
"startsAt": "2024-11-30",
"endsAt": "2024-11-31",
"recurrenceType": "Single Shot",
"site": "ION",
"type": "Live",
"client": "Combate",
"serviceDefinitionGroup": "G",
"serviceDefinitionName": "Processor"
}
Hi João,
It looks like you try to access the properties from your 'requestData' class using the lowercase name.
Instead of calling 'requestData.workOrderId', make sure to call 'requestData.WorkOrderId', the same for other properties you call in your code.
To give some background, your JSON properties are camelCase, and C# properties are typically PascalCase. To convert these correctly, JsonProperty attributes are used where you specify the name of your JSON property, so it can be correctly translated to your C# properties. You are doing this correctly, only you have to use the PascalCase when accessing C# properties.
I also want to mention that these type of compilation errors are more easy to spot using a code editor like Visual Studio, which you can extend with DataMiner Integration Studio (DIS).
I hope this helps you further.
Hi Wouter, hope you're well! Thank you for your help, this was really the problem.