28 May 2020

Cannot match arguments error when using acesHttpOperation

You can send updates from inside the Design Automation server using the onProgress callback mechanism - see https://forge.autodesk.com/blog/communicate-servers-inside-design-automation
The way to do that is to print a message to the command line with !ACESAPI:acesHttpOperation() - see https://forge.autodesk.com/en/docs/design-automation/v3/developers_guide/callbacks/
Note: in case of Inventor AppBundle you can use the HttpOperation() utility method 

You have to make sure that all the parameters are set correctly, adhering to these rules:
- 1st argument can be any word
2nd and 3rd argument can be anything that isn't a comma ','
4th argument can either be json {...} or anything that isn't a comma ','
5th argument must start with a word or ':' or '\' or '%' followed by zero or one dots '.' followed by zero or more of anything

Here is the regex rule to help you with this: 

\((?<name>\w+),(?<suffix>[^,]*),(?<headers>[^,]*),(?<requestContentOrFile>(?:{.+}|[^,]*)),(?<responseFile>[\w,:\/%]+\.?.*)\)

You can simply use an online editor like https://regex101.com/ to verify the string you are providing is correct - see above picture

If you're not following the rules and e.g. try to do this:

LogTrace(
  "!ACESAPI:acesHttpOperation({0},\"\",\"\",{1},\"\")",
  "onProgress",
  "{ \"current-progress\": 30, \"step\": \"apply parameters\" }"
);

Then you'll run into "Error: API failed. Reason = Cannot match arguments.":

[05/28/2020 17:02:45]     InventorCoreConsole.exe Information: 0 : RunWithArguments called
[05/28/2020 17:02:45]     InventorCoreConsole.exe Information: 0 : !ACESAPI:acesHttpOperation(onProgress,"","",{ "current-progress": 30, "step": "apply parameters" },"")
[05/28/2020 17:02:45] !!!!This is an API callback => "    InventorCoreConsole.exe Information: 0 : !ACESAPI:acesHttpOperation(onProgress,"","",{ "current-progress": 30, "step": "apply parameters" },"")"
[05/28/2020 17:02:45] Start processing API request acesHttpOperation.
[05/28/2020 17:02:45] Error: API failed. Reason = Cannot match arguments.
[05/28/2020 17:02:45] Done processing API request with result: failed. Time spent 0.0008435 seconds.

The problem with the above code is that the 5th argument cannot be an empty string, and should be modified to e.g.:

LogTrace(
  "!ACESAPI:acesHttpOperation({0},\"\",\"\",{1},null)",
  "onProgress",
  "{ \"current-progress\": 30, \"step\": \"apply parameters\" }"
);

 

Related Article