PipedreamHQ / PipedreamHQ/pipedream
[BUG] Pipedream python api returning 401 for Pipedream action invocation using Pipedream connect
- Dominant language
- JavaScript
- Stars
- 11.7k
- Forks
- 5.8k
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 102
Description
**Describe the bug**
When invoking action from a Pipedream connect account using curl works. But, same invocation using the python api returns 401 and does not attach authorization headers to the invocation requests
**To Reproduce**
Steps to reproduce the behavior:
1. In this step, I run below curl
`curl --location 'https://api.pipedream.com/v1/oauth/token' \
--header 'Content-Type: application/json' \
--data '{
"grant_type": "client_credentials",
"client_id": "XXXXXXXXXXXXXXXXXXXXXX",
"client_secret": "XXXXXXXXXXXXXXXXXXXXXXXXX
}'`
This returns oauth access token properly.
2. Then run this curl using the access token received in step 1:
`curl --location 'https://api.pipedream.com/v1/connect/proj_XXXX/actions/run' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSJ9.eyJqdGkiOiJhNWEwYTI2Mi1jNjJlLTQyMjEtOGY3Mi0wMTA4OWM5NDFhZGEiLCJpc3MiOiJodHRwczovL2FwaS5waXBlZHJlYW0uY29tIiwiZXhwIjoxNzU2Nzk4NTI0LCJpYXQiOjE3NTY3OTQ5MjQsIm5iZiI6MTc1Njc5NDkxOSwidG9rZW5fdHlwZSI6Im9hdXRoX2FjY2Vzc190b2tlbiIsImF1ZCI6WyJhcGkiLCJjYXRjaGVyIl0sInN1YiI6Im9fS2dJWHdtQSIsInNjb3BlcyI6WyIqIl19.jHqXW4z3ACzZfqjH_sSS9MRVFtVn3re5m3cy66gZC2sHXNUk6ay2BkHpAGc6nVDuEiYocyfLkp_VTRGmSuTmBw' \
--header 'Content-Type: application/json' \
--header 'x-pd-environment: development' \
--data-raw '{
"id": "gmail-create-draft",
"external_user_id": "9c5a8877-0b1e-4ba3-b8f2-4bc478e8e36e",
"configured_props": {
"gmail": {
"authProvisionId": "apn_XXXXXX"
},
"to": "someone@example.com",
"subject": "test",
"body": "hello"
}
}'`
Works completely fine and draft is created.
But, when using python SDK mentioned here [https://pipedream.com/docs/connect/api-reference/run-action](https://pipedream.com/docs/connect/api-reference/run-action)
I keep getting 401. Pipedream python client never attaches the Authorization header.
```
from pipedream import Pipedream
from infrastructure.config.settings import get_settings
def create_draft(user_email: str, to: str, subject: str, body: str):
try:
settings = get_settings()
pipedream_client = Pipedream(
client_id=settings.pipedream_client_id,
client_secret=settings.pipedream_client_secret,
project_environment=settings.pipedream_environment,
project_id=settings.pipedream_project_id
)
accounts = pipedream_client.accounts.list()
account = next((account for account in accounts if account.external_id == user_email), None)
execute_tool_response = pipedream_client.actions.run(
id="gmail-create-draft",
external_user_id=user_email,
configured_props={ "to": to, "subject": subject, "body": body, "from_email": user_email, "gmail": {
"auth_provision_id": account.id
}
},
)
except Exception as e:
return str(e)
return execute_tool_response
```
**Expected behavior**
Drafts should be created when using python sdk too.
Contributor guide
Assessment
This issue has not been assessed yet.