twilio/twilio-java — Issue #13: Update IncomingPhoneNumber for subaccount?
Author: franklovecchio
Created: 2011-11-30 21:27:55+00:00
State: open

Probably my fault, but when I try to update a phone number, I get an "Authenticate" error. I can get the call to work in APIGEE. I'm trying to update a number's URLs, and said number belongs to a subaccount. I authenticate the client with the master account, then ask for numbers for the subaccount. I even tried to add the AccountSid parameter manually (which is the subaccount's sid?). Do you see what I'm doing wrong? Thanks!

/* Top level account is needed for this */
TwilioRestClient client = new TwilioRestClient(
Credentials.TWILIO_MASTER_ACCOUNT_SID, Credentials.TWILIO_MASTER_AUTH_TOKEN);

Account TwilioSubAccount = client.getAccount(Credentials.TWILIO_SUBACCOUNT_SID);
IncomingPhoneNumberList list = TwilioSubAccount.getIncomingPhoneNumbers();

String sid = null;
for (IncomingPhoneNumber phoneNumber : list) {
if (phoneNumber.getPhoneNumber().equals(number)) {
Logger.info("Found matching number for subaccount, it's SID is: "
+ phoneNumber.getSid());
Logger.info("Number we found: " + phoneNumber.getPhoneNumber());
Logger.info("Number voice url (current): "
+ phoneNumber.getVoiceUrl());
sid = phoneNumber.getSid();
}
}

IncomingPhoneNumber phoneNumber = new IncomingPhoneNumber(client,
Credentials.TWILIO_SUBACCOUNT_SID);

Map params = new HashMap();
params.put("AccountSid", Credentials.TWILIO_SUBACCOUNT_SID);
params.put("VoiceUrl", "my new url");
params.put("VoiceMethod", "GET");
params.put("StatusCallback", "my new url");
params.put("StatusCallbackMethod", "GET");

try {
phoneNumber.update(params);
Logger.info("Updated phone number successfully");
} catch (TwilioRestException e1) {
Logger.info("Error updating phone number");
e1.printStackTrace();
return false;
}
return true;