Ben Paddick Posted January 25, 2019 Posted January 25, 2019 Hi. I am trying to ADD / UPDATE project tasks using the various API functions. I receive a similar error for both functions API Call Status : fail Error Returned : Failed to load FlowCode script '\\?\D:\Hornbill\ESP Server\instances\vinci\apps\com.hornbill.core\entities\Projects\fc_ops\addProjectTask.xml' The script i am using for the ADD task is ## Powershell Hornbill XMLMC Module Example ## Add project task as defined in script to your Hornbill instance ## See the API documentation for a full list of supported input parameters: ## https://api.hornbill.com/apps/com.hornbill.projectmanager/ProjectTasks?op=addProjectTask # Import Hornbill XMLMC Powershell Module Import-Module "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\powershellHornbillAPIModule-master\xmlmcModule.psm1" # Define instance connection details & API key for session authentication $hbInstance ="vinci" $hbZone = "eur" $hbAPIKey = "myprivatekeyisinhere" Set-Instance -Instance $hbInstance -Key $hbAPIKey -Zone $hbZone # Define Project Tasks details - replace with a CSV loop $projectID = "273" $name = "this is a test project task" $file = "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\Scripts\statuses.json" # Get statuses from JSON file ["Active", "Cancelled", "Completed"] $JsonOutcomes = $file $JsonOutcomes = $JsonOutcomes | ConvertTo-Json # check the JSON has been loaded and is correct Write-Host $JsonOutcomes # Build XMLMC API call to add project task record Add-Param "projectID" "$projectID" Add-Param "name" "$name" Add-Param "outcomes" "$converted" # Invoke XMLMC call, output returned as PSObject $xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.projectmanager/Projects" "addProjectTask" "status code: " + $xmlmcOutput.status "New project task outcome : " + $xmlmcOutput.params.outcome "New project task ID : " + $xmlmcOutput.params.projectTaskId if($xmlmcOutput.status -ne "ok" -or !$xmlmcOutput.params.rowData){ if($xmlmcOutput.status -eq "ok") { "No matching project task records found!" } else { # API call status not OK - return status and error to console "API Call Status : " + $xmlmcOutput.status "Error Returned : " + $xmlmcOutput.error } } # Important! Remove XMLMC module from memory for security once XMLMC calls complete Remove-Module xmlmcModule I presume I am doing something wrong? Most likely to do with the validation of the "Statuses"??? The JSON file looks like this [ "Active", "Cancelled", "Completed" ] Any ideas? I really want to be able to resolve this so I can Create / Update project tasks dates and information in bulk using excel. Many Thanks Ben
AlexTumber Posted January 25, 2019 Posted January 25, 2019 @Ben Paddick sorry to hear you are having problems. Looking at your api call, the JSON for the outcomes param should be something like this: [{"outcome":"completed","text":"Completed","language":"en-GB","buttonColor":"primary","requiresReason":"false"}] Can you let me know if this works? Alex
AlexTumber Posted January 25, 2019 Posted January 25, 2019 I should add that we will update the documentation on the project task api's as this is not clear. The reason the outcomes param is like this is because in the future we will be giving our customers the opportunity to create custom outcomes for their project tasks. Alex
Ben Paddick Posted January 25, 2019 Author Posted January 25, 2019 Alex I have ammended the JSON to the following for purpose of test [ {"outcome":"completed","text":"Completed","language":"en-GB","buttonColor":"primary","requiresReason":"false"} ] The script has been tweaked to call this so now stands as ## Powershell Hornbill XMLMC Module Example ## Add project task as defined in script to your Hornbill instance ## See the API documentation for a full list of supported input parameters: ## https://api.hornbill.com/apps/com.hornbill.projectmanager/ProjectTasks?op=addProjectTask # Import Hornbill XMLMC Powershell Module Import-Module "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\powershellHornbillAPIModule-master\xmlmcModule.psm1" # Define instance connection details & API key for session authentication $hbInstance ="vinci" $hbZone = "eur" $hbAPIKey = "key in here" Set-Instance -Instance $hbInstance -Key $hbAPIKey -Zone $hbZone # Define Project Tasks details - replace with a CSV loop $projectID = "273" $name = "this is a test project task" $file = get-content "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\Scripts\statuses.json" $JsonOutcomes = $file write-host $JsonOutcomes # Build XMLMC API call to add project task record Add-Param "projectID" "$projectID" Add-Param "name" "$name" Add-Param "outcomes" "$JsonOutcomes" # Invoke XMLMC call, output returned as PSObject $xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.projectmanager/Projects" "addProjectTask" "status code: " + $xmlmcOutput.status "New project task outcome : " + $xmlmcOutput.params.outcome "New project task ID : " + $xmlmcOutput.params.projectTaskId if($xmlmcOutput.status -ne "ok" -or !$xmlmcOutput.params.rowData){ if($xmlmcOutput.status -eq "ok") { "No matching project task records found!" } else { # API call status not OK - return status and error to console "API Call Status : " + $xmlmcOutput.status "Error Returned : " + $xmlmcOutput.error } } # Important! Remove XMLMC module from memory for security once XMLMC calls complete Remove-Module xmlmcModule I still recieve "Error Returned : Failed to load FlowCode script '\\?\D:\Hornbill\ESP Server\instances\vinci\apps\com.hornbill.core\entities\Projects\fc_ops\addProjectTask.xml'" Any further ideas? Thanks
AlexTumber Posted January 25, 2019 Posted January 25, 2019 @Ben Paddick It looks like the path is wrong. Instead of: \\?\D:\Hornbill\ESP Server\instances\vinci\apps\com.hornbill.core\entities\Projects\fc_ops\addProjectTask.xml' It should be: \\?\D:\Hornbill\ESP Server\instances\vinci\apps\com.hornbill.projectmanager\entities\Projects\fc_ops\addProjectTask.xml' Alex
Ben Paddick Posted January 25, 2019 Author Posted January 25, 2019 Alex I had made an assumption that the path is generated as an internal variable in API code controlled by Hornbill? Thanks Ben
AlexTumber Posted January 25, 2019 Posted January 25, 2019 @Ben Paddick I don't think it is. Is this now working for you? Alex
Ben Paddick Posted January 25, 2019 Author Posted January 25, 2019 @AlexTumber How do I change the path then? This is not a parameter within the script, this is a server side ouput returned by the API. Thanks for your assistance on this!
AlexTumber Posted January 25, 2019 Posted January 25, 2019 @Ben Paddick I can only assume that this is a fault with our powershell module because if the error being returned is this: : Failed to load FlowCode script '\\?\D:\Hornbill\ESP Server\instances\vinci\apps\com.hornbill.core\entities\Projects\fc_ops\addProjectTask.xml'" It can only mean that the app path is hardcoded to com.hornbill.core when it should be configurable to allow you to inject an app, which in this case would translate to com.hornbill.projectmanager. I will raise this internally and reply to this thread when I have an update. Alex
AlexTumber Posted January 25, 2019 Posted January 25, 2019 @Ben Paddick I should have spotted this sooner: You need the ProjectTasks entity and not the Projects entity. So # Invoke XMLMC call, output returned as PSObject $xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.projectmanager/Projects" "addProjectTask" should be: # Invoke XMLMC call, output returned as PSObject $xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.projectmanager/ProjectTasks" "addProjectTask" I will ask internally about changing the error message to better reflect the issue. Alex 1
Ben Paddick Posted January 25, 2019 Author Posted January 25, 2019 @AlexTumber I should have spotted it sooner Thats the problem with me pasting code between two script types. Thank you for the assistance ill go give it a try. 1
Ben Paddick Posted January 25, 2019 Author Posted January 25, 2019 @AlexTumber Ok the API now responds correctly (thanks). However its not yet able to create a task. It responds with "the specified project task does not exist". If I use the projectID value returned to me within getProject it returns "failure - the specified project task does not exist". So I presume its either a permissions issue or me supplying an incorrect projectID value. The last sems hard to believe as its a only 3 digit value ("277"). The projectID I am using is the value within H_ID returned by during addProject. I am the project manager on the project so should have relevant permissions. Any ideas? Thanks 1
Ben Paddick Posted January 25, 2019 Author Posted January 25, 2019 FYI - This is the latest version of the script ## Powershell Hornbill XMLMC Module Example ## Add project task as defined in script to your Hornbill instance ## See the API documentation for a full list of supported input parameters: ## https://api.hornbill.com/apps/com.hornbill.projectmanager/ProjectTasks?op=addProjectTask # Import Hornbill XMLMC Powershell Module Import-Module "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\powershellHornbillAPIModule-master\xmlmcModule.psm1" # Define instance connection details & API key for session authentication $hbInstance ="vinci" $hbZone = "eur" $hbAPIKey = "mykey" Set-Instance -Instance $hbInstance -Key $hbAPIKey -Zone $hbZone # Define Project Tasks details - replace with values from CSV file later $projectID = "277" $TaskName = "this is a test project task" $file = get-content "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\Scripts\statuses.json" # Check the JSON values are correct on screen $JsonOutcomes = $file write-host $JsonOutcomes # Build XMLMC API call to add project task record Add-Param "projectID" "$projectID" Add-Param "name" "$TaskName" Add-Param "outcomes" "$JsonOutcomes" # Invoke XMLMC call, output returned as PSObject $xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.projectmanager/ProjectTasks" "addProjectTask" if($xmlmcOutput.status -eq "ok") { "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" "API Status: " + $xmlmcOutput.Status "API Outcome: " + $xmlmcOutput.params.outcome "New project task ID : " + $xmlmcOutput.params.projectTaskId "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" } else { # API call status not OK - return status and error to console "API Call Status : " + $xmlmcOutput.status "Error Returned : " + $xmlmcOutput.error } # Important! Remove XMLMC module from memory for security once XMLMC calls complete Remove-Module xmlmcModule
AlexTumber Posted January 28, 2019 Posted January 28, 2019 @Ben Paddick sorry to hear this is still causing issues. When you say: On 1/25/2019 at 4:41 PM, Ben Paddick said: However its not yet able to create a task. It responds with "the specified project task does not exist". I'm slightly confused as to when api you are calling. Can you confirm how many api calls you are making and in which order? Alex
Ben Paddick Posted February 1, 2019 Author Posted February 1, 2019 @AlexTumber Hi Alex - Let's start with debugging this script (GetProject) as i think the error is likely be related to why my create task fails. Is the syntax of the projectID field valid? I still get an error "API Outcome: failure - the specified project does not exist or you have no access to it" I presume its either a permissions issue or me supplying an incorrect projectID value. The last sems hard to believe as its a only 3 digit value ("277"). Thanks ## Powershell Hornbill XMLMC Module ## Get Single project details from Hornbill instance ## See the API documentation for a full list of supported API input parameters: ## https://api.hornbill.com/apps/com.hornbill.projectmanager/Projects?op=getProject # Import Hornbill XMLMC Powershell Module Import-Module "C:\Users\paddickb\OneDrive - Vinci Construction UK\Hornbill\powershellHornbillAPIModule-master\xmlmcModule.psm1" # Define instance connection details & API key for session authentication $hbInstance = "vinci" $hbZone = "eur" $hbAPIKey = "mykeyis here" Set-Instance -Instance $hbInstance -Key $hbAPIKey -Zone $hbZone # Build XMLMC API call Add-Param "projectID" "277" #Add-Param "returnBpmDetails" "1" # Invoke XMLMC call, output returned as PSObject $xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.projectmanager/Projects" "getProject" if($xmlmcOutput.status -eq "ok") { # Confirm if API searched "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" "API Status: " + $xmlmcOutput.Status "API Outcome: " + $xmlmcOutput.params.outcome "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" "Projects Details: " + $xmlmcOutput.params.projectDetails "Projects BPM Details: " + $xmlmcOutput.params.projectBPMDetails "Projects Risk Details: " + $xmlmcOutput.params.projectRiskWeighting "Projects Total Cost Details: " + $xmlmcOutput.params.projectTotalCost "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" } else { # API call status not OK - return status and error to console "API Call Status : " + $xmlmcOutput.status "Error Returned : " + $xmlmcOutput.error } # Important! Remove XMLMC module from memory for security once XMLMC calls complete Remove-Module xmlmcModule
AlexTumber Posted February 1, 2019 Posted February 1, 2019 @Ben Paddick thanks for your post. Ok, so I think the returned error is probably correct :-) Which user session are you using to invoke the api and does it have the Project Portfolio Manager role? In terms of security for project manager, you can only see and action projects that you are a stakeholder in (if you have the standard Project User role). If you have the Project Portfolio Manager role you have access to all projects. I would suggest giving your user (who you are making the api call with) the Project Portfolio Manager role. Alex
Ben Paddick Posted February 1, 2019 Author Posted February 1, 2019 @AlexTumber the apikey is associated to my account. I am in the Project Portfolio Manager role and also the assigned Project Manager on the project. I have validated access by using the the Web App to locate project and create tasks. yet still not via the API. thanks
Victor Posted February 1, 2019 Posted February 1, 2019 @Ben Paddick - API parameters are case sensitive. For getProject API: projectID - not a valid parameter projectId - correct parameter 1
Ben Paddick Posted February 1, 2019 Author Posted February 1, 2019 @Victor You are truely the Hornbill Sith Lord! That's worked perfectly! @AlexTumber - Thanks for your help as well. You got me this far. Maybe the API could benefit from a more descriptive error message for idiots like me? 2
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now