Trying to fetch Read food items eaten data from google fit but returning 403 in reponse - google-fit

This is the request below: For scope : https://www.googleapis.com/auth/fitness.nutrition.read
Also do let me know how to pass multiple scope inorder to fetch auth code via api
POST /fitness/v1/users/me/dataSources?dataTypeName=com.google.nutrition&fields=dataSource(dataStreamId) HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Content-type: application/json
Authorization: Bearer Auth_code
Accept: application/json

If you are trying to list nutrition data sources, send a GET request instead of a POST.

Related

Content-type application/json causes 415 Unsupported Media Type

I am testing Forge API, and I have been able to complete requests smoothly for most endpoints, except the GET Hubs - I kept getting a 415 Unsupported Media Type.
Strangely enough, after I remove the Content-Type header - which was the same header used for all the other end-points of Content-Type:application/json -
the request worked and returns a 200 with the correct data.
Is there something about content-type I am not familiar with?
Shouldn't the first request work?
Request 1 - Returns 415 for hubs endpoint: no data
GET https://developer.api.autodesk.com/project/v1/hubs HTTP/1.1
Host: developer.api.autodesk.com
Authorization: Bearer {{ACCESS_TOKEN}}
Content-Type: application/json
Cache-Control: no-cache
Request 2 - Returns 200: data ok
GET https://developer.api.autodesk.com/project/v1/hubs HTTP/1.1
Host: developer.api.autodesk.com
Authorization: Bearer {{ACCESS_TOKEN}}
Cache-Control: no-cache
The JSON API defines that the client MUST send Content-Type: application/vnd.api+json
Answering my own question based on the comments (thanks #chetan-ranpariya)
You don't need to pass a Content-type on GET requests
the API should ignore the header; issue has been reported to API team

HTTP Request headers and caching

How should an HTTP Agent make decisions about using cached response when a request has the same path but different headers?
Take for example this HTTP request/response:
GET /resource HTTP/1.1
Host: example.org
X-Filter: foo=bar
HTTP/1.1 200 OK
Cache-Control: max-age=3600
Content-Type: application/json
Content-Length: 13
{"foo":"bar"}
Should the agent consider the response valid for a second request with a different X-Filter header? For example:
GET /resource HTTP/1.1
Host: example.org
X-Filter: foo=baz
then within an hour from the first request, should the agent request a fresh response since the request header differs, or should use the cached response from the first request, ignoring the header?
I'm asking this because I noticed that Google Chrome makes a new request, Microsoft Edge instead use the cached response.
You should use the cached version unless changed header appears in the list provided by the (optional) Vary response header.
For example, a response that contains
Vary: accept-encoding, accept-language
indicates that the origin server might have used the request's
Accept-Encoding and Accept-Language fields (or lack thereof) as
determining factors while choosing the content for this response.

YouTrack API Form Data Description

I am trying to send the description in form data to create an issue but it seems it is only possible through parameters with a length restriction. Does anybody know a way around this or am I doing something wrong?
PUT /rest/issue?project=LSDebug&summary=Debug%2520Log HTTP/1.1
Connection: keep-alive
Content-Length: 266
Accept: application/json, text/plain, */*
Origin: http://localhost:8080
Content-Type: application/x-www-form-urlencoded
Referer: http://localhost:8080/index.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Query String Parameters
project:LSDebug
summary:Debug%20Log
Form Data
description=Submitted%20Form%20name%3A%20null%2C%20Id%3Anull%0D%0AInput%20name%3A%20null%2C%20Id%3Anull%2C%20NgModel%3Aresult.homeTeamScore.score%2C%20Value%3A%201%0D%0AInput%20name%3A%20null%2C%20Id%3Anull%2C%20NgModel%3Aresult.awayTeamScore.score%2C%20Value%3A%202
I think you need to embed the data in XML within the body of your PUT request as documented in the Import REST API docs.
Html forms only support GET or POST. So i would suggest you to post the form data using POST method instead of PUT. So that the form content will go into the body of the message and you will able to evade the URL restriction

How can I put Google Drive API files.list requests for different users in the same batch request?

Normally, one would use BatchHttpRequest to aggregate several requests, but what if I want to list files for two different users?
Nominally that requires an oauth2 token per-user. BatchHttpRequest either takes one http object (which handles the credentials) for the batch, or pulls it out of the first batched request encountered when .execute() is called.
Using oauth1 to sign each batched requests results in proper results (different feeds for each user). However, using oauth2 and manually constructing the payload results in identical feeds (matching the user in the first batched request):
POST /batch HTTP/1.1
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=blah
Content-Length: 572
accept-encoding: gzip, deflate
Cache-Control: no-cache
--blah
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: <b29c5de2-0db4-490b-b421-6a51b598bd22+1>
GET /drive/v2/changes HTTP/1.1
Authorization: Bearer ya29.UQAabvlG2hnRPyEAAADUm7vkDe_qg7L49R655IyxvgBnkN7_PEgE3IG7UnZ_ZEmJwUK_6fSV4kTHjNQIjTk
accept: application/json
--blah
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: <b29c5de2-0db4-490b-b421-6a51b598bd22+2>
GET /drive/v2/changes HTTP/1.1
Authorization: Bearer ya29.UQBu8f9W8S5E6RwAAAAPqCOiqoFW3QEFYkBvQGx36UVKNHeEhdZT8GPN-P74ng
accept: application/json
--blah
Since oauth1 works, it seems that this is at least theoretically possible, although I may be blocked by a google bug where the oauth2 token for the first request in the batch overrides any other authorizations included.
The google-provided client does not support this, but providing an Authorization header for each request will work. The example given should work assuming all of the authorization header values are correct.

multipart/mixed HTTP request in actionscript

Is there an easy way to make an multipart/mixed HTTP request in as3?
I'm trying to reach LightSwitch server using OData protocol from flash. To send multiple commands at once you can combine them in one batch using HTTP request with "multipart/mixed" content type.
Here an example of HTTP requests with two commands:
Content-Type:multipart/mixed; boundary=batch
--batch
Content-Type: multipart/mixed; boundary=changeset
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT http://localhost:18065/ApplicationData.svc/Orders(3)/$links/User HTTP/1.1
Content-Type: application/json;odata=verbose
{"uri": "http://localhost:18065/ApplicationData.svc/Users(4)"}
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
MERGE http://localhost:18065/ApplicationData.svc/Users(3) HTTP/1.1
Content-Type: application/json;odata=verbose
If-Match: W/"X'0000000000002715'"
{"Name": "User 3_"}
--changeset--
--batch--
Every part contains own HTTP headers and body. Response formatted the same way, with own http response code.
How to work with multiple HTTP requests in actionscript?