I am using http api call for downloading D365 export csv file. It is downloading in binary format "$content-type": "application/octet-stream"
{
"$content-type": "application/octet-stream",
"$content": "UEsDBBQAAAAIAL07VFMaQk8xFQcAAEkXAAAZAAAAQVZBVmV"
}
I tried the below code still it is not decoded properly and giving junk values. Please let me know the correct way to get csv file.
I think $content holds full file data not just the content.
json(base64ToString(replace(body('Get_blob_content')?['$content'],'77u/','')))
@string(body('Download_the_package_file')['$content'])
I observe that you are exporting a CSV file but reading a .json file from the blob. Based on your provided information, we have 3 scenarios in place.
1. If test.json file contains AVAVendorEntity.csv elements You can retrieve these files without the junk by using string expressions for the whole output.
Example : if body contains
{
"$content-type": "application/octet-stream",
"$content": "Ww0KICB7DQogICAgImlkIjogIjEiLA0KICAgICJyZWNlaXZlciI6ICIgMTIzODUiLA0KICAgICJwYXlsb2FkIjogIiB7J21lc3NhZ2UnOiAndGVzdCAxJyIsDQogICAgIm9wZXJhdG9yIjogIiAnRW5naW5lSWQnOiAzIiwNCiAgICAic2VuZGVyIjogIiAnUGVyc29uSWQnOiAxIg0KICB9LA0KICB7DQogICAgImlkIjogIjIiLA0KICAgICJyZWNlaXZlciI6ICIgMTIzNDciLA0KICAgICJwYXlsb2FkIjogIiB7J21lc3NhZ2UnOiAndGVzdCAyJyIsDQogICAgIm9wZXJhdG9yIjogIiAnRW5naW5lSWQnOiAzIiwNCiAgICAic2VuZGVyIjogIiAnUGVyc29uSWQnOiAyIg0KICB9DQpd"
}
then we use
string(triggerBody())
2. If there are only CSV elements but having .json extension If this is the case then we use JSON instead of string
Example: If body contains
{
"$content-type": "application/octet-stream",
"$content": "dXJsCXVzZXJfaWQJdG9rZW5faWQJdXNlcm5hbWUJcGFzc3dvcmQNCmh0dHA6Ly93d3cudHdpdHRlci5jb20vYTg1CTEJMTIzMTIzMTIzCWFiaGluYXYJYWJjDQpodHRwOi8vd3d3LnR3aXR0ZXIuY29tL3NvYnRpYW5raXQJMgk4OTk4OTkJYW5raXQJZGVmDQpodHRwOi8vd3d3LnR3aXR0ZXIuY29tL2FiaGlqaXRrYW5lCTMJNDU2MTIzMTIzCWFiaGlqaXQJeHl6DQo="
}
then we use
json(triggerBody())
3. Change the content-type accordingly
4. The problem might be in API call while extracting the data
For converting the desired output into .csv one of the workarounds is you can always store them into blob using the .csv extension and then it will automatically convert the data into CSV format.