Search code examples
httpaxiosgoogle-fitgoogle-fit-api

Add to the body of the Axios POST


I am wondering how I can add this to the body of the Axios POST request.

  const res =  axios({
    method: 'post',
    url: 'https://fitness.googleapis.com/fitness/v1/users/me/dataset:aggregate',
    headers: {
      'Authorization': 'Bearer ACCESS_TOKEN'
    }
  });

I want to add this to the Body but I dont have a clue how to do it:

{
  "aggregateBy": [{
    "dataSourceId": "derived:com.google.calories.expended:com.google.android.gms:platform_calories_expended" 
  }],
  "bucketByTime": { "durationMillis":86400000 },
  "startTimeMillis" : 1617667200000,
  "endTimeMillis" : 1617703858000
}

Solution

  • Heres how I got it to work:

    const res = await axios({
        method: 'post',
        url: 'https://fitness.googleapis.com/fitness/v1/users/me/dataset:aggregate',
        headers: {
          'Authorization': 'Bearer ACCESS_TOKEN'
        },
        data: {
          aggregateBy : [{
            dataSourceId : "derived:com.google.calories.expended:com.google.android.gms:platform_calories_expended"
          }],
          bucketByTime : {durationMillis : 86400000},
          startTimeMillis : 1617667200000,
          endTimeMillis : 1617703858000
        }
      });