Skip to main content
Solved

List Detailed Answering Rules in C#

  • 22 October 2021
  • 1 reply
  • 313 views

(I know there is a parameter for detailed, please read) Is there another call to make for detailed instead of simple? In Python I would just add '"view" : "Detailed"' in my params and the output would let me parse through all of the detailed output. However, when adding the detailed param in C# the SDK doesn't have the detailed keys so it throws errors when trying to parse through them.


1634909604614.png


This is what I'm using


  1. ListAnsweringRulesParameters listAnsweringRulesParameters = new ListAnsweringRulesParameters
  2. {
  3. view = "Detailed",
  4. enabledOnly = true,
  5. };
  6.  
  7. var handleIDs = await rc.Restapi().Account("~").Extension(ext.id.ToString()).AnsweringRule().List(listAnsweringRulesParameters);
  8.  
  9. var fwdId = handleIDs.records"0].forwarding.rules"0].forwardingNumbers"0].id;
  10. var fwdType = handleIDs.records"0].forwarding.rules"0].forwardingNumbers"0].type;


The SDK doesn't have a "forwarding" key (in fwdId and fwdType) after "recordsd0]" so it throws me an error, even though I'm requesting a detailed list

Trying to use the ID/Type to set the users default answering rule, if there's a more simplistic way of doing it please let me know

I think the SDK has an issue to parse the response for the "Detailed" view. I will ask the SDK team to fix that. Meanwhile, you can work around the problem with this code:

public class DetailedAnsweringRuleInfo
{
public string uri { get; set; }
public string id { get; set; }
public string type { get; set; }
public string name { get; set; }
public bool? enabled { get; set; }
public ScheduleInfo schedule { get; set; }
public CalledNumberInfo[] calledNumbers { get; set; }
public CallersInfo[] callers { get; set; }
public string callHandlingAction { get; set; }
public ForwardingInfo forwarding { get; set; }
public UnconditionalForwardingInfo unconditionalForwarding { get; set; }
public QueueInfo queue { get; set; }
public TransferredExtensionInfo transfer { get; set; }
public VoicemailInfo voicemail { get; set; }
public GreetingInfo[] greetings { get; set; }
public string screening { get; set; }
public SharedLinesInfo sharedLines { get; set; }
public MissedCallInfo missedCall { get; set; }
};

public class CustomUserAnsweringRuleList
{
public string uri { get; set; }
public DetailedAnsweringRuleInfo[] records { get; set; }
public UserAnsweringRuleListPaging paging { get; set; }
public UserAnsweringRuleListNavigation navigation { get; set; }
};

static private async Task list_users_answering_rule_raw()
{
ListAnsweringRulesParameters listAnsweringRulesParams = new ListAnsweringRulesParameters{
view = "Detailed";
enabledOnly = false;
};
string endpoint = "restapi/v1.0/account/~/extension/~/answering-rule";
var response = await rcsdk.Get(endpoint, listAnsweringRulesParams);
var body = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<CustomUserAnsweringRuleList>(body);

foreach (var record in result.records)
{
dynamic jsonStr = JsonConvert.SerializeObject(record);
Console.WriteLine("=======");
Console.WriteLine(jsonStr);
}
}

Reply