To change the sharing permission of a file using Drive API, use Method: permissions.create
with the following request body:
{
"role": "writer",
"type": "anyone"
}
I tried this using the API Explorer and got the desired result.
Output
References: