vrvoice1 | 2016-07-05 12:46:54 UTC | #1
Hi, I want to add a new remote phone via the platform API to my purecloud. This is my example:
<code>
TelephonyProvidersEdgeApi tpea = new TelephonyProvidersEdgeApi();
var groups = tpea.GetProvidersEdgesEdgegroups();
EdgeGroup eg = groups.Entities.First();
var templates = tpea.GetProvidersEdgesPhonebasesettingsAvailablemetabases(); Metabase metabase = templates.Entities.First(b => b.Name == "Remote");
var baseSettings = tpea.GetProvidersEdgesPhonebasesettings(); PhoneBase phoneBase = baseSettings.Entities.First(e => e.Name == "Remote");
var sites = tpea.GetProvidersEdgesSites(); var site = sites.Entities.First();
var lbs = tpea.GetProvidersEdgesLinebasesettings(); var lb = lbs.Entities.First(g => g.Name == "Remote_1");
var l = new List<Line>(); l.Add(new Line() { Name = "Remote_Line", LineBaseSettings = new UriReference(Id: lb.Id),
});
Phone phone = new Phone( Site: new UriReference(site.Id), PhoneBaseSettings: new UriReference(Id: phoneBase.Id), EdgeGroup: new UriReference(Id: eg.Id), Name: "Remote_Phone", Lines: l, PhoneMetaBase: new UriReference(Id: metabase.Id) );
tpea.PostProvidersEdgesPhones(phone); </code>
I think that all required fields are filled but I get the following error on the PostProvidersEdgesPhones method:
<code> "status": 500, "code": "internal.server.error", "message": "The server encountered an unexpected condition which prevented it from fulfilling the request.", "contextId": "000e9abd-2870-4aad-b644-04ff82aed766", </code>
I have try it with Postman but it happens the same. Postman JSON Request:
<code> { "name": "RemotePhone", "description": "", "version": 0, "dateCreated": "", "dateModified": "", "modifiedBy": "", "createdBy": "", "state": "", "modifiedByApp": "", "createdByApp": "", "edgeGroup": { "id": "a73daa9a-ab6e-4c76-be4d-a1b024dcfdb7", "name": "", "selfUri": "" }, "site": { "id": "9044d09f-9602-4173-85fc-9a2ce32fc93b", "name": "", "selfUri": "" }, "phoneBaseSettings": { "id": "1e1863b2-bd31-4e7f-a05e-234199b3d7c4", "name": "", "selfUri": "" }, "lineBaseSettings": { "id": "cc0ff54c-5870-49c8-a105-f27ac8e80169", "name": "", "selfUri": "" }, "phoneMetaBase": { "id": "ininremote.json", "name": "", "selfUri": "" }, "lines": [], "status": { "name": "", "operationalStatus": "", "edgesStatus": "", "provision": {}, "lineStatuses": [], "phoneAssignmentToEdgeType": "", "edge": {} }, "secondaryStatus": { "name": "", "operationalStatus": "", "edgesStatus": "", "provision": {}, "lineStatuses": [], "phoneAssignmentToEdgeType": "", "edge": {} }, "properties": {}, "capabilities": { "provisions": false, "registers": false, "dualRegisters": false, "hardwareIdType": "", "allowReboot": false, "noRebalance": false }, "webRtcUser": { "id": "", "name": "", "selfUri": "" } } </code>
Kind regards,
Sven
KevinGlinski | 2016-07-08 18:16:31 UTC | #2
can you rerun the test and post the contextId? I'm having a hard time pulling back the one you posted.
vrvoice1 | 2016-07-11 06:24:28 UTC | #3
Hi Kevin,
sure this is the new Id: 7cec9a0b-cc7b-4ae9-b2ad-befacba76f61
I have changed my code a little bit in the last days because I have a working Postman example and I have adjusted the C# one.
<code> TelephonyProvidersEdgeApi tpea = new TelephonyProvidersEdgeApi();
var groups = tpea.GetProvidersEdgesEdgegroups();
EdgeGroup eg = groups.Entities.First();
var templates = tpea.GetProvidersEdgesPhonebasesettingsAvailablemetabases(); Metabase metabase = templates.Entities.First(b => b.Name == "Remote");
var baseSettings = tpea.GetProvidersEdgesPhonebasesettings(); PhoneBase phoneBase = baseSettings.Entities.First(e => e.Name == "Remote");
var sites = tpea.GetProvidersEdgesSites(); var site = sites.Entities.First();
var line = tpea.GetProvidersEdgesLines();
var lbs = tpea.GetProvidersEdgesLinebasesettings(); var lb = lbs.Entities.First(g => g.Name == "Remote_1");
var prop = new Dictionary<string, object>();
prop.Add("stationremoteaddress", "\"instance\": \"01732113092\""); prop.Add("stationlineLabel", "\"instance\": \"RemoteLineLabel\""); prop.Add("stationlabel", "\"instance\": null"); prop.Add("stationlineKeyPosition", "\"instance\": 0");
var l = new List<Line>(); l.Add(new Line() { Name = "Remote_Line2", LineBaseSettings = new UriReference(Id: lb.Id,Name: lb.Name), Properties = prop
}); var phoneProp = new Dictionary<string, object>(); phoneProp.Add("phone_hardwareId", "\"instance\": null");
Phone phone = new Phone( Site: new UriReference(site.Id), PhoneBaseSettings: new UriReference(Id: phoneBase.Id), EdgeGroup: new UriReference(Id: eg.Id), Name: "Remote_Phone2", Lines: l, Properties: phoneProp );
tpea.PostProvidersEdgesPhones(phone); </code>
KevinGlinski | 2016-07-11 13:17:24 UTC | #4
Which region are you in?
vrvoice1 | 2016-07-11 13:19:43 UTC | #5
The region is EMEA (germany)
KevinGlinski | 2016-07-12 18:56:10 UTC | #6
Was hoping the logs on our end would show something, they do not.
Should the value of the props be json objects?
prop.Add("stationremoteaddress", "{\"instance\": \"01732113092\"}" } ?
Try calling phone.ToJSON() and compare your object with what works in postman for you.
tim.smith | 2016-07-12 19:36:59 UTC | #7
I was able to get this working in Postman. I followed the Create a phone tutorial. Here's the request I ended up with:
POST /api/v2/telephony/providers/edges/phones HTTP/1.1 Host: api.mypurecloud.com Authorization: bearer xxxx Content-Type: application/json Cache-Control: no-cache Postman-Token: 137c75e1-1840-0e35-41a9-721a7d957e9a
{ "name": "Test Phone2", "site": { "id": "fbefa3ae-1e4b-4b4b-912d-f0a9852a6b9a" }, "phoneBaseSettings": { "id": "71f8c7c2-c019-4290-a3d5-87613e338c10" }, "lines": [ { "name": "line2", "lineBaseSettings": { "id": "716329a7-9113-4f08-ba73-04e4e48f8c9c" }, "edgeGroup": { "id": "4a62ee1b-1f28-45e3-8595-67ec85ef9851" }, "properties": { "stationlabel": { "value": { "instance": "line2" } }, "stationremoteaddress": { "value": { "instance": "3172222222" } }, "stationlineLabel": { "value": { "instance": "line2" } }, "stationlineKeyPosition": { "value": { "instance": 0 } } } } ], "properties": { "phonehardwareId": { "value": { "instance": "0004f0000001" } } } }
I'm working on a .NET SDK example and will post that shortly.
tim.smith | 2016-07-12 20:25:53 UTC | #8
Ok, I've gotten this figured out. I think the main thing that was wrong with your code is that prop.Add("station_remote_address", "\"instance\": \"01732113092\""); serializes to "station_label2": "{\"value\": {\"instance\": \"line4\"}". The escaped quotes are included, which makes the JSON invalid. I worked around this by creating classes to store the properties and have them serialized correctly.
As a takeaway, I will work with the team responsible for this resource to improve the documentation (don't use object as the type for properties). Once that is fixed, the SDKs can include a strongly typed set of classes to construct the value for properties.
Here's the helper classes I wrote:
[DataContract] public class ValueString { [DataMember(EmitDefaultValue = false, Name = "value")] public InstanceString Value { get; set; }
public ValueString(string value) { Value = new InstanceString(value); } public string ToJson() { return JsonConvert.SerializeObject((object)this, Formatting.Indented); } }
[DataContract] public class InstanceString { [DataMember(EmitDefaultValue = false, Name = "instance")] public string Instance { get; set; }
public InstanceString(string instance) { Instance = instance; } public string ToJson() { return JsonConvert.SerializeObject((object)this, Formatting.Indented); } } [DataContract] public class ValueInt { [DataMember(EmitDefaultValue = false, Name = "value")] public InstanceInt Value { get; set; }
public ValueInt(int value) { Value = new InstanceInt(value); } public string ToJson() { return JsonConvert.SerializeObject((object)this, Formatting.Indented); } }
[DataContract] public class InstanceInt { [DataMember(EmitDefaultValue = false, Name = "instance")] public int Instance { get; set; }
public InstanceInt(int instance) { Instance = instance; } public string ToJson() { return JsonConvert.SerializeObject((object)this, Formatting.Indented); } }
And here's the C# code that works to create a station. Of course, this is throwaway code; I wouldn't suggest using retrieved values without validation and some kind of logical selection of entities and using real values for settings.
static void CreateStation() { var suffix = "4";
var telephonyApi = new TelephonyProvidersEdgeApi();
// Get edges var edgeGroups = telephonyApi.GetProvidersEdgesEdgegroups();
// Get phone base settings var phoneBaseSettings = telephonyApi.GetProvidersEdgesPhonebasesettings();
// Get sites var sites = telephonyApi.GetProvidersEdgesSites();
// Get line base settings var lineBaseSettings = telephonyApi.GetProvidersEdgesLinebasesettings();
// Create request var phone = new Phone( Name: $"Test phone {suffix}", Site: new UriReference(sites.Entities[0].Id), PhoneBaseSettings: new UriReference(phoneBaseSettings.Entities[0].Id), Lines: new List<Line> { new Line { Name = $"line{suffix}", LineBaseSettings = new UriReference(lineBaseSettings.Entities[0].Id), EdgeGroup = new UriReference(edgeGroups.Entities[0].Id), Properties = new Dictionary<string, object> { {"stationlabel", new ValueString("line" + suffix)}, {"stationremoteaddress", new ValueString("3172222222")}, {"stationlineLabel", new ValueString("line" + suffix)}, {"stationlineKeyPosition", new ValueInt(1)} } } }, Properties: new Dictionary<string, object> { {"phonehardwareId", new ValueString("0004f000000" + suffix)} });
// Create phone telephonyApi.PostProvidersEdgesPhones(phone); }
vrvoice1 | 2016-07-13 08:49:58 UTC | #9
Hi Tim, yes that's the problem. Now it's working. Thanks. Perhaps you can add this example to the API Resources.
Regards,
Sven
tim.smith | 2016-07-13 19:38:33 UTC | #10
Absolutely. I'll be adding it as a tutorial after the API docs are updated and the SDK has the changes.
system | 2017-08-28 19:25:09 UTC | #11
This post was migrated from the old Developer Forum.
ref: 116