Closed KaranAhlawat closed 1 year ago
Hi @KaranAhlawat , PathAccountSid
is not needed when constructing CreateMessageParams
. It will be handled by the api with the credentials you entered in NewTwilioClient
.
Also, it would be advised to remove the otherSid
value from your example above and replace it with 'xxxx'
@claudiachua Thanks for the reply, and the advise. Updated my snippet.
As for the question, I understand it is not needed. So would the best possible solution be to recreate the client on each request with the appropriate credentials?
@KaranAhlawat : Looks like you need to use a subaccount? https://github.com/twilio/twilio-go#using-subaccount
I've adapted my application accordingly. To leave the gist of it for future readers, you can either create a Twilio client on a per-request basis, or have all your numbers under a single account SID. Closing this now.
Issue Summary
Ambiguity regarding the expected behaviour of
PathAccountSid
parameter on theCreateMessageParams
struct. The Twilio client is initialized on application startup, using our organization's Account SID and Auth Token.Our application requires us to be able to send messages from other accounts as well, which have different phone numbers, Account SIDs and Auth Tokens.
I tried passing the Account SID of the
From
phone number as thePathAccountSid
field, thinking that was the logical thing to do, but since the credentials with which the client was created are different, the Twilio REST API throws an authentication error. The only way I've found to deal with this is to create a new client with the desired Account SID and Auth Token. Since I've found this to be the case so far, I'm unsure as to what thePathAccountSid
field is supposed to do.Steps to Reproduce
PathAccountSid
.Code Snippet
This creates a REST client some account's SID and auth token.
This tries to create a message using other account's phone number.
Exception/Log
https://www.twilio.com/docs/api/errors/20003