batch request on google group api with oauth2-playground

731 views Asked by At

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/[email protected]/members
and the body is:

{
"email": "[email protected]",
"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/[email protected]/members HTTP/1.1

Content-Type: application/json
content-length: 58
{
"email": "[email protected]",
"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

1

There are 1 answers

0
Harold On BEST ANSWER

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/[email protected]/members HTTP/1.1
Content-type: application/json

{"email": "[email protected]", "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