Skip to main content
When you use prebuilt actions tied to apps, you don’t need to write the code to authorize API requests. Just connect your account for that app and run your workflow. But sometimes you’ll need to write your own code. You can also connect apps to custom code steps, using the auth information to authorize requests to that app. For example, you may want to send a Slack message from a step. We use Slack’s OAuth integration to authorize sending messages from your workflows. Add Slack as an app on the Python step, then connect your Slack account.
Then within the Python code step, pd.inputs["slack"]["$auth"]["oauth_access_token"] will contain your Slack account OAuth token. With that token, you can make authenticated API calls to Slack:
from slack_sdk import WebClient
 
def handler(pd: "pipedream"):
  # Your Slack OAuth token is available under pd.inputs
  token = pd.inputs["slack"]["$auth"]["oauth_access_token"]
 
  # Instantiate a new Slack client with your token
  client = WebClient(token=token)
 
  # Use the client to send messages to Slack channels
  response = client.chat_postMessage(
    channel='#general',
    text='Hello from Pipedream!'
  )
 
  # Export the Slack response payload for use in future steps
  pd.export("response", response.data)

Accessing connected account data with pd.inputs[appName]["$auth"]

In our Slack example above, we created a Slack WebClient using the Slack OAuth access token:
# Instantiate a new Slack client with your token
client = WebClient(token=token)
Where did pd.inputs["slack"] come from? Good question. It was generated when we connected Slack to our Python step.