cancel
Showing results for 
Search instead for 
Did you mean: 

connector SDk : "Why is the 'Create Account' action not working in my Salesforce custom connector?"

Patel0786
Deputy Chef II
Deputy Chef II

Hi everyone,

I'm building a custom connector for Salesforce and have implemented a 'Create Account' action. However, it’s not working as expected. Here's my setup:

  1. Connection Details:

    • OAuth2 authorization is configured with client ID, client secret, and token endpoints.
    • The base URI points to the Salesforce instance URL
      1. Action Code for 'Create Account':

       

       
      create_account: { description: 'Create Salesforce Account', input_fields: ->(_object_definitions) { [ { name: 'Name', type: 'string', optional: false }, { name: 'Phone', type: 'string', optional: true } ] }, execute: lambda do |connection, input| post("#{connection['base_uri']}/services/data/v62.0/sobjects/Account/")
      .payload( Name: input['account_name'], Phone: input['phone'] ) end, output_fields: ->(_object_definitions) { [ { name: 'Id', type: 'string' }, { name: 'Name', type: 'string' } ] } }
      Observed Issue:
      The action fails when executed. It either returns an '302 not found'error.

      Questions:

      • Is there an issue with the post request or payload structure?
      • Do I need to explicitly specify headers for the API call, such as "Content-Type": "application/json"?
      • Could it be a problem with the base_uri or endpoint used?

      Any insights or suggestions are greatly appreciated! Thanks in advance.

SDK Console Code:- 

{
title: 'Salesforce Connector',
connection: {
fields: [
{ name: 'client_id', optional: false },
{ name: 'client_secret', optional: false, control_type: 'password' }
],
authorization: {
type: 'oauth2',
authorization_url: lambda do |connection|
client_id = connection['client_id']
redirect_uri = "https://www.workato.com/oauth/callback"
scope = "full"
"https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=#{client_id}&red...}"
end,
token_url: lambda do |_connection|
"https://login.salesforce.com/services/oauth2/token"
end,
client_id: lambda do |connection|
connection['client_id']
end,
client_secret: lambda do |connection|
connection['client_secret']
end,
apply: lambda do |connection, access_token|
headers("Authorization": "Bearer #{access_token}")
end,
refresh_on: [401, 403],
refresh: lambda do |connection, refresh_token|
response = post("https://login.salesforce.com/services/oauth2/token")
.payload(
grant_type: "refresh_token",
client_id: connection['client_id'],
client_secret: connection['client_secret'],
refresh_token: refresh_token
)
{
access_token: response['access_token'],
refresh_token: response['refresh_token']
}
end
},
base_uri: lambda do |connection|
'https://curious-otter-480hm5-dev-ed.trailblaze.lightning.force.com/'
end
},
test: lambda do |_connection|
get("/services/data/v57.0/sobjects/Account/")
end,
actions: {
fetch_account: {
description: 'Fetch Salesforce Account',
input_fields: ->(_object_definitions) {
[
{ name: 'account_id', type: 'string', optional: false }
]
},
execute: lambda do |connection, input|
get("#{connection['base_uri']}/services/data/v62.0/sobjects/Account/#{input['account_id']}")
end,
output_fields: ->(_object_definitions) {
[
{ name: 'Id', type: 'string' },
{ name: 'Name', type: 'string' },
{ name: 'Phone', type: 'string' }
]
}
},
create_account: {
description: 'Create Salesforce Account',
input_fields: ->(_object_definitions) {
[
{ name: 'Name', type: 'string', optional: false },
{ name: 'Phone', type: 'string', optional: true }
]
},
execute: lambda do |connection, input|
post("#{connection['base_uri']}/services/data/v62.0/sobjects/Account/")
.payload(
Name: input['account_name'],
Phone: input['phone']
)
end,
output_fields: ->(_object_definitions) {
[
{ name: 'Id', type: 'string' },
{ name: 'Name', type: 'string' }
]
}
}
}
}

0 REPLIES 0