Question

I'm trying to understand (and eventually make it work) batch request on the google group API.
With Oauth2 Playground I know how to perform a single request with:
on step 1 authorised API are
https://www.googleapis.com/auth/admin.directory.group.member.readonly
https://www.googleapis.com/auth/admin.directory.group.member
https://www.googleapis.com/auth/admin.directory.group.readonly
https://www.googleapis.com/auth/admin.directory.group

on step 3 I'm making a post request with:
request URI: https://www.googleapis.com/admin/directory/v1/groups/mytestgroup@domain.ext/members
and the body is:

{
"email": "lya@example.com",
"role": "MEMBER"
}

So far so good, but now I'm trying to do the same in a batch request
I tried to follow the explanation here:
https://developers.google.com/admin-sdk/directory/v1/guides/batch#example
but I didn't understood everything so I went there:
https://developers.google.com/storage/docs/json_api/v1/how-tos/batch

So I did the following request with, on step 1 the same API but on step 3:
a post request to:
https://www.googleapis.com/batch
with a custom content-type:
the header is now
multipart/mixed; boundary="batch_foobarbaz"
and in the body request:

--batch_foobarbaz
Content-Type: application/http
POST /admin/directory/v1/groups/mytestgroup@domain.ext/members HTTP/1.1

Content-Type: application/json
content-length: 58
{
"email": "liz@example.com",
"role": "MEMBER"
}

--batch_foobarbaz--

I also tried different variants but I never get to do the correct request, I systematically get 400 error.
Can someone help me with that, I don't know what I can do to correct that.
Thanks in advance, Harold

Was it helpful?

Solution

Okey sorry for the inconvenience, I found my answer. Here is what I've done:

on step 1 authorised API are:
https://www.googleapis.com/auth/admin.directory.group.member.readonly
https://www.googleapis.com/auth/admin.directory.group.member
https://www.googleapis.com/auth/admin.directory.group.readonly
https://www.googleapis.com/auth/admin.directory.group

on step 3 I'm making a post request with:
https://www.googleapis.com/batch
with a custom content-type: multipart/mixed; boundary="batch_foobarbaz"

body request:

--batch_foobarbaz
Content-Type: application/http
Content-Transfer-Encoding: binary

POST /admin/directory/v1/groups/mytestgroup@domain.ext/members HTTP/1.1
Content-type: application/json

{"email": "ldn@example.com", "role": "MEMBER"}
--batch_foobarbaz--

the important part here are the carriage return. They are mandatory after Content-Transfer-Encoding: binary and after Content-type: application/json

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top