Google Calendar API batch request - Failed to get multipart boundary - google-calendar-api

I'm trying to do a batch call to get Calendars from Google.
I've tried following several answers here on StackOverflow:
What is the endpoint to make batch request for Google Calendar v3 API
Batch request in Google Calendar V3 REST API
and also followed the Google Documentation:
https://developers.google.com/calendar/api/guides/batch#format-of-a-batch-request
Since the general endpoint (https://www.googleapis.com/batch) is deprecated, I'm using https://www.googleapis.com/batch/calendar/v3 to post to.
I'm posting a plain text body:
POST /batch/calendar/v3 HTTP/1.1
Content-Type: multipart/mixed; boundary="batch_foobarbaz"
--batch_foobarbaz
Content-Type: application/http
GET /calendar/v3/calendars/*calendarId1*
--batch_foobarbaz
Content-Type: application/http
GET /calendar/v3/calendars/*calendarId2*
--batch_foobarbaz--
The result I keep getting is:
{
"error": {
"code": 400,
"message": "Failed to get multipart boundary.",
"status": "INVALID_ARGUMENT"
}
}
Can anyone tell me what I'm doing wrong here?
Thanks!

Related

Google Classroom API | How add scopes in HTTP request

I want to get a list of courses from an audience by HTTP request, I have set the required areas in the project in Google Cloud, but I still get an error when I try to get the courses.
P.S - Please do not offer me documentation and libraries, do not try to convince me, I just need an HTTP request.
{
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"status": "PERMISSION_DENIED",
"details": [{
"#type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT",
"domain": "googleapis.com",
"metadata": {
"method": "google.classroom.v1.Courses.ListCourses",
"service": "classroom.googleapis.com"
}
}]
}
}
I tried adding ?scope=https://www.googleapis.com/auth/classroom.courses.readonly to the end of the link
Here is the request template
curl \
'https://classroom.googleapis.com/v1/courses?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
Im going to assume that you are using courses list method
The call should look something like this in raw HTTP Request
GET https://classroom.googleapis.com/v1/courses HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
The access token ([YOUR_ACCESS_TOKEN]) you are sending must be authorized with the proper scope. If you check the documentation page for the method you are using you will see that you should have authorized the user with one of these scopes
So in your case the error Request had insufficient authentication scopes. means that when you requested authorization you did not request one of the scopes above. There for your access token has insufficient authorization scopes to make the request.
The solution is to reauthorize your user with one of the scopes required by the method in question.
You can read more about how to request authorization and what scopes are in the Using OAuth 2.0 to Access Google APIs documentation page.
Hint: Your very first in the oauth2 flow contains the scope.
https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/classroom.courses&response_type=code&redirect_uri=http%3A//127.0.0.1%3A9004&client_id=client_id
This video may help you understand scopes Understanding Google OAuth 2.0 with curl since you appear to be using curl and not just raw HTTP calls.

Google Calendar API batch inserting has stopped working

I have an application that has been successfully using HTTP batch requests to insert, edit, and delete events via the Google Calendar API. In the last couple of days, the individual requests within the batches have started returning 404 errors (although the batch itself gets a 200 success response). Making those same requests as individual requests using the same authorization header is still working.
I'm pretty sure that this isn't related to the forthcoming shutdown of Google's global HTTP batch endpoints because we're using https://www.googleapis.com/batch/calendar/v3 as our endpoint.
Here's an example of what I'm trying to do:
https://www.googleapis.com/batch/calendar/v3
Authorization: Bearer your_auth_token
Content-Type: multipart/mixed; boundary=batch_google_calendar
--batch_google_calendar
Content-Type: application/http
Content-ID: <item-0-batchevent#example.com>
POST calendar/v3/calendars/your_calendar_id#group.calendar.google.com/events
Content-Type: application/json
{"summary":"batch API test","start":{"date":"2020-07-31"},"end":{"date":"2020-07-31"}}
--batch_google_calendar--
And the response is:
--batch_3J6sfuPtVQbjZLcpUe06245gKlO31YnC
Content-Type: application/http
Content-ID: <response-item-0-batchevent#example.com>
HTTP/1.1 404 Not Found
Vary: Origin
Vary: X-Origin
Vary: Referer
Content-Type: application/json; charset=UTF-8
[{
"error": {
"code": 404,
"message": "URL path: /v3/calendars/your_calendar_id#group.calendar.google.com/events could not be resolved. Maybe there is an error parsing the batch item.",
"status": "NOT_FOUND"
}
}
]
--batch_3J6sfuPtVQbjZLcpUe06245gKlO31YnC--
And here's an example of an individual request that's working:
https://www.googleapis.com/calendar/v3/calendars/your_calendar_id#group.calendar.google.com/events
Authorization: Bearer your_auth_token
Content-Type: application/json
{"summary":"API test","start":{"date":"2020-07-31"},"end":{"date":"2020-07-31"}}
Why might the individual request be succeeding but the batch request fail?
Google gave a helpful reply via their issue tracker: there was an error in the way that batch entry paths were specific in my application. This had worked without errors until last week, so I think something must have changed at their end to make it less tolerant of mistakes.
The error we had made was omitting the leading slash in the path in each batch entry. Here's what we were doing:
POST calendar/v3/calendars/your_calendar_id#group.calendar.google.com/events
And here's what we should have been doing:
POST /calendar/v3/calendars/your_calendar_id#group.calendar.google.com/events
I hope that this might be helpful to anyone else who ever finds themselves in a similar situation!

ASP.NET WebAPI - OAuth returning "error": "invalid_grant" after validation success

I'm sending a request from my MVC application to my WebAPI where the OAuth2 is implemented. Request is something like:
Content-Type: application/application/x-www-form-urlencoded
Accept: application/json
grant_type:password
username:someusername
password:somepassword
Everything is ok, user is validated with a success, but the response that returns to my MVC is:
StatusCode:BadRequest
Content:invalid_grant
CORS is allowed:
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
No idea what's wrong. It was working quite good before...
No idea what's wrong. It was working quite good before...
Your request payload is wrong. You indicated application/application/x-www-form-urlencoded as Content-Type which is invalid and unsupported by Web API. The reason you are getting invalid_grant error is because the Web API didn't understand this request and couldn't even read the grant_type parameter from it.
So you could fix your request:
Content-Type: application/x-www-form-urlencoded
Accept: application/json
grant_type=password&username=someusername&password=somepassword
Here we use a standard and correct Content-Type of application/x-www-form-urlencoded and also the request body respects the content type that we indicated.
Alternatively you could have used JSON:
Content-Type: application/json
Accept: application/json
{
"grant_type": "password",
"username": "someusername",
"password": "somepassword"
}
You need to check that you have the "users" in "AspnetUsers" table.
In my case the problem was in the connection string. I have given a wrong db name and it was returning error 400 "invalid_grant". Fixed Db name and now it is working like before.
Got the same issue today.
Local: works fine
Test: works fine
Prod: "invalid_grant"
2 hours of research - nothing
Removed some special chars from password and this start work fine :)

IBM Watson - Conversation API integration returns Resource Not Found error (404)

I am trying to integrate watson from salesforce (Http Callout) and received 404 error. Then I tried the sameusing Postman tool but getting the same result
Added conversation credentials in request header
Request Endpoint
https://gateway.watsonplatform.net/conversation/api/v1/workspaces/883c7704-02c4-41fc-b8a0-aea1d0325c5a/message?version=2016-09-20
Request Body
{
"application/json": {
"input": {
"text": "Hi"
},
"alternate_intents": true
}
}
Response Body
{
"error": "Resource not found"
}
Status
404 Not found
Please let me know what is the issue here. I am not sure whether the way I added version and workspace id in the endpoint went wrong
I had the same issue and I found that it's simply rate limiting that kicks in.
According to the docs here there is no limit for the endpoint, however that turns out to be untrue. If you send a few thousand messages in quick succession, you'll start getting 404 Not Found until the quota resets, which seems to take around 1 hour.
The request body doesn't seem right. It should be JSON with e.g. this structure (see api ref. page in watson conversation service doc.):
{
"input": {
"text": "Hi"
}
}
application/json should be the content type. Sample request with curl:
curl -X POST -u "{username}":"{password}" -H "Content-Type:application/json" --data "{\"input\": {\"text\": \"Hi\"}}" "https://gateway.watsonplatform.net/conversation/api/v1/workspaces/<workspace_id>/message?version=2017-02-10"
See the API Reference for more details: https://www.ibm.com/watson/developercloud/conversation/api/v1/

unable to receive push notification for Google calender

I am trying to watch events resource based on given example using API explorer and Chrome Advanced Rest Client.
https://developers.google.com/google-apps/calendar/v3/push#watch_request_examples
Requst
POST https://www.googleapis.com/calendar/v3/calendars/XXX%40gmail.com/events/watch?key={YOUR_API_KEY}
Content-Type: application/json
Authorization: Bearer ya29.AHES6ZSNBYiHYPu6Y1_5P08hdb-EX5pdF4Ygj5ou_RKp_jOCS5beiDDH
X-JavaScript-User-Agent: Google APIs Explorer
{
"id": "01234567-89ab-cdef-0123456789ab",
"type": "web_hook",
"address": "https://www.example.com/WebHook/Index",
"token": "token=123546"
}
Response
401 Unauthorized
cache-control: private, max-age=0
content-encoding: gzip
content-length: 188
content-type: application/json; charset=UTF-8
date: Thu, 17 Oct 2013 12:49:00 GMT
expires: Thu, 17 Oct 2013 12:49:00 GMT
server: GSE
www-authenticate: Bearer realm="https://www.google.com/accounts/AuthSubRequest", error=invalid_token
{
"error": {
"errors": [
{
"domain": "global",
"reason": "push.webhookUrlUnauthorized",
"message": "Unauthorized WebHook callback channel: https://www.example.com/WebHook/Index"
}
],
"code": 401,
"message": "Unauthorized WebHook callback channel: https://www.example.com/WebHook/Index"
}
}
I have already whitelisted my domain www.example.com
I have already got ssl certificate which is mandatory to receive push
notifications
I googled about this issue , but could not find much help.
Posted same question on google group of calender api, but no response yet. https://groups.google.com/forum/#!topic/google-calendar-api/ZHKwm2xWuNE
can anybody guide, whats wrong with request ?
when you try with API Explorer,it will not use your OAuth2.0 project keys where you have registerd whitelisted domains, maybe it would use another keys
try to use client/lib
Your auth token may be incorrect. Please make sure you are using correct auth token for the calendar you are trying to set watch for
The one step I was missing to get this working was to actually enable the Calendar API in the console. The 401 push.webhookUrlUnauthorized error is really not helpful here.
Finally It worked for me , cause of error "Unauthorized WebHook callback channel" was in Configuration of Project in
Go to Google Developers Console.
Click your project name
Click "API & Auth" Menu on left
then click on sub menu "Push"
Click on Add Domains button which Allows webhook notifications to be
sent to the entered domains
Happy coding :)

Resources