{"_id":"56c2bc2a46d27917009d0722","project":"56bc8e679afb8b0d00d62dcf","parentDoc":null,"user":"56b98db7bb36440d0001f492","githubsync":"","__v":4,"category":{"_id":"56bc8e689afb8b0d00d62dd3","__v":6,"pages":["56bc8e699afb8b0d00d62dd5","56c2aadf46d27917009d0719","56c2bc123e1b8d2300fe4ca0","56c2bc1dde695a19009a4aa7","56c2bc2a46d27917009d0722","56c2bc398073830d00e42e6f"],"project":"56bc8e679afb8b0d00d62dcf","version":"56bc8e689afb8b0d00d62dd2","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-11T13:36:40.802Z","from_sync":false,"order":0,"slug":"documentation","title":"Getting Started"},"version":{"_id":"56bc8e689afb8b0d00d62dd2","project":"56bc8e679afb8b0d00d62dcf","__v":18,"createdAt":"2016-02-11T13:36:40.146Z","releaseDate":"2016-02-11T13:36:40.146Z","categories":["56bc8e689afb8b0d00d62dd3","56c3c837bc41330d009f25ed","56c3c83e521f350d00d348eb","56c3c8452d97560d00e23cd8","56c3c85234df460d00c2beb8","56c4180d70187b17005f43b4","56c418162d97560d00e23cf6","56c4181cc4796b0d007ef039","56c4182370187b17005f43b5","56c418292e75e01700986052","56c4183328bd680d005e7ac6","56c4183bbb64720d00552b88","56c418414040602b0064cea0","56c4184754b6030d00ec29a1","56c4184c28bd680d005e7ac7","56c4185370187b17005f43b6","56c4185b6063071700500cfc","582a98b6f8c0a0190053d7a5"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-16T06:05:30.112Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":5,"body":"## Overview\n\nThe Buddy JavaScript SDK helps you get up and running in seconds. \n\nFor the most part, the Buddy JavaScript SDK takes care of all the housekeeping of making requests against the Buddy REST API:\n\n* Building and formatting requests\n* Managing authentication\n* Parsing responses\n* Loading and saving credentials\n\nWith that handled, all you have to do is initialize the SDK and start making some calls!\n\n## Getting Started\n\nTo get started with the Buddy Platform SDK, please reference the _Getting Started_ series of documents at [docs.buddy.com](https://docs.buddy.com). You will need an application ID and key before you can use the SDK. The _Getting Started_ documents will walk you through obtaining everything you need and show you where to find the SDK for your platform.\n\nApplication IDs and keys are obtained at the Buddy Developer Dashboard at [buddyplatform.com](https://buddyplatform.com/login).\n\nFull documentation for Buddy's services are available at [docs.buddy.com](https://docs.buddy.com).\n\n### Installing the SDK\n\n1) Clone the repo to your desktop\n\n git clone git clone https://github.com/BuddyPlatform/Buddy-JS-SDK.git\n\n2) Move the *buddy.js* file to a convenient location within your project\n\n3) Create or open your HTML project\n\n4) Add the following lines to your `<HEAD>...</HEAD>` tags or at the end of `<BODY>` before any other JavaScript\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<script src=\\\"http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js\\\"></script>\\n<script src=\\\"buddy.js\\\"></script>\",\n \"language\": \"html\"\n }\n ]\n}\n[/block]\n## Using the JavaScript SDK\n\nVisit the [Buddy Dashboard](https://buddyplatform.com) to obtain your application ID and key.\n\n### Initialize the SDK\n\n`Buddy.init('[your app id]', '[your app key]');`\n\n*You may see the word \"Undefined\" appear in your console here. This is not an error, it is simply JavaScript's way of notifying you that the Buddy.init call does not return a value.*\n\n### User Flow\n\nThe Buddy JavaScript SDK handles user creation and login.\n\n#### Create A User\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"// Only username and password are required\\nBuddy.createUser({\\n username: 'test',\\n password: 'password',\\n firstName: 'Test',\\n lastName: 'User'\\n email: 'test:::at:::test.com',\\n dob: '4/23/1980'\\n}, [callback]);\",\n \"language\": \"javascript\"\n }\n ]\n}\n[/block]\n#### User Login\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"// All functions from here on out accept callbacks\\n// Callbacks are optional in the JavaScript SDK as indicated by the [ ]\\nBuddy.loginUser('test', 'password', [callback]);\",\n \"language\": \"javascript\"\n }\n ]\n}\n[/block]\n#### User Logout\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"Buddy.logoutUser();\",\n \"language\": \"javascript\"\n }\n ]\n}\n[/block]\n### REST Interface\n\nEach SDK provides wrappers that make REST calls to Buddy.\n\n#### POST\n\nIn this example we'll create a checkin. Take a look at [Create Checkin](doc:create-checkin) then:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"// POST to Checkins\\n// Location is required\\nBuddy.post('/checkins', {location: '34.052, -118.243', description: 'Somewhere in LA'}, [callback]);\",\n \"language\": \"javascript\"\n }\n ]\n}\n[/block]\n#### GET\n\nWe now can call GET to [Search Checkins](doc:search-checkins) we just created!\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"// GET a checkin by ID\\nvar checkinId;\\nBuddy.get('/checkins/' + checkinId, [callback]);\",\n \"language\": \"javascript\"\n }\n ]\n}\n[/block]\n#### PUT/PATCH/DELETE\n\nEach remaining REST verb is available through the Buddy SDK using the same pattern as the POST and GET examples.\n\n### Working With Files\n\nBuddy offers support for binary files. The JavaScript SDK works with files through our REST interface similarly to other API calls.\n\n**Note:** Responses for files deviate from the standard Buddy response templates. See [docs.buddy.com](https://docs.buddy.com) for more information.\n\n#### Upload A File\n\nHere we demonstrate uploading a picture. For all binary files (e.g. blobs and videos), the pattern is the same, but with a different path and different parameters. For full documentation see our [Media and Files](https://docs.buddy.com/docs/create-picture) documentation page.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"// This example assumes both of the following HTML elements exist:\\n// <input type=\\\"file\\\" id=\\\"file\\\" name=\\\"file\\\" />\\n// <input id=\\\"uploadButton\\\" type=\\\"button\\\" value=\\\"Upload\\\" />\\n\\n$('#uploadButton').click(function() {\\n\\n var inputFile = $('#file')[0];\\n\\n var myImage = inputFile.files[0];\\n\\n Buddy.post('/pictures', {data: myImage}); \\n\\n});\",\n \"language\": \"javascript\"\n }\n ]\n}\n[/block]\n#### Download A File\n\nDue to browser limitations the JavaScript SDK does not support direct file downloads.\n\n## Contributing Back: Pull Requests\n\nWe'd love to have your help making the Buddy SDK as good as it can be!\n\nTo submit a change to the Buddy SDK please do the following:\n\n1) Create your own fork of the Buddy SDK\n\n2) Make the change to your fork\n\n3) Before creating your pull request, please sync your repository to the current state of the parent repository: `git pull origin master`\n\n4) Commit your changes, then [submit a pull request](https://help.github.com/articles/using-pull-requests) for just that commit\n\n## Questions or need help?\n\nThis should have given you the basics of how to work with the Buddy JavaScript SDK. If you have further questions or are stuck, send an email to [email protected]","excerpt":"","slug":"javascript-sdk","type":"basic","title":"JavaScript SDK"}

Checkins

Batching

JavaScript SDK

## Overview
The Buddy JavaScript SDK helps you get up and running in seconds.
For the most part, the Buddy JavaScript SDK takes care of all the housekeeping of making requests against the Buddy REST API:
* Building and formatting requests
* Managing authentication
* Parsing responses
* Loading and saving credentials
With that handled, all you have to do is initialize the SDK and start making some calls!
## Getting Started
To get started with the Buddy Platform SDK, please reference the _Getting Started_ series of documents at [docs.buddy.com](https://docs.buddy.com). You will need an application ID and key before you can use the SDK. The _Getting Started_ documents will walk you through obtaining everything you need and show you where to find the SDK for your platform.
Application IDs and keys are obtained at the Buddy Developer Dashboard at [buddyplatform.com](https://buddyplatform.com/login).
Full documentation for Buddy's services are available at [docs.buddy.com](https://docs.buddy.com).
### Installing the SDK
1) Clone the repo to your desktop
git clone git clone https://github.com/BuddyPlatform/Buddy-JS-SDK.git
2) Move the *buddy.js* file to a convenient location within your project
3) Create or open your HTML project
4) Add the following lines to your `<HEAD>...</HEAD>` tags or at the end of `<BODY>` before any other JavaScript
[block:code]
{
"codes": [
{
"code": "<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js\"></script>\n<script src=\"buddy.js\"></script>",
"language": "html"
}
]
}
[/block]
## Using the JavaScript SDK
Visit the [Buddy Dashboard](https://buddyplatform.com) to obtain your application ID and key.
### Initialize the SDK
`Buddy.init('[your app id]', '[your app key]');`
*You may see the word "Undefined" appear in your console here. This is not an error, it is simply JavaScript's way of notifying you that the Buddy.init call does not return a value.*
### User Flow
The Buddy JavaScript SDK handles user creation and login.
#### Create A User
[block:code]
{
"codes": [
{
"code": "// Only username and password are required\nBuddy.createUser({\n username: 'test',\n password: 'password',\n firstName: 'Test',\n lastName: 'User'\n email: '[email protected]',\n dob: '4/23/1980'\n}, [callback]);",
"language": "javascript"
}
]
}
[/block]
#### User Login
[block:code]
{
"codes": [
{
"code": "// All functions from here on out accept callbacks\n// Callbacks are optional in the JavaScript SDK as indicated by the [ ]\nBuddy.loginUser('test', 'password', [callback]);",
"language": "javascript"
}
]
}
[/block]
#### User Logout
[block:code]
{
"codes": [
{
"code": "Buddy.logoutUser();",
"language": "javascript"
}
]
}
[/block]
### REST Interface
Each SDK provides wrappers that make REST calls to Buddy.
#### POST
In this example we'll create a checkin. Take a look at [Create Checkin](doc:create-checkin) then:
[block:code]
{
"codes": [
{
"code": "// POST to Checkins\n// Location is required\nBuddy.post('/checkins', {location: '34.052, -118.243', description: 'Somewhere in LA'}, [callback]);",
"language": "javascript"
}
]
}
[/block]
#### GET
We now can call GET to [Search Checkins](doc:search-checkins) we just created!
[block:code]
{
"codes": [
{
"code": "// GET a checkin by ID\nvar checkinId;\nBuddy.get('/checkins/' + checkinId, [callback]);",
"language": "javascript"
}
]
}
[/block]
#### PUT/PATCH/DELETE
Each remaining REST verb is available through the Buddy SDK using the same pattern as the POST and GET examples.
### Working With Files
Buddy offers support for binary files. The JavaScript SDK works with files through our REST interface similarly to other API calls.
**Note:** Responses for files deviate from the standard Buddy response templates. See [docs.buddy.com](https://docs.buddy.com) for more information.
#### Upload A File
Here we demonstrate uploading a picture. For all binary files (e.g. blobs and videos), the pattern is the same, but with a different path and different parameters. For full documentation see our [Media and Files](https://docs.buddy.com/docs/create-picture) documentation page.
[block:code]
{
"codes": [
{
"code": "// This example assumes both of the following HTML elements exist:\n// <input type=\"file\" id=\"file\" name=\"file\" />\n// <input id=\"uploadButton\" type=\"button\" value=\"Upload\" />\n\n$('#uploadButton').click(function() {\n\n var inputFile = $('#file')[0];\n\n var myImage = inputFile.files[0];\n\n Buddy.post('/pictures', {data: myImage}); \n\n});",
"language": "javascript"
}
]
}
[/block]
#### Download A File
Due to browser limitations the JavaScript SDK does not support direct file downloads.
## Contributing Back: Pull Requests
We'd love to have your help making the Buddy SDK as good as it can be!
To submit a change to the Buddy SDK please do the following:
1) Create your own fork of the Buddy SDK
2) Make the change to your fork
3) Before creating your pull request, please sync your repository to the current state of the parent repository: `git pull origin master`
4) Commit your changes, then [submit a pull request](https://help.github.com/articles/using-pull-requests) for just that commit
## Questions or need help?
This should have given you the basics of how to work with the Buddy JavaScript SDK. If you have further questions or are stuck, send an email to [email protected]