Let's say I post a workitem to Revit engine using the following code
var response = await _flurlClient.Request("https://developer.api.autodesk.com/da/us-east/v3/workitems")
.PostJsonAsync(new
{
activityId = "ActivityID",
arguments = new
{
rvtFile = new
{
url = storageUrl,
Headers = new
{
Authorization = $"Bearer {accessToken}"
}
},
result = new
{
verb = "post",
url = $"{baseUrl}/api/result"
}
}
})
.ReceiveJson();
The response will contain the Id for this workitem. once the work item completes successfully, Forge calls my API endpoint with the output file. My endpoint is implemented as follows:
[HttpPost("Result")]
public async Task<IActionResult> PostResults()
{
await using (var fs = new FileStream("D://Test//l2.xlsx", FileMode.Create))
{
await Request.Body.CopyToAsync(fs);
}
return Ok();
}
The file is correctly saved but I can't get the associated workitem Id (not as a query parameter nor a header). This causes an issue, let's say I submitted two work items (A and B) when I receive a file how I can tell if it is related to work item A or B.
See answer.
Design automation allows you to specify a variable workitem.id
in your output url. When your workitem completes we shall call this url with the variable expanded to the id of that workitem. This dynamic variable path allows you to determine the workitem id associated with that callback.
At your end you will need to implement Attribute Routing.
[HttpPost("Result/{workitemId}")]
public async Task<IActionResult> PostResults(string workitemId)
{
}
You may post the workitem with:
result = new
{
verb = "post",
url = $"{baseUrl}/api/result/$(workitem.id)"
}