Reputation: 241
I created an profile for exporting products.
Is there a way to start the export with the api ? And then downloading that .csv file with the api ?
Upvotes: 2
Views: 509
Reputation: 13161
Yes there is a way. See the ImportExportActionController
.
Using your admin api credentials you can request the following endpoints in that order with the respective payloads:
POST /api/_action/import-export/prepare
{
"profileId": "...",
"expireDate": "2022-12-12 12:00:00"
}
profileId
would be the id of the profile you want to use for exporting. expireDate
is a date after which the export would be deemed expired and ready to be deleted. Set it sometime into the future. There's also the parameter file
which would contain the file you're trying to import, but since you want to export you just omit it.
This endpoint will return a logId
you'll need in the next step.
POST /api/_action/import-export/process
{
"logId": "..."
}
Requesting this endpoint with the logId
you got from the prior request will actually start the export/import.
The import/export will run in the message queue so you'll have to wait for the process to finish at this point.
POST /api/search/import-export-log
{
"filter": [
{
"type": "equals",
"field": "id",
"value": "..."
}
]
}
Use the search endpoint for the import_export_log
entities with the logId
you received previously as a filter. You can do so to check the state
of the process so you can proceed once it is finished. For the download you'll also need the fileId
from this record.
POST /api/_action/import-export/file/prepare-download/{fileId}
Use the fileId
you received previously to request this endpoint. It will return an accessToken
you'll need for the final request.
GET /api/_action/import-export/file/download?accessToken=...&fileId=...
Using both the fileId
and the accessToken
from earlier, request this endpoint which should yield a download stream of the exported file.
Upvotes: 4