Using the POST api/new_code_periods/set Web API should help you. You can find a link to the Web API documentation for your SonarQube instance in the footer of your instance, and you might also find this guide helpful:
I’d also invite you to raise a thread in our “Product Manager for a Day” category, or I can just move this thread there if you’d like.