Power Automate Anaplan integration Part 2

Posted by     "Andrey Paltusov" on Tuesday, February 2, 2021

Оглавление

Power Automate flow

   In this part I will describe file exchange process between Anaplan and SharePoint, built in Microsoft Power Automate. Exporting files from Anaplan consists of several steps:

  1. Starting the export task
  2. Checking the export task is ready
  3. Downloading the file

A full description of API methods can be found here. To export files, you need to know the file export code. To get the list of export files, you should call the API method https://api.anaplan.com/1/3/workspaces/8a8196b15b7dbae6015b8694411d13fe/models/75A40874E6B64FA3AE0743278996850F/exports. Don’t forget to add the authorization key from the previous article to the header. In the current example, I will store export codes and file names in the SharePoint list.

Let’s continue with the flow I described in the previous article. At first, we need to initialize several new variables for storing temporary data.

varAccessStatus – authentication status

varAccessToken – authentication access token, we will use it in all API methods

varExportsList – export file list from SharePoint

varExportStatus – temporary variable to store export task status

varFileName – temporary variable to store the name of the export file

First, let’s check the authentication status, if it is successful, then we get a list of files for export.

For each export file, we get the values of the work place, model, export code and file name.

Then foreach file let’s start export task.

Check if task is started


{
    "type": "object",
    "properties": {
        "meta": {
            "type": "object",
            "properties": {
                "schema": {
                    "type": "string"
                }
            }
        },
        "status": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "integer"
                },
                "message": {
                    "type": "string"
                }
            }
        },
        "task": {
            "type": "object",
            "properties": {
                "taskId": {
                    "type": "string"
                },
                "taskState": {
                    "type": "string"
                },
                "creationTime": {
                    "type": "integer"
                }
            }
        }
    }
}


Now we need to wait for the export task to complete. I used the DO WHILE construction, in the body of which I check the status of the export task and assign it to the temporary variable varExportStatus.

{
    "type": "object",
    "properties": {
        "meta": {
            "type": "object",
            "properties": {
                "schema": {
                    "type": "string"
                }
            }
        },
        "status": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "integer"
                },
                "message": {
                    "type": "string"
                }
            }
        },
        "task": {
            "type": "object",
            "properties": {
                "taskId": {
                    "type": "string"
                },
                "currentStep": {
                    "type": "string"
                },
                "progress": {
                    "type": "integer"
                },
                "result": {
                    "type": "object",
                    "properties": {
                        "details": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "occurrences": {
                                        "type": "integer"
                                    },
                                    "type": {
                                        "type": "string"
                                    },
                                    "values": {
                                        "type": "array"
                                    }
                                },
                                "required": [
                                    "occurrences",
                                    "type",
                                    "values"
                                ]
                            }
                        },
                        "failureDumpAvailable": {
                            "type": "boolean"
                        },
                        "objectId": {
                            "type": "string"
                        },
                        "successful": {
                            "type": "boolean"
                        }
                    }
                },
                "taskState": {
                    "type": "string"
                },
                "creationTime": {
                    "type": "integer"
                }
            }
        }
    }
}


After the file export task is complete, you need to get a list of its chunks and export them to SharePoint. Unfortunately, I was unable to get it working with multiple chunks in the case of non-text files. Due to the encoding of the temporary variable for storing pieces of the file, XLSX files were damaged and saved in an incorrect format. In this example my file consists of one chunk.


{
    "type": "object",
    "properties": {
        "meta": {
            "type": "object",
            "properties": {
                "paging": {
                    "type": "object",
                    "properties": {
                        "currentPageSize": {
                            "type": "integer"
                        },
                        "offset": {
                            "type": "integer"
                        },
                        "totalSize": {
                            "type": "integer"
                        }
                    }
                },
                "schema": {
                    "type": "string"
                }
            }
        },
        "status": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "integer"
                },
                "message": {
                    "type": "string"
                }
            }
        },
        "chunks": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "name": {
                        "type": "string"
                    }
                },
                "required": [
                    "id",
                    "name"
                ]
            }
        }
    }
}


At the end of the file transfer cycle, clear the temporary variable with the status of the export task

Everything is ready to test the flow. Run the test and check for the file in the SharePoint library.

--Андрей Палтусов--


comments powered by Disqus