├── _config.yml ├── examples ├── token_refresh.js ├── login.js └── get_user_info.js ├── LICENSE ├── README.md ├── .gitignore └── swagger.json /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /examples/token_refresh.js: -------------------------------------------------------------------------------- 1 | const fetch = require("node-fetch"); 2 | 3 | const body = `{ 4 | "client_id": "1_4hiybetvfksgw40o0sog4s884kwc840wwso8go4k8c04goo4c", 5 | "client_secret": "6rok2m65xuskgkgogw40wkkk8sw0osg84s8cggsc4woos4s8o", 6 | "grant_type": "refresh_token", 7 | "refresh_token": "_refresh_token_here_" 8 | }`; 9 | 10 | fetch('https://yzapi.yazio.com/v5/oauth/token', {method: 'post', body: body}) 11 | .then(response => { 12 | if (response.status === 200) { 13 | return response.json(); 14 | } else { 15 | throw new Error('Something went wrong on api server!'); 16 | } 17 | }) 18 | .then(response => { 19 | console.debug(response); 20 | }).catch(error => { 21 | console.error(error); 22 | }); 23 | 24 | /* 25 | Json response: 26 | { 27 | access_token: '_here_will_be_access_token_', 28 | expires_in: 172800, 29 | refresh_token: '_here_will_be_refresh_token_', 30 | token_type: 'bearer' 31 | } 32 | */ 33 | -------------------------------------------------------------------------------- /examples/login.js: -------------------------------------------------------------------------------- 1 | const fetch = require("node-fetch"); 2 | 3 | const body = `{ 4 | "client_id": "1_4hiybetvfksgw40o0sog4s884kwc840wwso8go4k8c04goo4c", 5 | "client_secret": "6rok2m65xuskgkgogw40wkkk8sw0osg84s8cggsc4woos4s8o", 6 | "username": "_LOGIN_EMAIL_", 7 | "password": "_PASSWORD_", 8 | "grant_type": "password" 9 | }`; 10 | 11 | fetch('https://yzapi.yazio.com/v5/oauth/token', {method: 'post', body: body}) 12 | .then(response => { 13 | if (response.status === 200) { 14 | return response.json(); 15 | } else { 16 | throw new Error('Something went wrong on api server!'); 17 | } 18 | }) 19 | .then(response => { 20 | console.debug(response); 21 | }).catch(error => { 22 | console.error(error); 23 | }); 24 | 25 | /* 26 | Json response: 27 | { 28 | access_token: '_here_will_be_access_token_', 29 | expires_in: 172800, 30 | refresh_token: '_here_will_be_refresh_token_', 31 | token_type: 'bearer' 32 | } 33 | */ 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 saganos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Yazio API description 2 | ============ 3 | 4 | What 5 | ------------ 6 | Public API description for Yazio application. 7 | 8 | Why? 9 | ------------ 10 | After waiting for more than one year for public API description I was tired. 11 | Some functions are still missing (i.e. Share saved meal with other people) - should be easier now to create it as a `plugin / extension / additional webapp` 12 | 13 | How to install 14 | ------------ 15 | ```bash 16 | npm i node-fetch --save 17 | ``` 18 | 19 | Documentation 20 | ------------ 21 | 22 | A `swagger.json` file was added. You can use the public [swagger editor](https://editor-next.swagger.io/) to paste/import it and play around. 23 | 24 | ℹ️ The OAuth part works. You can log in and retrieve a valid token. 25 | 26 | ⚠️ The other endpoints won't work in the swagger UI, as long as you are playing around using the public swagger editor. The reason is that yazio has CORS security rules enabled that can only be omitted using HTTP or localhost clients. [You can use the client credentials that are posted in this repository](https://github.com/saganos/yazio_public_api/blob/master/examples/login.js). 27 | 28 | Examples: 29 | ------------ 30 | 31 | ### Login ### 32 | ```bash 33 | node examples/login.js 34 | ``` 35 | 36 | [login.js](examples/login.js) - Login to Yazio App with login and password using OAUTH2 37 | 38 | ---- 39 | ### Token refresh ### 40 | ```bash 41 | node examples/token_refresh.js 42 | ``` 43 | 44 | [token_refresh.js](examples/token_refresh.js) - Refresh login token 45 | 46 | ### Get user info ### 47 | ```bash 48 | node examples/get_user_info.js 49 | ``` 50 | 51 | [get_user_info.js](examples/get_user_info.js) - Gets user info 52 | 53 | -------------------------------------------------------------------------------- /examples/get_user_info.js: -------------------------------------------------------------------------------- 1 | const fetch = require("node-fetch"); 2 | global.Headers = fetch.Headers; 3 | 4 | var myHeaders = new Headers(); 5 | myHeaders.append("Content-Type", "application/json"); 6 | myHeaders.append("Authorization", "Bearer __put_access_token_here__"); 7 | 8 | var requestOptions = { 9 | method: 'GET', 10 | headers: myHeaders, 11 | redirect: 'follow' 12 | }; 13 | 14 | fetch('https://yzapi.yazio.com/v5/user', requestOptions) 15 | .then(response => { 16 | if (response.status === 200) { 17 | return response.json(); 18 | } else { 19 | throw new Error('Something went wrong on api server!'); 20 | } 21 | }) 22 | .then(response => { 23 | console.debug(response); 24 | }).catch(error => { 25 | console.error(error); 26 | }); 27 | 28 | /* 29 | Json response: 30 | { 31 | diet: { 32 | carb_percentage: 30, 33 | fat_percentage: 30, 34 | protein_percentage: 30, 35 | name: 'default' 36 | }, 37 | is_premium: false, 38 | email: '__your_email__', 39 | pal: 0, 40 | sex: 'male', 41 | first_name: null, 42 | last_name: null, 43 | city: null, 44 | weight_change_per_week: 0, 45 | body_height: 110, 46 | goal: 'lose', 47 | date_of_birth: '1983-05-06', 48 | registration_date: '2020-01-17 21:23:04', 49 | locale: '_code_', 50 | timezone_offset: 0, 51 | last_active_date: '2020-01-02', 52 | unit_length: 'cm', 53 | unit_mass: 'kg', 54 | unit_glucose: 'mgdl', 55 | unit_serving: 'g', 56 | unit_energy: 'kcal', 57 | profile_image: null, 58 | user_token: '__your_user_token__', 59 | start_weight: 64, 60 | email_confirmation_status: 'confirmed', 61 | login_type: 'email_password', 62 | siwa_user_id: null 63 | } 64 | 65 | */ 66 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | -------------------------------------------------------------------------------- /swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server for Yazio API.", 5 | "version": "1.0.0", 6 | "title": "Yazio API", 7 | "termsOfService": "http://swagger.io/terms/", 8 | "contact": { 9 | "email": "apiteam@swagger.io" 10 | } 11 | }, 12 | "host": "api.yazio.com", 13 | "basePath": "/v1", 14 | "tags": [ 15 | { 16 | "name": "auth", 17 | "description": "Authentication related endpoints" 18 | }, 19 | { 20 | "name": "meals", 21 | "description": "Meal management endpoints" 22 | }, 23 | { 24 | "name": "nutrients", 25 | "description": "Nutrient information endpoints" 26 | } 27 | ], 28 | "schemes": [ 29 | "https" 30 | ], 31 | "paths": { 32 | "/login": { 33 | "post": { 34 | "tags": [ 35 | "auth" 36 | ], 37 | "summary": "User login", 38 | "description": "Login to Yazio App with username and password using OAuth2.", 39 | "parameters": [ 40 | { 41 | "name": "body", 42 | "in": "body", 43 | "required": true, 44 | "schema": { 45 | "$ref": "#/definitions/Login" 46 | } 47 | } 48 | ], 49 | "responses": { 50 | "200": { 51 | "description": "Successful login", 52 | "schema": { 53 | "$ref": "#/definitions/AuthResponse" 54 | } 55 | } 56 | } 57 | } 58 | }, 59 | "/token_refresh": { 60 | "post": { 61 | "tags": [ 62 | "auth" 63 | ], 64 | "summary": "Refresh token", 65 | "description": "Refreshes the authentication token.", 66 | "parameters": [ 67 | { 68 | "name": "body", 69 | "in": "body", 70 | "required": true, 71 | "schema": { 72 | "$ref": "#/definitions/TokenRefresh" 73 | } 74 | } 75 | ], 76 | "responses": { 77 | "200": { 78 | "description": "Token refreshed", 79 | "schema": { 80 | "$ref": "#/definitions/AuthResponse" 81 | } 82 | } 83 | } 84 | } 85 | }, 86 | "/user_info": { 87 | "get": { 88 | "tags": [ 89 | "auth" 90 | ], 91 | "summary": "Get user info", 92 | "description": "Retrieves user information.", 93 | "responses": { 94 | "200": { 95 | "description": "Successful retrieval", 96 | "schema": { 97 | "$ref": "#/definitions/UserInfo" 98 | } 99 | } 100 | } 101 | } 102 | }, 103 | "/share_meal": { 104 | "post": { 105 | "tags": [ 106 | "meals" 107 | ], 108 | "summary": "Share meal", 109 | "description": "Share saved meal with other users.", 110 | "parameters": [ 111 | { 112 | "name": "body", 113 | "in": "body", 114 | "required": true, 115 | "schema": { 116 | "$ref": "#/definitions/ShareMeal" 117 | } 118 | } 119 | ], 120 | "responses": { 121 | "200": { 122 | "description": "Meal shared", 123 | "schema": { 124 | "$ref": "#/definitions/ShareMealResponse" 125 | } 126 | } 127 | } 128 | } 129 | }, 130 | "/log_meal": { 131 | "post": { 132 | "tags": [ 133 | "meals" 134 | ], 135 | "summary": "Log a meal", 136 | "description": "Log a meal for the user.", 137 | "parameters": [ 138 | { 139 | "name": "body", 140 | "in": "body", 141 | "required": true, 142 | "schema": { 143 | "$ref": "#/definitions/LogMeal" 144 | } 145 | } 146 | ], 147 | "responses": { 148 | "200": { 149 | "description": "Meal logged", 150 | "schema": { 151 | "$ref": "#/definitions/LogMealResponse" 152 | } 153 | } 154 | } 155 | } 156 | }, 157 | "/get_meals": { 158 | "get": { 159 | "tags": [ 160 | "meals" 161 | ], 162 | "summary": "Get meals", 163 | "description": "Retrieve meals logged by the user.", 164 | "responses": { 165 | "200": { 166 | "description": "Successful retrieval", 167 | "schema": { 168 | "$ref": "#/definitions/Meals" 169 | } 170 | } 171 | } 172 | } 173 | }, 174 | "/nutrients_info": { 175 | "get": { 176 | "tags": [ 177 | "nutrients" 178 | ], 179 | "summary": "Get nutrient information", 180 | "description": "Get detailed nutrient information.", 181 | "responses": { 182 | "200": { 183 | "description": "Successful retrieval", 184 | "schema": { 185 | "$ref": "#/definitions/NutrientsInfo" 186 | } 187 | } 188 | } 189 | } 190 | } 191 | }, 192 | "definitions": { 193 | "Login": { 194 | "type": "object", 195 | "required": [ 196 | "username", 197 | "password" 198 | ], 199 | "properties": { 200 | "username": { 201 | "type": "string" 202 | }, 203 | "password": { 204 | "type": "string" 205 | } 206 | } 207 | }, 208 | "AuthResponse": { 209 | "type": "object", 210 | "properties": { 211 | "token": { 212 | "type": "string" 213 | } 214 | } 215 | }, 216 | "TokenRefresh": { 217 | "type": "object", 218 | "required": [ 219 | "token" 220 | ], 221 | "properties": { 222 | "token": { 223 | "type": "string" 224 | } 225 | } 226 | }, 227 | "UserInfo": { 228 | "type": "object", 229 | "properties": { 230 | "id": { 231 | "type": "string" 232 | }, 233 | "username": { 234 | "type": "string" 235 | }, 236 | "email": { 237 | "type": "string" 238 | } 239 | } 240 | }, 241 | "ShareMeal": { 242 | "type": "object", 243 | "required": [ 244 | "mealId", 245 | "recipientId" 246 | ], 247 | "properties": { 248 | "mealId": { 249 | "type": "string" 250 | }, 251 | "recipientId": { 252 | "type": "string" 253 | } 254 | } 255 | }, 256 | "ShareMealResponse": { 257 | "type": "object", 258 | "properties": { 259 | "status": { 260 | "type": "string" 261 | } 262 | } 263 | }, 264 | "LogMeal": { 265 | "type": "object", 266 | "required": [ 267 | "mealDetails" 268 | ], 269 | "properties": { 270 | "mealDetails": { 271 | "type": "string" 272 | } 273 | } 274 | }, 275 | "LogMealResponse": { 276 | "type": "object", 277 | "properties": { 278 | "status": { 279 | "type": "string" 280 | } 281 | } 282 | }, 283 | "Meals": { 284 | "type": "object", 285 | "properties": { 286 | "meals": { 287 | "type": "array", 288 | "items": { 289 | "$ref": "#/definitions/Meal" 290 | } 291 | } 292 | } 293 | }, 294 | "Meal": { 295 | "type": "object", 296 | "properties": { 297 | "id": { 298 | "type": "string" 299 | }, 300 | "details": { 301 | "type": "string" 302 | } 303 | } 304 | }, 305 | "NutrientsInfo": { 306 | "type": "object", 307 | "properties": { 308 | "nutrients": { 309 | "type": "array", 310 | "items": { 311 | "$ref": "#/definitions/Nutrient" 312 | } 313 | } 314 | } 315 | }, 316 | "Nutrient": { 317 | "type": "object", 318 | "properties": { 319 | "name": { 320 | "type": "string" 321 | }, 322 | "amount": { 323 | "type": "string" 324 | } 325 | } 326 | } 327 | }, 328 | "securityDefinitions": { 329 | "oauth2": { 330 | "type": "oauth2", 331 | "flow": "password", 332 | "tokenUrl": "https://yzapi.yazio.com/v12/oauth/token", 333 | "scopes": {} 334 | } 335 | }, 336 | "security": [ 337 | { 338 | "oauth2": [] 339 | } 340 | ] 341 | } --------------------------------------------------------------------------------