0

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'])

enter image description here

  • 1
    when I used `string(triggerBody())` with `compose` connector it was working for me and could able to retrieve the csv file. Instead of using only content try sending the whole binary format. – SwethaKandikonda Oct 21 '21 at 13:20
  • thanks for you input, but still I am getting junk values... May be I am thinking the problem is in Api call URI? from 2 days blocked here only – Lathik Kumar N Oct 21 '21 at 15:18
  • Can you please make sure if the data is extracted right? Also, I observe that you are exporting a CSV file but reading a .json file? – SwethaKandikonda Oct 23 '21 at 17:44
  • 1
    You are downloading a ZIP file, not CSV. AVAVendorMasterEntity.csv is inside the package. – 10p Nov 02 '21 at 16:16
  • yes it was ZIP file... I need to save as .zip and extract to get .csv file.. thank you – Lathik Kumar N Mar 30 '22 at 08:36

1 Answers1

2

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())

enter image description here

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())

enter image description here

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. enter image description here

SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18