For code examples you can take a look at the gvm-tools scripts. They use the same API
To get the id of a task you have to look at the GMP protocol doc and the response xml data. E.g. for create_task the new task id is return as the id attribute of the response.