Expand my Community achievements bar.

Wondering how Workfront Proof works? Join our AMA on May 8th and ask our Community experts!
SOLVED

Python code to access Workfront API using OAuth2 authenticaiton

Avatar

Level 10

Hello,

 

Is there anybody, who could provide me with some Python code to access the Workfront API using OAuth2 authorization code flow?

 

I am currently too dump to make some progress on this issue...

 

Thanks in advance.

 

Regards

Lars

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hi @lgaertner 


from requests_oauthlib import OAuth2Session


authorization_base_url = "https://<your-domain>.my.workfront.com/attask/oauth/authorize"
token_url = "https://<your-domain>.my.workfront.com/attask/oauth/token"


client_id = "<your-client-id>" # Replace with your client ID
redirect_uri = "<your-redirect-URI>" # Replace with your redirect URI


oauth = OAuth2Session(client_id, redirect_uri=redirect_uri)


authorization_url, state = oauth.authorization_url(authorization_base_url)
webbrowser.open(authorization_url)


authorization_response = input('Enter the full callback URL')


token = oauth.fetch_token(
token_url,
authorization_response=authorization_response,
client_secret="<your-client-secret>") # Replace with your client secret

 

This is to get the User Profile:
response = oauth.get('https://<your-domain>.my.workfront.com/attask/api/user/profile')
print(response.json())

View solution in original post

7 Replies

Avatar

Correct answer by
Level 4

Hi @lgaertner 


from requests_oauthlib import OAuth2Session


authorization_base_url = "https://<your-domain>.my.workfront.com/attask/oauth/authorize"
token_url = "https://<your-domain>.my.workfront.com/attask/oauth/token"


client_id = "<your-client-id>" # Replace with your client ID
redirect_uri = "<your-redirect-URI>" # Replace with your redirect URI


oauth = OAuth2Session(client_id, redirect_uri=redirect_uri)


authorization_url, state = oauth.authorization_url(authorization_base_url)
webbrowser.open(authorization_url)


authorization_response = input('Enter the full callback URL')


token = oauth.fetch_token(
token_url,
authorization_response=authorization_response,
client_secret="<your-client-secret>") # Replace with your client secret

 

This is to get the User Profile:
response = oauth.get('https://<your-domain>.my.workfront.com/attask/api/user/profile')
print(response.json())

Avatar

Level 10

Hello Jvenkat,

 

Thanks a lot. Unfortunately it is not working for me yet...

 

I constantly do get the error message Missing access token parameter.

 

What do you use as redirect_uri and how is your callback URL formatted?

 

Regards

Lars

Avatar

Level 10

Correction:

 

I got it finally working!!!

 

Here is my final code:

 

import webbrowser
from requests_oauthlib import OAuth2Session

# Client-side Configuration
client_id = "<clientID>" # Replace with your client ID
client_secret = "<clientSecret>"
redirect_uri = "http://127.0.0.1:8088" # Replace with your redirect URI

# OAuth endpoints given in the Workfront API documentation
authorization_base_url = 'https://oauth.my.workfront.com/integrations/oauth2/authorize'
token_url = 'https://<your-domain>.my.workfront.com/integrations/oauth2/api/v1/token'
response_type = 'code'


# Create the OAuth2 Session
oauth = OAuth2Session(client_id, redirect_uri=redirect_uri)

# Redirect user to Workfront for authorization
authorization_url, state = oauth.authorization_url(authorization_base_url)
webbrowser.open(authorization_url)

# User will get an authorization code. Copy it
authorization_response = input('Enter the full callback URL: ')


# Exchange the authorization code for a token
token = oauth.fetch_token(
token_url,
authorization_response=authorization_response,
client_secret = client_secret)

print(token)

 

Thanks a lot @Jvenkat 

Avatar

Level 1

Not working for me could you please help me with the redirect url and callback URI im not sure what to put im trying to integrate with sb01 environment.

Avatar

Level 1

HI @OmprakashKu2 

did you get any working solution ?

 

if yes please share 

Avatar

Level 1

Yes, i just added the technical user in to workfront instance and granted him access

Avatar

Level 1

Hi @lgaertner ,

I just wanted to check—has the code been updated recently, or is it still working as expected? On my end, it’s not working, and I keep encountering an error, see the attached screenshot, error is That page doesn't exist, i am tired of this error now.


Additionally, could you please confirm if it’s possible to use a localhost URL for the redirect_uri, or does it strictly require an HTTPS URL?

I would really appreciate your help—I've been troubleshooting this for the past few days and would love your guidance to move forward.


Thanks so much in advance!

 

VINAYPA2_0-1745616530851.png