#SALESFORCE Connect fail with redirect auth

1 messages · Page 1 of 1 (latest)

lunar juniper
#

Hi, I came across issues, this is my code:


from langchain.agents import create_openai_functions_agent, AgentExecutor
from langchain import hub
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
from composio_langchain import ComposioToolSet, App

from core.config import settings

llm = ChatOpenAI(api_key=settings.OPENAI_API_KEY, temperature=0)
composio_toolset = ComposioToolSet(api_key=settings.COMPOSIO_API_KEY)

app = App.SALESFORCE

integration = composio_toolset.create_integration(
    app=app,
    use_composio_oauth_app=True,
    force_new_integration=True,
)

user_id = "abc"

connection_req = composio_toolset.initiate_connection(
    integration_id=integration.id,
    entity_id=user_id,

)
print(f"Navigate to {connection_req.redirectUrl} to connect your Services account")
print(
    f"Connection status: {connection_req.connectionStatus}"
)  # Status will be INITIATED

connection = connection_req.wait_until_active(composio_toolset.client, timeout=50)

print(f"Connection created: {connection.id}")
#

facing issue:

InvalidParams: Expected 'connected_account_params' to provide these params: ['instanceEndpoint']

Fix:

connection_req = composio_toolset.initiate_connection(
    integration_id=integration.id,
    entity_id=user_id,
    connected_account_params={
        "instanceEndpoint": "https://studioai-demo.lightning.force.com/lightning/r/User/005Hp00000j0W7aIAE/view/"
    },
)
#

Continue the rest code:


tools = composio_toolset.get_tools(apps=[App.SALESFORCE], entity_id=user_id)
prompt = hub.pull("hwchase17/openai-functions-agent")
agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
task = "Create a new account with name John Doi, company ACME Inc, and email [email protected]"
agent_executor.invoke({"input": task})
#

Facing issue:

[1m> Entering new AgentExecutor chain...[0m
[32;1m[1;3m
Invoking: `SALESFORCE_ACCOUNT_CREATION_WITH_CONTENT_TYPE_OPTION` with `{'Name': 'John Doi', 'Company': 'ACME Inc', 'Email': '[email protected]'}`


[0m[36;1m[1;3m{'data': {}, 'error': 'HTTPSConnectionPool(host=\'orgfarm-8aafb99c27-dev-ed.develop.my.salesforce.comhttps\', port=443): Max retries exceeded with url: /studioai-demo.lightning.force/sobjects/Account (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f2c77d55510>: Failed to resolve \'orgfarm-8aafb99c27-dev-ed.develop.my.salesforce.comhttps\' ([Errno -2] Name or service not known)"))', 'successfull': False, 'successful': False}[0m[32;1m[1;3m
Invoking: `SALESFORCE_ACCOUNT_CREATION_WITH_CONTENT_TYPE_OPTION` with `{'Name': 'John Doi', 'Company': 'ACME Inc', 'Email': '[email protected]'}`
responded: I encountered an error while trying to create a new account. It seems there was an issue with the URL. Let me try again.

[1m> Finished chain.[0m

I notice that this only happen when I using redirect authentication. It work fine with composio add salesforce

molten mango
#

Hey @lunar juniper, Salesforce requires instanceEndpoint to be passed when creating a new connection—You'd have to use get_expected_params_for_user which will respond with the params needed to be passed while creating the connection, here's the code snippet:
Code:

composio_toolset.get_expected_params_for_user(integration_id="f08f22fa-abe5-4c08-8291-5cfd1fb65171")

Response:

{
  'integration_id': 'f08f22fa-abe5-4c08-8291-5cfd1fb65171',
  'auth_scheme': 'OAUTH2',
  'expected_params': [
    ExpectedFieldInput(name='instanceEndpoint',
    type='string',
    description='The service endpoint for your Salesforce instance eg /services/data/v61.0, used for API requests.',
    displayName='Instance endpoint',
    is_secret=False,
    required=True,
    expected_from_customer=True,
    default='/services/data/v61.0',
    get_current_user_endpoint=None)
  ]
}

You can learn more about it here: https://docs.composio.dev/auth/connection/non-oauth (although Salesforce supports OAuth, it still requires the instanceEndpoint as an input from user, you can also use the default value)

And regarding composio add salesforce, to make the onboarding seamless we just use the default value of instanceEndpoint

lunar juniper
#

Cool thank you

#

Solve the issue

#

I leave instanceEndpoint = "/services/data/v61.0" then it work

#

but not really understand this

molten mango
#

Yes passing instanceEndpoint = "/services/data/v61.0" will work—What exactly didn't you understand?

lunar juniper
#

if instanceEndpoint = "/services/data/v61.0" is default value, why this is require ? and then we are filling the default value again ? What is this sense ?