Craft 3 - Save new Entry with Relations (Categories/Assets)
This should be as simple as setting the relation field (category, asset, etc.) value on the entry as an array of related element IDs before saving.
$entry-&gt;setFieldValue('categoryFieldHandle', [$categoryId1, $categoryId2]);

Craft::$app-&gt;elements-&gt;saveElement($entry);

This will work for all relation fields:
$entry-&gt;setFieldValue('assetFieldHandle', [$assetId1, $assetId2]);

Craft::$app-&gt;elements-&gt;saveElement($entry);