twilio-ruby icon indicating copy to clipboard operation
twilio-ruby copied to clipboard

Impossible to create messaging services through AccountInstance resource

Open rafaeelaudibert opened this issue 2 years ago • 3 comments

Issue Summary

We are trying to create messaging services on a subaccount. At first, we tried doing so following what is suggested on the README, by instantiating a client containing the subaccount_sid and then hitting the messaging API

client = Twilio::REST::Client.new(account_sid, auth_token, subaccount_sid)
client.messaging.v1.services.create(friendly_name: "Test Subaccount")

That does not work because the gem uses the main account SID instead of the subaccount SID in the request path. That's already been explained on https://github.com/twilio/twilio-ruby/issues/225.

When trying the workaround on that issue we found the actual issue here: messaging is not defined on the AccountInstance class https://github.com/twilio/twilio-ruby/blob/e6ef5385fa49a866e254bc9efd6ca0971ca213b5/lib/twilio-ruby/rest/api/v2010/account.rb#L679

For that reason, this does not work:

client = Twilio::REST::Client.new(account_sid, auth_token)
account = client.accounts.get(subaccount_sid)
number = account.messaging.v1.services.create(friendly_name: "Test Subaccount") # NoMethodError: undefined method `messaging' for #<Twilio::REST::Api::V2010::AccountInstance:0x00005617df452e30>

messaging is not the only missing namespace, as trusthub cannot be found either.

Technical details:

  • twilio-ruby version: 6.0.1
  • ruby version: 2.6.6

rafaeelaudibert avatar Jun 07 '23 00:06 rafaeelaudibert

I'm trying to escalate this through your internal support ID #12597290. 2 weeks without any triage here sounds bad.

rafaeelaudibert avatar Jun 23 '23 03:06 rafaeelaudibert

Twilio's support directed me to https://www.twilio.com/docs/iam/api/subaccounts#authentication, more specifically

Your main account credentials will allow you to access resources for any of your subaccounts that fall under the v2010 REST API. However, resources on subdomains, such as studio.twilio.com and taskrouter.twilio.com, must be accessed directly using subaccount credentials (API Keys or subaccount SID + subaccount auth token).

There are many ways to determine if a resource lives on its own subdomain or under v2010. One example method is to find the API Reference page for the resource, such as the Workspace resource. Observe the returned url value in the example payloads: if the URL begins with https://SOME-SUBDOMAIN.twilio.com, then you must access that resource using subaccount-specific credentials. If you do the same for some other resource, such as the Messaging resource, and see that uri begins with /2010-04-01, then it can be safely accessed using either your main account or subaccount credentials.


I'm still checking to see if there's the option to change this in the future to make the experience more seamless.

rafaeelaudibert avatar Jul 03 '23 14:07 rafaeelaudibert

This was their response:

I confirmed with our Product Team, and there are no plans in the near future to implement this functionality. Using parent resources to do CRUD actions on subaccounts is something we actively suggest against.

I'll keep this issue open for now, but any Twilio rep can close it if you think this should be closed.

rafaeelaudibert avatar Jul 05 '23 21:07 rafaeelaudibert