将 CSV 文件导入 Shopware 6 的 REST 调用是什么?

What are the REST calls to import a CSV file into Shopware 6?

我们看到了 https://developer.shopware.com/docs/guides/integrations-api 但找不到 API 的详细文档。

编辑:我发现 https://my-shop-host.example/api/v2/_info/swagger.html 描述了所有可用的 API 和 import-export-file 端点,但没有清楚地描述如何使用它们(以及使用哪些)。

我相信我们需要调用(从管理面板工作流程中提取)

然后

触发导入。

但是文件是如何上传的?

是否有更简单的方法,例如一次调用?

我从身份验证开始

curl 'http://example.com/api/oauth/token'\
  -H 'Accept: pplication/vnd.api+json'\
  -H 'Content-Type: application/json' \
  --data '{
    "grant_type": "client_credentials",
    "client_id": "<my client ID from the integration>",
    "client_secret": "<my secret>"
  }'  | jq .access_token

此 returns 和有效期为 10 分钟的身份验证令牌。

我存储到变量$B

接下来我上传文件并将到期日期设置为未来 10 天:

curl 'http://example.com/api/v2/_action/import-export/prepare' \
  -H 'Accept: application/vnd.api+json' \
  -H "Authorization: Bearer $B"
  --form "file=@\"products.csv\"" --form "profileId=d4ec3999a33242a690ca5c213a7145cd" --form "expireDate=+10 days"    | jq .log.id

这个returns一个log.id字段

这个字段必须传递给流程调用

curl 'http://example.com/api/v2/_action/import-export/process'  \
 -H 'Accept: application/vnd.api+json' \ 
 -H 'Content-type: application/json' \
 -H "Authorization: Bearer $B"  --data '{"logId":"1410eaa1ca434744a8c211b60f65a3c5","offset":0}'

编辑:必须使用最后返回的偏移量单独触发每个块,并将其再次传递给 process 调用。