09-01-2015 09:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-01-2015 09:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I am writing code to retrieve users fitbit data into my application. Is there any way for my users to make entries into my application and for my application to send it to fitbit?

09-01-2015 11:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-01-2015 11:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
What type of entries?
You can log activity: https://dev.fitbit.com/docs/activity/#log-activity
You can log weight: https://dev.fitbit.com/docs/body/#log-weight
You can log food: https://dev.fitbit.com/docs/food-logging/#logging-and-deleting-collection-data
You can log sleep: https://dev.fitbit.com/docs/sleep/#log-sleep

09-01-2015 14:33
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-01-2015 14:33
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-01-2015 14:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-01-2015 14:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
How do you get the user id to put in the POST https://api.fitbit.com/1/user/[user-id]/body/log/weight.json ?

09-01-2015 15:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-01-2015 15:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@jschrimshire wrote:
Where do you get the user id to put in the url? The documentation says use the "-" for the current logged in user. I tried that and that does not work.
It's not the logged in user, but rather the OAuth access token for the user that you're sending in the Authorization header. You can check what user a token belongs to by requesting the profile.

09-01-2015 15:40
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-01-2015 15:40
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@jschrimshire wrote:
How do you get the user id to put in the POST https://api.fitbit.com/1/user/[user-id]/body/log/weight.json ?
The user id is returned with the access token at the end of the OAuth process.

09-02-2015 11:41
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-02-2015 11:41
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
If you can just give me a code snippet of say posting a users weight, I can do the rest. I have got it pulling in the users data for a given date. Do I set up the same kind of httpwebrequest and header as I did to retrieve the information? I have been working on this for 2 weeks now and feel like I am close.

09-02-2015 13:51
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-02-2015 13:51
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Does anyone have a code snippet that shows how to post user data such as weight to the fitbit api? The documentation gives very little details as to how to do this. If there was just a simple example of posting one item, then I could figure out the rest. This is so frustrating. Thanks in advance.

09-02-2015 15:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-02-2015 15:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@jschrimshire wrote:
Is there any example as to how you actually do a post? Please don't point me to the documentation. That is written from a 30,000 ft view.
POST is one of the HTTP methods, sometimes called HTTP's verbs. Most HTTP libraries allow you to specify the HTTP method easily. I'd point you to documentation, but...*
If you were using cURL, the request might look like:
curl \ -X POST \ -H "Authorization: Bearer reallylongoauth.token.here" \ --data "weight=65.7&date=2015-09-02&time=15:23:00" \ https://api.fitbit.com/1/user/-/body/log/weight.json
* If you do want to learn about HTTP methods, MDN has a good introduction.

09-03-2015 07:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-03-2015 07:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-03-2015 13:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-03-2015 13:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Did you try the example with cURL? If so, what was the server's response?

09-03-2015 14:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-03-2015 14:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Can you please look at this code? I just can't figure out how to populate the data2 variable. I have tried every variation google has to offer. It would just be so nice if someone could post a code snippet similar to this that works.
This has been the most frustrating thing I have ever tried to do in my 20 years in IT.
string data2 = "weight=65.7&date=2015-08-13";
urlworkout = "https://api.fitbit.com/1/user/3MQRBF/body/log/weight/65.7/date/2015-08-13.json";
HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(urlworkout);
request2.Method = WebRequestMethods.Http.Post;
request2.ContentLength = data2.Length;
request2.ContentType = "application/x-www-form-urlencoded";
StreamWriter writer = new StreamWriter(request2.GetRequestStream());
writer.Write(data2);
writer.Close();

09-03-2015 17:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-03-2015 17:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@jschrimshire wrote:
urlworkout = "https://api.fitbit.com/1/user/3MQRBF/body/log/weight/65.7/date/2015-08-13.json";
To create a weight log entry, the URL to POST to is https://api.fitbit.com/1/user/-/body/log/weight.json
Did you look at the server's response when you tried to use the URL in your example? It should have returned a HTTP 404 Not Found error, which lets you know when you're not using the correct URL.

09-04-2015 07:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-04-2015 07:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I changed my url to the one in your answer and it still did not work.
If you do not place the actual weight into the url, then where do you put it?
I know that to log a weight, more is required than just having the correct url.
As I asked for in my last email, it would be so helpful if you or someone could just provide an example code snippet that would make this work.
All the documentation provides is post parameters and the url. This is not very helpful. I just need an example of the additional code required to make this work.
I have researched the httpwebrequest and have tried every code variation google provides but it still does not work. Please help.

09-04-2015 11:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-04-2015 11:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@jschrimshire wrote:
As I asked for in my last email, it would be so helpful if you or someone could just provide an example code snippet that would make this work.
I provided a working cURL example earlier. I don't have a code example for the HTTP library that you're using.
@jschrimshire wrote:
No I do not get a 404 error or any error for that matter. It just does not log a weight.
The server returns some response. What is the response? Specifically, what is the HTTP status code and what is the body of the response say?
@jschrimshire wrote:
If you do not place the actual weight into the url, then where do you put it?
You put the information in the HTTP body as a form encoded values.

09-04-2015 12:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-04-2015 12:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
string data2 = "weight=65.7&date=2015-08-13";
urlworkout = "https://api.fitbit.com/1/user/3MQRBF/body/log/weight.json";
HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(urlworkout);
request2.Method = WebRequestMethods.Http.Post;
request2.ContentLength = data2.Length;
request2.ContentType = "application/x-www-form-urlencoded";
StreamWriter writer = new StreamWriter(request2.GetRequestStream());
writer.Write(data2);
writer.Close();

