SmartConnector Forum
Schneider Electric support forum about SmartConnector applications for integration of other building management systems (BMS) into EcoStruxure Building Operation.
Link copied. Please paste this link to share this article on your social media post.
I am using Sample REST Provider Class example to add my SetMode() method. This method takes three parameter RoomNum, mode and ModeChangeTime. I am able to add it in my custom REST Provider class. However, on execution of PUT method, I am getting error - "Can't bind multiple parameters'. Is multiple parameters supported ? Do I need to add some attribute [MultiPostParameters] for it to work. Is it supported in SmartrtConnector ? Please advise.
Link copied. Please paste this link to share this article on your social media post.
Hi Neeraj,
This is actually nothing to do with SmartConnector. Programming an API controller is actually just MVC ASP stuff from .NET. As you noticed I don’t think you can have multiple parameters in a PUT request. But you can pass in an object type, instead of a 3 primitives.
See below for an example. The example has multiple URL parameters, and a single body parameter that is actually an object with a Key/Value pair.
#region UpdateValue (PUT)
/// <summary>
/// Updates the property requested to the new value.
/// </summary>
/// <param name="roomId">ID of the Alexa device targeted</param>
/// <param name="action">Action to take</param>
/// <param name="newValue">Property Name/Value pair</param>
[HttpPut, Route("Value/{roomId}/{actionName}"), ResponseType(typeof(string))]
public HttpResponseMessage Update(string roomId, string actionName, [FromBody] NameValue newValue)
{
Func<HttpResponseMessage> method = delegate
{
Func<object, HttpResponseMessage> innerMethod = delegate
{
var roomMapping = Provider.GetRoomMapping(roomId);
if(roomMapping == null) this.ThrowItemNotFoundException("Alexa", roomId);
var ewsId = Provider.GetValueItemId(roomMapping, actionName, newValue.Name);
var valueModel = Provider.UpdateScalarValue<ValueModel>(this, ewsId, "Value", newValue.Value);
var response = Request.CreateResponse(HttpStatusCode.OK, valueModel.Value);
return response;
};
return this.ExecuteAndLogCall("UpdateValue", new { RoomId = roomId, Action = actionName, NewValue = newValue }, innerMethod);
};
return this.ExecuteRequestAndHandleErrors(method);
}
#endregion
Regards,
-Jeff
Link copied. Please paste this link to share this article on your social media post.
Hi Neeraj,
This is actually nothing to do with SmartConnector. Programming an API controller is actually just MVC ASP stuff from .NET. As you noticed I don’t think you can have multiple parameters in a PUT request. But you can pass in an object type, instead of a 3 primitives.
See below for an example. The example has multiple URL parameters, and a single body parameter that is actually an object with a Key/Value pair.
#region UpdateValue (PUT)
/// <summary>
/// Updates the property requested to the new value.
/// </summary>
/// <param name="roomId">ID of the Alexa device targeted</param>
/// <param name="action">Action to take</param>
/// <param name="newValue">Property Name/Value pair</param>
[HttpPut, Route("Value/{roomId}/{actionName}"), ResponseType(typeof(string))]
public HttpResponseMessage Update(string roomId, string actionName, [FromBody] NameValue newValue)
{
Func<HttpResponseMessage> method = delegate
{
Func<object, HttpResponseMessage> innerMethod = delegate
{
var roomMapping = Provider.GetRoomMapping(roomId);
if(roomMapping == null) this.ThrowItemNotFoundException("Alexa", roomId);
var ewsId = Provider.GetValueItemId(roomMapping, actionName, newValue.Name);
var valueModel = Provider.UpdateScalarValue<ValueModel>(this, ewsId, "Value", newValue.Value);
var response = Request.CreateResponse(HttpStatusCode.OK, valueModel.Value);
return response;
};
return this.ExecuteAndLogCall("UpdateValue", new { RoomId = roomId, Action = actionName, NewValue = newValue }, innerMethod);
};
return this.ExecuteRequestAndHandleErrors(method);
}
#endregion
Regards,
-Jeff
Link copied. Please paste this link to share this article on your social media post.
Hi Jeff,
Thanks for the explanation and sample. I am able to pass three parameters using header as in your sample:
//[HttpPut, Route("SetMode"), ResponseType(typeof(string))]
[HttpPut, Route("SetMode/bValue/{RoomNum}/{Mode}/{ModeChangeTime}"), ResponseType(typeof(string))]
public HttpResponseMessage SetMode(string RoomNum, string Mode, DateTime ModeChangeTime)
{
}
I found the issue is with date being passed as '1/1/2018'. It works if I pass date as '1 Jan 2018'.
Thanks Again!
Neeraj Tomar
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.