<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ACC Build Get Assets Token Problem in BIM 360 API Forum</title>
    <link>https://forums.autodesk.com/t5/bim-360-api-forum/acc-build-get-assets-token-problem/m-p/12530064#M104</link>
    <description>&lt;P&gt;Thanks, will look for that stuff.&lt;/P&gt;&lt;P&gt;There is a nice example in the aps service GitHub with a Revit addin.&lt;/P&gt;&lt;P&gt;In that example they open a browser too, will try to build it inside a wpf form &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2024 19:34:51 GMT</pubDate>
    <dc:creator>jw.vanasselt</dc:creator>
    <dc:date>2024-01-30T19:34:51Z</dc:date>
    <item>
      <title>ACC Build Get Assets Token Problem</title>
      <link>https://forums.autodesk.com/t5/bim-360-api-forum/acc-build-get-assets-token-problem/m-p/12437743#M100</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have followed the instructions on the ACC &lt;A href="https://aps.autodesk.com/en/docs/acc/v1/reference/http/assets-assets-v2-GET/" target="_blank" rel="noopener"&gt;API web page link here.&amp;nbsp;&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Under headers, it says "&lt;SPAN class=""&gt;&amp;lt;token&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;is obtained via a&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://aps.autodesk.com/en/docs/oauth/v2/tutorials/get-3-legged-token" target="_blank" rel="noopener"&gt;three-legged&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;OAuth flow."&lt;BR /&gt;&lt;BR /&gt;Question 1:&lt;BR /&gt;Is there any way to use a two-legged OAuth flow? The three-legged ones require a user to log in. I hope to have this script run in headless mode as I am just trying to get a CSV of all assets from a build project regularly like I have set up for BIM360 (to download Revit files).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When I tried to use a two-legged OAuth flow I set the scope to "data:read" and get a&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;status_code of 200 back. When I check the token it does not have a scope attached (which could be the following problem). When I use the token with the endpoint "&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;A href="https://developer.api.autodesk.com/construction/assets/v2/projects/" target="_blank" rel="noopener"&gt;https://developer.api.autodesk.com/construction/assets/v2/projects/&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;project_id&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;/assets" it returns the following 403 error.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;"The client_id specified does not have access to the api product"&lt;BR /&gt;&lt;BR /&gt;The screenshot below shows that my app has the two required APIs checked (Autodesk construction Cloud API and Data Management API).&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="smharch_0-1702443933294.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1304137iE4B4B6BB7D57E7FF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="smharch_0-1702443933294.png" alt="smharch_0-1702443933294.png" /&gt;&lt;/span&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Everything from question one is what leads me to question 2. When following the documentation to receive a three-legged token it requires one to enter a&amp;nbsp;redirect_uri for after the token has been grated. I am running this script from a secure local computer (again why I want to use a two-legged token) so I do not need a&amp;nbsp;redirect_uri. Since it does require one though I gave it "&lt;SPAN&gt;&lt;A href="https://www.google.com/&amp;quot;" target="_blank" rel="noopener"&gt;https://www.google.com/"&lt;/A&gt;. When I run this code I get the following warning.&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="smharch_1-1702444410234.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1304139i9457BD1BC1A96F1C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="smharch_1-1702444410234.png" alt="smharch_1-1702444410234.png" /&gt;&lt;/span&gt;&lt;P&gt;&lt;BR /&gt;code for a two-legged token&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import base64
import requests

# Step 1: Convert Client ID and Secret to Base64 encoded string
client_id = 'xxx'
client_secret = 'xxx'
project_id = 'b.xxx'

# Concatenate and encode to Base64
combined_credentials = f'{client_id}:{client_secret}'
base64_encoded_credentials = base64.b64encode(combined_credentials.encode()).decode()

print(f'Base64 Encoded String: {base64_encoded_credentials}')

# Step 2: Use encoded string to obtain an Access Token
token_url = 'https://developer.api.autodesk.com/authentication/v2/token'

headers = {
	'Content-Type': 'application/x-www-form-urlencoded',
	'Accept': 'application/json',
	'Authorization': f'Basic {base64_encoded_credentials}'
}

payload = {
	'grant_type': 'client_credentials',
	'scope': 'data:read'
}

# Make the POST request to obtain the access token
token_response = requests.post(token_url, headers=headers, data=payload)
print('Token:')
print(token_response.json())

# Check the response
if token_response.status_code == 200:
	access_token = token_response.json().get('access_token')
	granted_scopes = token_response.json().get('scope')

	# Print the granted scopes
	print(f'Access Token: {access_token}')
	print(f'Granted Scopes: {granted_scopes}')

	# Construct the API endpoint URL
	api_url = f'https://developer.api.autodesk.com/construction/assets/v2/projects/{project_id}/assets'

	# Make the API request
	headers = {'Authorization': f'Bearer {access_token}'}
	print(headers)
	response = requests.get(api_url, headers=headers)
	print(response)

	# Check the response
	if response.status_code == 200:
		asset_data = response.json()

		# Process the asset data as needed
		for asset in asset_data['data']:
			print(f"Asset ID: {asset['id']}, Asset Name: {asset['name']}")

		# Check for pagination
		next_url = asset_data.get('links', {}).get('next', None)
		if next_url:
			print(f"Next page URL: {next_url}")
	else:
		print(f"Error: {response.status_code}, {response.text}")
else:
	print(f'Token request failed. Status code: {token_response.status_code}, {token_response.text}')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;code for three-legged token&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests

# Step 1: Direct the User to the Authorization Web Flow
authorize_url = "https://developer.api.autodesk.com/authentication/v2/authorize"
client_id = 'xxx'
client_secret = 'xxx'
project_id = 'b.xxx'
redirect_uri = "https://www.google.com/"
scope = "data:read"

auth_url = f"{authorize_url}?response_type=code&amp;amp;client_id={client_id}&amp;amp;redirect_uri={redirect_uri}&amp;amp;scope={scope}"

print(f"Click on the following link to grant access: {auth_url}")

# Step 2: Implement Code that Extracts the Authorization Code
# After the user grants access, the authorization code will be received in the callback URL.
authorization_code = input("Enter the authorization code from the callback URL: ")

# Step 3: Exchange the Authorization Code for an Access Token
token_url = "https://developer.api.autodesk.com/authentication/v2/token"
client_secret = "Your_Client_Secret"

headers = {
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization": f"Basic Your_Base64_Encoded_Client_ID_and_Secret"
}

payload = {
    "grant_type": "authorization_code",
    "code": authorization_code,
    "redirect_uri": redirect_uri
}

response = requests.post(token_url, headers=headers, data=payload)

if response.status_code == 200:
    token_data = response.json()
    access_token = token_data["access_token"]
    refresh_token = token_data["refresh_token"]

    print(f"Access Token: {access_token}")
    print(f"Refresh Token: {refresh_token}")
else:
    print(f"Error: {response.status_code} - {response.text}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;Any help would be greatly appreciated.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Steven&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 05:17:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/bim-360-api-forum/acc-build-get-assets-token-problem/m-p/12437743#M100</guid>
      <dc:creator>smharch</dc:creator>
      <dc:date>2023-12-13T05:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: ACC Build Get Assets Token Problem</title>
      <link>https://forums.autodesk.com/t5/bim-360-api-forum/acc-build-get-assets-token-problem/m-p/12527368#M102</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3096187"&gt;@smharch&lt;/a&gt;&amp;nbsp;do you have a solution for this? I want to use the 3-legged too, without open my browser.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 06:08:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/bim-360-api-forum/acc-build-get-assets-token-problem/m-p/12527368#M102</guid>
      <dc:creator>jw.vanasselt</dc:creator>
      <dc:date>2024-01-30T06:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: ACC Build Get Assets Token Problem</title>
      <link>https://forums.autodesk.com/t5/bim-360-api-forum/acc-build-get-assets-token-problem/m-p/12529945#M103</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8555692"&gt;@jw.vanasselt&lt;/a&gt;&amp;nbsp;I have not tried it but through my research, you can open a port on your router and have it returned directly to your computer. Ensure you do your own research as opening ports can lead to others gaining access to your system.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;In case you or others did not know Auth 2 is also a global standard, not an Autodesk-specific signing. When I first started searching I was looking for BIM360-specific articles witch there were only a few. If you look for Auth 2 there is a bunch of stuff.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 18:41:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/bim-360-api-forum/acc-build-get-assets-token-problem/m-p/12529945#M103</guid>
      <dc:creator>smharch</dc:creator>
      <dc:date>2024-01-30T18:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: ACC Build Get Assets Token Problem</title>
      <link>https://forums.autodesk.com/t5/bim-360-api-forum/acc-build-get-assets-token-problem/m-p/12530064#M104</link>
      <description>&lt;P&gt;Thanks, will look for that stuff.&lt;/P&gt;&lt;P&gt;There is a nice example in the aps service GitHub with a Revit addin.&lt;/P&gt;&lt;P&gt;In that example they open a browser too, will try to build it inside a wpf form &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 19:34:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/bim-360-api-forum/acc-build-get-assets-token-problem/m-p/12530064#M104</guid>
      <dc:creator>jw.vanasselt</dc:creator>
      <dc:date>2024-01-30T19:34:51Z</dc:date>
    </item>
  </channel>
</rss>

