Create Configuration Service with Class Object as Parameter

Hi Community,

 

I have created a POST API which accepts class object as parameter. Below is my code.

 

 

When I tested my API using Postman, I am getting Object Reference Error.

 

 

Any idea, what's wrong with my code? In academy I cannot find any example of configuration service which accepts class object as parameter.

 

Thank you so much

Like 0

Like

4 comments

Hi Fulgen,

 

It usually means that the problem is somewhere with the UserConnection. Can you please also check the application logs at the moment of issue reproduce? Maybe they contain more information on this topic?

 

Best regards,

Oscar

Fulgen,

You also need to add the [DataContract] attribute to the class you're passing/returning (the ActivityRequest and Activity classes) 

Ryan

Ryan Farley,

 Hi Ryan, Thank you for your reply.

 

I tried to put [DataContract] and [DataMember] attribute on my object classes but still the same error I am getting. 

Fulgen Ninofranco,

Fulgen, I believe your issue is how you're passing the body to the service. Since the method takes a single parameter named "activityRequest" which is an object, the body should look like this:

{
    "activityRequest": {
        "DepartmentId": "the id here",
        "StatusId": "the id here"
    }
}

This way, the parameter of activityRequest will be filled with the object containing the two values of DepartmentId and StatusId. The way you're passing the body in now, it is assuming there are two parameters, one named DepartmentId and one named StatusId, so when you try to use the activityRequest properties the object is null.

Ryan

Show all comments