I am using UCWA 2.0 for some Skype4Business integration in our intranet web application.
I can successfully connect and do some stuff for example: changing availability status or asking for callforwarding settings of the user.
What I like to do that does not work is set a forward contact for the user. Documentation for this: click here
My code for the POST call:
using (var client = new HttpClient())
{
var param = new { target = "sip:user@domain.be" };
var paramJson = JsonConvert.SerializeObject(param, Formatting.Indented);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Referrer = new Uri(result4._links.xframe.href);
client.DefaultRequestHeaders.Add("Authorization", $"{result3.token_type} {result3.access_token}");
var url = $"https://ucwebext.domain.be/{applicationUrl}/me/callForwardingSettings/immediateForwardSettings/immediateForwardToContact";
var responseNew = await client.PostAsync(url, new StringContent(paramJson, Encoding.UTF8, "application/json"));
var responseString = await responseNew.Content.ReadAsStringAsync();
}
Same code using RestSharp:
var client = new RestClient($"https://ucwebext.domain.be/{applicationUrl}");
var restR = new RestRequest("/me/callForwardingSettings/immediateForwardSettings/immediateForwardToContact", Method.POST);
var param = new { target = "sip:user@domain.be" };
var jsonToSend = JsonConvert.SerializeObject(param, Formatting.Indented);
restR.AddParameter("application/json; charset=utf-8", jsonToSend, ParameterType.RequestBody);
restR.AddParameter("referer", result4._links.xframe.href);
restR.AddHeader("Authorization", $"{result3.token_type} {result3.access_token}");
restR.RequestFormat = DataFormat.Json;
var response = client.ExecuteAsPost(restR, "POST");
Request header from the call:
POST https://ucwebext.domain.be/ucwa/oauth/v1/applications/101024253230/me/callForwardingSettings/immediateForwardSettings/immediateForwardToContact HTTP/1.1
Accept: application/json
Referer: https://ucwebext.domain.be/Autodiscover/XFrame/XFrame.html
Authorization: Bearer cwt=AAEBHAEFAAAAAAAF...0Q_OXzsR4g4F-PpYaMGK10Pg
Content-Type: application/json; charset=utf-8
Host: ucwebext.domain.be
Content-Length: 48
Expect: 100-continue
{"target":"sip:user@domain.be"}
I get the following error:
{"code":"BadRequest","subcode":"ParameterValidationFailure","message":"Please check what you entered and try again.","parameters":[{"name":"target","reason":"MissingOrInvalid"}]}
I tried everything and don't understand why the parameter is not submitting or invalid.
Any help is much appreciated!
SOLUTION
Instead of using JSON I added the parameter as querystring which worked!
var client = new RestClient($"https://ucwebext.domain.be/{applicationUrl}");
var restR = new RestRequest($"/me/callForwardingSettings/immediateForwardSettings/immediateForwardToContact{Url.Encode("?target=sip:user@domain.be")}", Method.POST);
restR.AddParameter("referer", result4._links.xframe.href);
restR.AddHeader("Authorization", $"{result3.token_type} {result3.access_token}");
var response = client.ExecuteAsPost(restR, "POST");