{"section":"known-issues","requestedLocale":"en","requestedSlug":"collections-created-by-api-and-products-inserted-by-api-insert-sku-by-file-not-working-properly","locale":"en","slug":"collections-created-by-api-and-products-inserted-by-api-insert-sku-by-file-not-working-properly","path":"docs/en/known-issues/Catalog/collections-created-by-api-and-products-inserted-by-api-insert-sku-by-file-not-working-properly.md","branch":"main","content":"## Summary\n\n\nToday we have some ways to create and add products to a collection. We can use our new Collection Adimn, our legacy collection admin and we can use API to create collections and add products to a collection. But we have a problem when creating collections through API and add products to this collection using the route `api/catalog/pvt/collection//stockkeepingunit/importinsert`. With this API we are able to add products to the collection using a spreadsheet.\n\nThe problem happens every time we create a collection by API and try to use this `importinsert` API to add products. The products do not become available to the collection created.\n\n\n#### Simulation\n\n\n- Create a collection using API:\n\n    curl --location -g --request POST 'https://.vtexcommercestable.com.br/api/catalog/pvt/collection?an=' \\--header 'Content-Type: application/json' \\--header 'Accept: application/json' \\--header 'x-vtex-api-appKey: vtexappkey-appvtex' \\--header 'x-vtex-api-appToken:  ' \\--data-raw '\\{    \"Name\": \"testando\",    \"Searchable\": false,    \"Highlight\": false,    \"DateFrom\": \"2017-09-27T10:47:00\",    \"DateTo\": \"2027-09-27T10:47:00\"\\}'\n\n\n- Add products to this collection with the Import Insert API:\n\n    curl --location -g --request POST 'https://.vtexcommercestable.com.br/api/catalog/pvt/collection//stockkeepingunit/importinsert' \\--header 'Content-Type: application/json' \\--header 'Accept: application/json' \\--header 'VtexIdclientAutCookie: ' \\--form 'file=@\"/path/to/file\"'\n\n- After about 30 minutes, check the products without the collection information and the collection page not rendering the products:\n\n    curl --location -g --request GET 'https://.vtexcommercestable.com.br/api/catalog_system/pub/products/search/?fq=H:' \\--header 'Accept: application/json' \\--header 'Content-Type: application/json'\n\n#### Workaround\n\n\n\nThere are two viable workarounds for this issue:\n\n1️⃣ Add products to collections created by API using Admin Spreadsheet Upload or use the Insert SKU to subcollection API to insert SKUs to collections:\n\nTo add SKUs to collections using API, we have to follow these steps:\n\nCreate collection:\n\n    curl --location -g --request POST 'https://catalog.vtexcommercestable.com.br/api/catalog/pvt/collection?an=(https://catalog.vtexcommercestable.com.br/api/catalog/pvt/collection?an=)' \\--header 'Content-Type: application/json' \\--header 'Accept: application/json' \\--header 'x-vtex-api-appKey: vtexappkey-appvtex' \\--header 'x-vtex-api-appToken: ' \\--header 'Cookie: janus_sid=7026383e-2070-4b68-a2c2-59cf729ec0da' \\--data-raw '\\{ \"Name\": \"testando\", \"Searchable\": false, \"Highlight\": false, \"DateFrom\": \"2017-09-27T10:47:00\", \"DateTo\": \"2027-09-27T10:47:00\"\\}'\n\nCreate subcollection:\n\n    curl --location -g --request POST 'https://catalog.vtexcommercestable.com.br/api/catalog/pvt/subcollection?an=(https://catalog.vtexcommercestable.com.br/api/catalog/pvt/subcollection?an=)' \\--header 'Content-Type: application/json' \\--header 'Accept: application/json' \\--header 'VtexIdclientAutCookie: ' \\--header 'Cookie: janus_sid=7026383e-2070-4b68-a2c2-59cf729ec0da' \\--data-raw '\\{ \"CollectionId\": 173, \"Name\": \"Inclusive 1\", \"Type\": \"Inclusive\", \"PreSale\": false, \"Release\": false\\}'\n\nInsert SKU to subcollection:\n\n    curl --location -g --request POST 'https://catalog.vtexcommercestable.com.br/api/catalog/pvt/subcollection//stockkeepingunit?an=(https://catalog.vtexcommercestable.com.br/api/catalog/pvt/subcollection//stockkeepingunit?an=)' \\--header 'Content-Type: application/json' \\--header 'Accept: application/json' \\--header 'VtexIdclientAutCookie: ' \\--header 'Cookie: janus_sid=7026383e-2070-4b68-a2c2-59cf729ec0da' \\--data-raw '\\{ \"SkuId\": 2000037\\}'\n\n\n2️⃣ There is also the possibility to use the `api/catalog/pvt/collection//stockkeepingunit/importinsert` and then, after the import is complete and all products were added, to go manually, via UI and update the entire collection data, either by changing its name or its begin/end date.\n\nThis way, the collection products that were just inserted will be forced into a reindex and the collection related data will be added to them, allowing the correct display of the needed information."}