How to create batch request to gmail api in angular 7
The short and sweet is...What code can I use within angular 7 to make batch requests to the gmail api batch endpoint?
I have been able to successfully make a batch request with the gmail api using postman...using the raw body format but cannot seem to craft the proper post request to the gmail api batch endpoint from within my angular 7 app. I am receiving error response 400, due to invalid syntax.
In postman it is as simple as setting the token with Authorization: Bearer and Content-Type: multipart/mixed; boundary="foo_bar" then making the body a raw request with:
--foo_bar
Content-Type: application/http
GET /gmail/v1/users/me/threads/16805106cf1751bc
--foo_bar
Content-Type: application/http
GET /gmail/v1/users/me/threads/16804cfeaeb94c4a
--foo_bar--
I have tried this in angular 7:
private readonly BATCH_API_URL: string = 'https://www.googleapis.com/batch/gmail/v1';
batchTest() {
let authToken = this.authService.getToken();
let body = `--foo_bar
Content-Type: application/http
GET /gmail/v1/users/me/threads/16805106cf1751bc
--foo_bar
Content-Type: application/http
GET/gmail/v1/users/me/threads/16804cfeaeb94c4a
--foo_bar--`
this.httpClient.post(this.BATCH_API_URL, body, {
headers: new HttpHeaders({
'Authorization': `Bearer ${authToken}`,
'Content-Type': `multipart/mixed; boundary="foo_bar"`
})
}).subscribe(response => {
console.log(response);
})
}
I have also tried:
let body = String.raw`--foo_barrnContent-Type: application/httprnrnGET /gmail/v1/users/me/threads/16805106cf1751bcrnrn--foo_bar--`
...and a few other long shots like converting the string to a BufferArray and passing that in as body...
I'm trying to figure out how to properly form the body of the post request to the gmail api batch endpoint so that I can make and receive batch requests...Super thankful to anybody that can help me to solve this.
angular http gmail content-type batch-request
add a comment |
The short and sweet is...What code can I use within angular 7 to make batch requests to the gmail api batch endpoint?
I have been able to successfully make a batch request with the gmail api using postman...using the raw body format but cannot seem to craft the proper post request to the gmail api batch endpoint from within my angular 7 app. I am receiving error response 400, due to invalid syntax.
In postman it is as simple as setting the token with Authorization: Bearer and Content-Type: multipart/mixed; boundary="foo_bar" then making the body a raw request with:
--foo_bar
Content-Type: application/http
GET /gmail/v1/users/me/threads/16805106cf1751bc
--foo_bar
Content-Type: application/http
GET /gmail/v1/users/me/threads/16804cfeaeb94c4a
--foo_bar--
I have tried this in angular 7:
private readonly BATCH_API_URL: string = 'https://www.googleapis.com/batch/gmail/v1';
batchTest() {
let authToken = this.authService.getToken();
let body = `--foo_bar
Content-Type: application/http
GET /gmail/v1/users/me/threads/16805106cf1751bc
--foo_bar
Content-Type: application/http
GET/gmail/v1/users/me/threads/16804cfeaeb94c4a
--foo_bar--`
this.httpClient.post(this.BATCH_API_URL, body, {
headers: new HttpHeaders({
'Authorization': `Bearer ${authToken}`,
'Content-Type': `multipart/mixed; boundary="foo_bar"`
})
}).subscribe(response => {
console.log(response);
})
}
I have also tried:
let body = String.raw`--foo_barrnContent-Type: application/httprnrnGET /gmail/v1/users/me/threads/16805106cf1751bcrnrn--foo_bar--`
...and a few other long shots like converting the string to a BufferArray and passing that in as body...
I'm trying to figure out how to properly form the body of the post request to the gmail api batch endpoint so that I can make and receive batch requests...Super thankful to anybody that can help me to solve this.
angular http gmail content-type batch-request
I'm really sorry. I noticed that I misunderstand your situation. In my environment, I also confirmed that the request body withoutContent-ID
worked. Because my answer is not useful, I would like to delete it. By the way, in your script, there is no empty line betweenContent-Type: application/http
andGET /gmail/v1/users/me/threads/16805106cf1751bc
. This is the different from your above request body. If you use this, the error occurs. Could you please confirm it again?
– Tanaike
Jan 1 at 8:37
add a comment |
The short and sweet is...What code can I use within angular 7 to make batch requests to the gmail api batch endpoint?
I have been able to successfully make a batch request with the gmail api using postman...using the raw body format but cannot seem to craft the proper post request to the gmail api batch endpoint from within my angular 7 app. I am receiving error response 400, due to invalid syntax.
In postman it is as simple as setting the token with Authorization: Bearer and Content-Type: multipart/mixed; boundary="foo_bar" then making the body a raw request with:
--foo_bar
Content-Type: application/http
GET /gmail/v1/users/me/threads/16805106cf1751bc
--foo_bar
Content-Type: application/http
GET /gmail/v1/users/me/threads/16804cfeaeb94c4a
--foo_bar--
I have tried this in angular 7:
private readonly BATCH_API_URL: string = 'https://www.googleapis.com/batch/gmail/v1';
batchTest() {
let authToken = this.authService.getToken();
let body = `--foo_bar
Content-Type: application/http
GET /gmail/v1/users/me/threads/16805106cf1751bc
--foo_bar
Content-Type: application/http
GET/gmail/v1/users/me/threads/16804cfeaeb94c4a
--foo_bar--`
this.httpClient.post(this.BATCH_API_URL, body, {
headers: new HttpHeaders({
'Authorization': `Bearer ${authToken}`,
'Content-Type': `multipart/mixed; boundary="foo_bar"`
})
}).subscribe(response => {
console.log(response);
})
}
I have also tried:
let body = String.raw`--foo_barrnContent-Type: application/httprnrnGET /gmail/v1/users/me/threads/16805106cf1751bcrnrn--foo_bar--`
...and a few other long shots like converting the string to a BufferArray and passing that in as body...
I'm trying to figure out how to properly form the body of the post request to the gmail api batch endpoint so that I can make and receive batch requests...Super thankful to anybody that can help me to solve this.
angular http gmail content-type batch-request
The short and sweet is...What code can I use within angular 7 to make batch requests to the gmail api batch endpoint?
I have been able to successfully make a batch request with the gmail api using postman...using the raw body format but cannot seem to craft the proper post request to the gmail api batch endpoint from within my angular 7 app. I am receiving error response 400, due to invalid syntax.
In postman it is as simple as setting the token with Authorization: Bearer and Content-Type: multipart/mixed; boundary="foo_bar" then making the body a raw request with:
--foo_bar
Content-Type: application/http
GET /gmail/v1/users/me/threads/16805106cf1751bc
--foo_bar
Content-Type: application/http
GET /gmail/v1/users/me/threads/16804cfeaeb94c4a
--foo_bar--
I have tried this in angular 7:
private readonly BATCH_API_URL: string = 'https://www.googleapis.com/batch/gmail/v1';
batchTest() {
let authToken = this.authService.getToken();
let body = `--foo_bar
Content-Type: application/http
GET /gmail/v1/users/me/threads/16805106cf1751bc
--foo_bar
Content-Type: application/http
GET/gmail/v1/users/me/threads/16804cfeaeb94c4a
--foo_bar--`
this.httpClient.post(this.BATCH_API_URL, body, {
headers: new HttpHeaders({
'Authorization': `Bearer ${authToken}`,
'Content-Type': `multipart/mixed; boundary="foo_bar"`
})
}).subscribe(response => {
console.log(response);
})
}
I have also tried:
let body = String.raw`--foo_barrnContent-Type: application/httprnrnGET /gmail/v1/users/me/threads/16805106cf1751bcrnrn--foo_bar--`
...and a few other long shots like converting the string to a BufferArray and passing that in as body...
I'm trying to figure out how to properly form the body of the post request to the gmail api batch endpoint so that I can make and receive batch requests...Super thankful to anybody that can help me to solve this.
angular http gmail content-type batch-request
angular http gmail content-type batch-request
edited Jan 2 at 5:04
San Francisco Sunrise
asked Jan 1 at 2:00
San Francisco SunriseSan Francisco Sunrise
4914
4914
I'm really sorry. I noticed that I misunderstand your situation. In my environment, I also confirmed that the request body withoutContent-ID
worked. Because my answer is not useful, I would like to delete it. By the way, in your script, there is no empty line betweenContent-Type: application/http
andGET /gmail/v1/users/me/threads/16805106cf1751bc
. This is the different from your above request body. If you use this, the error occurs. Could you please confirm it again?
– Tanaike
Jan 1 at 8:37
add a comment |
I'm really sorry. I noticed that I misunderstand your situation. In my environment, I also confirmed that the request body withoutContent-ID
worked. Because my answer is not useful, I would like to delete it. By the way, in your script, there is no empty line betweenContent-Type: application/http
andGET /gmail/v1/users/me/threads/16805106cf1751bc
. This is the different from your above request body. If you use this, the error occurs. Could you please confirm it again?
– Tanaike
Jan 1 at 8:37
I'm really sorry. I noticed that I misunderstand your situation. In my environment, I also confirmed that the request body without
Content-ID
worked. Because my answer is not useful, I would like to delete it. By the way, in your script, there is no empty line between Content-Type: application/http
and GET /gmail/v1/users/me/threads/16805106cf1751bc
. This is the different from your above request body. If you use this, the error occurs. Could you please confirm it again?– Tanaike
Jan 1 at 8:37
I'm really sorry. I noticed that I misunderstand your situation. In my environment, I also confirmed that the request body without
Content-ID
worked. Because my answer is not useful, I would like to delete it. By the way, in your script, there is no empty line between Content-Type: application/http
and GET /gmail/v1/users/me/threads/16805106cf1751bc
. This is the different from your above request body. If you use this, the error occurs. Could you please confirm it again?– Tanaike
Jan 1 at 8:37
add a comment |
1 Answer
1
active
oldest
votes
let body ='--foo_barn' +
'Content-Type: application/httpnn' +
'GET https://www.googleapis.com/gmail/v1/users/me/threads/16805106cf1751bcn' +
'--foo_barn' +
'Content-Type: application/httpnn' +
'GET https://www.googleapis.com/gmail/v1/users/me/threads/16805106cf1751bcn' +
'--foo_bar--'
Had a similar problem to you. Fixed it by concatenating a group of strings for the body instead of using a multi line string (`). Which seemed to add in unwanted spaces and line breaks
Also by including the full HTTP Request within the batch body.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992605%2fhow-to-create-batch-request-to-gmail-api-in-angular-7%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
let body ='--foo_barn' +
'Content-Type: application/httpnn' +
'GET https://www.googleapis.com/gmail/v1/users/me/threads/16805106cf1751bcn' +
'--foo_barn' +
'Content-Type: application/httpnn' +
'GET https://www.googleapis.com/gmail/v1/users/me/threads/16805106cf1751bcn' +
'--foo_bar--'
Had a similar problem to you. Fixed it by concatenating a group of strings for the body instead of using a multi line string (`). Which seemed to add in unwanted spaces and line breaks
Also by including the full HTTP Request within the batch body.
add a comment |
let body ='--foo_barn' +
'Content-Type: application/httpnn' +
'GET https://www.googleapis.com/gmail/v1/users/me/threads/16805106cf1751bcn' +
'--foo_barn' +
'Content-Type: application/httpnn' +
'GET https://www.googleapis.com/gmail/v1/users/me/threads/16805106cf1751bcn' +
'--foo_bar--'
Had a similar problem to you. Fixed it by concatenating a group of strings for the body instead of using a multi line string (`). Which seemed to add in unwanted spaces and line breaks
Also by including the full HTTP Request within the batch body.
add a comment |
let body ='--foo_barn' +
'Content-Type: application/httpnn' +
'GET https://www.googleapis.com/gmail/v1/users/me/threads/16805106cf1751bcn' +
'--foo_barn' +
'Content-Type: application/httpnn' +
'GET https://www.googleapis.com/gmail/v1/users/me/threads/16805106cf1751bcn' +
'--foo_bar--'
Had a similar problem to you. Fixed it by concatenating a group of strings for the body instead of using a multi line string (`). Which seemed to add in unwanted spaces and line breaks
Also by including the full HTTP Request within the batch body.
let body ='--foo_barn' +
'Content-Type: application/httpnn' +
'GET https://www.googleapis.com/gmail/v1/users/me/threads/16805106cf1751bcn' +
'--foo_barn' +
'Content-Type: application/httpnn' +
'GET https://www.googleapis.com/gmail/v1/users/me/threads/16805106cf1751bcn' +
'--foo_bar--'
Had a similar problem to you. Fixed it by concatenating a group of strings for the body instead of using a multi line string (`). Which seemed to add in unwanted spaces and line breaks
Also by including the full HTTP Request within the batch body.
answered Jan 11 at 17:08
Barlow96Barlow96
305
305
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992605%2fhow-to-create-batch-request-to-gmail-api-in-angular-7%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'm really sorry. I noticed that I misunderstand your situation. In my environment, I also confirmed that the request body without
Content-ID
worked. Because my answer is not useful, I would like to delete it. By the way, in your script, there is no empty line betweenContent-Type: application/http
andGET /gmail/v1/users/me/threads/16805106cf1751bc
. This is the different from your above request body. If you use this, the error occurs. Could you please confirm it again?– Tanaike
Jan 1 at 8:37