Activity: Using impersonation and Zapier
In this activity, you use impersonation and Zapier to fetch data using the v3 API.
Steps
Create an action in Zapier to process the URN of the item that was just updated, and split it up to have the workspace id and item id of the item for which the event was triggered.
Add a new action after catching the hook, set it to Code.
Select Run Javascript.
Edit the template by picking the Payload Item Urn, returned by Fusion Manage via the hook.
Using Javascript coding – split the URN into an array, to get the site name, workspace id, and item id. You can use a simple script, such as:
var splitUrn = inputData.urn.substring(inputData.urn.lastIndexOf(":") + 1); var splitUrnArray = splitUrn.split("."); var tenantName = splitUrnArray[0]; var wsId = splitUrnArray[1]; var itemId = splitUrnArray[2]; var output = {tenantName: tenantName, wsId: wsId, itemId: itemId};
Run the script. You should see the following:
These values are going to be available for this Zap, and with this, you can leverage pretty much any v3 API resource and fetch data.
Now it’s time to fetch the owners of the items. However, for this, you’ll need a valid token to authenticate with Fusion Manage. For this example, we want this fetching to be done as another user in the system, which may (or may not) have access to the owners section of the item for which the event was triggered. In this case, we are going to impersonate that other user. The first step is to retrieve a 2-legged Oauth token – documented in the Autodesk Platform Services (APS) help.
Fetch the owners of the items
Add a new action after the Javascript code, select Webhooks by Zapier.
Select Custom Request.
Fill in the form:
- Method: POST
- URL:
https://developer.api.autodesk.com/authentication/v1/authenticate.
- Data: client_id=YOUR_FORGE_APP_CLIENT_ID&client_secret=YOUR_FORGE_APP_CLIENT_SECRET&grant_type=client_credentials&scope=data:read.
- Headers: Content-Type: application/x-www-form-urlencoded.
If everything went well, this will give you back an access_token
Now that you have an access token, it’s time to impersonate another user when calling Fusion Manage. Some important points to consider:
- Your APS app must be whitelisted in Fusion Manage, so that the system can let calls coming from that app into the site. If you have not done so, file a Support case to whitelist your APS app in Fusion Manage. You need to supply your client id. Do not share you client secret under any circumstance.
- You need the e-mail address of the user you want to impersonate.
Time to get the owners of the item.
Add a new action, select Webhooks by Zapier.
Select GET.
Fill in the URL:
https://TENANT.autodeskplm360.net/api/v3/workspaces/WSID/items/ITEMID/owners.
Fill in the headers:
X-user-id: The e-mail of the user you’re going to impersonate.
X-Tenant: TENANT.
Authorization: Bearer ACCESS_TOKEN IMPORTANT: Note the blank space between “Bearer” and the access token.
Tip:Leverage Zapier’s inline editor to build this URL.
If everything goes well, you’ll get a success message, and the information about the owner of the item that was just updated will now be available to you:
Success! Now you can notify the user, by using the longDesc field, which displays the e-mail address, to send him or her a notification. You can edit your existing action for that.