Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to create messaging services through AccountInstance resource #661

Open
rafaeelaudibert opened this issue Jun 7, 2023 · 3 comments

Comments

@rafaeelaudibert
Copy link

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 #225.

When trying the workaround on that issue we found the actual issue here: messaging is not defined on the AccountInstance class

class AccountInstance < InstanceResource

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 rafaeelaudibert changed the title Impossible to create messaging services through subaccount resource Impossible to create messaging services through AccountInstance resource Jun 7, 2023
@rafaeelaudibert
Copy link
Author

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

@rafaeelaudibert
Copy link
Author

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant