When retrieving a flow from Salesforce, it seems that you need to specify the version of the flow as well. For some reason, the List Metadata API doesn't show the version number for the active version of the flow. It does show version numbers.
For example, if I have a Flow called
My_Custom_Flow, and I make 3 versions, and don't activate any of them, List Metadata will tell me I have the following:
If I then go ahead and activate version 3 of the flow, List Metadata will now say:
Deploying and Retrieving Flows
However, the actual API name of version 3 is still
My_Custom_Flow-3, so when you go to retrieve it, you will need to call it by that name in your package.xml
<?xml version="1.0" encoding="UTF-8"?>
The same applies for the metadata Deploy API; you should deploy the flow using the full API name (including version number), with the additional caveat that you can only deploy the flow version when that version has not been activated in the org before. So if I wanted to deploy a new copy of
My_Custom_Flow to this org (where version 3 is activated), I would need to call the flow
My_Custom_Flow-4.flow so that it does not conflict with the currently active version.
Getting the Version Number for a Flow
Unfortunately, all this means that it's pretty hard to do any useful automation around flows, because Salesforce's internal versioning strategy makes them a little hard to work with. If you need a scriptable way to get the currently active or latest version of a flow from your org, the Tooling API may help a little:
WHERE DeveloperName = 'My_Custom_Flow'
This Tooling API's "query" service can give you both the currently active and the latest version number of the flow in your org.
If you need to retrieve the currently active version of the flow, you can just use the flow's API name in combination with the
ActiveVersion returned by this.
If you need to do something to automatically deploy new versions of the flow to your org, you can just take the
LatestVersion number and add 1 to get an unused version number for the new flow.