Introduction
Welcome to the Snackify API! You can use this API to access Snackify API endpoints, which can get information on snacks, companies, users, and snacks selections.
This is subject to change without notice (but I'll do my best), so just be wary of that. If you've got a problem, you can take it up with my complaint department.
The base URL is:
https://afternoon-tor-81402.herokuapp.com
Authentication
To authorize, it is recommended to create an axios handler in a separete folder with the following:
const axios = require('axios');
axios.defaults.withCredentials = true;
axios.defaults.baseURL = 'https://afternoon-tor-81402.herokuapp.com';
export const axiosInstance = axios;
Snackify utilizes express-sessions to maintain session information. In order to access any of the endpoints, you will need to login at Snackify Register. <- will need to be replaced.
No need to save a token or anything client side. That's for node noobs. The server will send you a cookie that will be handled by your browser and returned by axios if setup as recommended.
POST Register
Example POST NON Admin request
{
"name": "Judge Judy",
"email": "judy@lambdaschool.com",
"password": "password",
"company_id": "lambda-school-snackify-123"
}
Example NON Admin Response
{
"user_ID": 15,
"name": "Judge Judy",
"email": "judy@lambdaschool.com",
"img_url": "https://www.riteaid.com/shop/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/0/4/041570030837.jpg",
"company_ID": 4,
"admin": false
}
Example POST New Admin request
{
"name": "Dr. Frankenstein",
"email": "frakenstein@lambdaschool.com",
"password": "password"
}
Example New Admin Response
{
"user_ID": 15,
"name": "Dr. Frankenstein",
"email": "frankenstein@lambdaschool.com",
"company_ID": 4,
"admin": true
}
This enpoint allows the user to register.
If the user does not have a company code, this will create a user account and an empty company account. The company ID is created if no company code matches an existing company;
If the company code doesn't exist, everything explodes. JK. But please don't let everything explode.
Endpoint
POST /auth/register
POST Register Body Parameters
Parameter | Required | Description |
---|---|---|
name | String: true | Must be at least 1 character long... |
String: true | Must be a valid email address. Throw away emails will get rejected. | |
password | String: true | Must be at least 8 characters long. |
company_code | String: false | This is the server-side generated company code that is given to invited users. NOT users signing up for the first time |
PUT Register Company
Example PUT Request
{
"name": "Lambda School",
"phone": "(123) 456-7890",
"city": "Palo Alto",
"state": "CA",
"package_ID": 4
}
Example Response
{
"name": "Lambda School",
"phone": "(123) 456-7890",
"city": "Palo Alto",
"state": "CA",
"package_ID": 4,
"company_ID": 32
}
Endpoint
PUT /auth/register/company/{company_id}
PUT Register Company Body Parameters
Parameter | Required | Description |
---|---|---|
name | String: true | Company Name. |
phone | String: true | Must be at least a 10 character string. |
city | String: true | City the company is located at |
state | String: true | State the company located at |
package_ID | Int: false | Package ID which will only be 1, 2, 3, or 4, will default to 1. You can put this value later. |
POST Login
Example Post Request
{
"email": "amanda@lambadschool.com",
"password: "********"
}
Example Response
{
"user_ID": 1,
"company_ID": 2,
"company_name": "Lambda School",
"name": "Amanda Lane",
"email": "amanda@lambdaschool.com",
"img_url": "https://www.riteaid.com/shop/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/0/4/041570030837.jpg",
"admin": true,
"snacks": [
{
"name": "Smokehouse Almonds",
"brand": "Blue Diamond",
"uom": "16 oz bag",
"img_url": "https://www.riteaid.com/shop/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/0/4/041570030837.jpg"
},
{
"name": "Original Skittles",
"brand": "Wrigley",
"uom": "54 oz bag",
"img_url": "https://images-na.ssl-images-amazon.com/images/I/71dHUI2QzEL._SX425_.jpg"
}
]
}
Endpoint
POST /auth/login
POST Login Body Parameters
Parameter | Required | Description |
---|---|---|
String: true | Must be a valid email address. | |
password | String: true | Must be at least 8 characters long. |
GET Logout
If you can't figure this one out, I can't help you.
Response
{
"message": "You're leaving? Already? But we were just getting to know each other."
}
Endpoint
GET /auth/logout
Company
The company endpoints will be used for most operations when the User that is logged in is the admin on the account.
GET Company Info
Example Response
{
"name": "Lambda School",
"company-code": "lambda-school-snackify-123",
"phone": "(123) 456-7890",
"city": "Palo Alto",
"state": "CA",
"package_ID": 4,
"price": 199,
"company_ID": 32
}
Endpoint
GET /company/{company_ID}
URL Parameters
Property | Required | Description |
---|---|---|
company_ID | Int: true | Integer value of the company's ID |
PUT Company Info
Updates the company's info, and is only allowed if the user is the admin, and associated with the same company. But I don't know what kind of voodoo magic the client or user may perform to screw that up.
NOTE: The package ID is required for this operation... which should really only happen if the user is updating the company's name or phone or something like that.
Example PUT Request
{
"name": "Gamma School",
"phone": "(890) 765-4321",
"city": "Salt Lake City",
"state": "UT",
"package_ID": 3
}
Example Response
{
"company_ID": 1,
"name": "Gamma School",
"company_code": "lambda-school-snackify-123",
"phone": "(890) 765-4321",
"city": "Salt Lake City",
"state": "UT",
"package_ID": 3
}
Endpoint
PUT /company/{company_ID}
Body Parameters
Parameter | Required | Description |
---|---|---|
name | String: false | Company Name. |
phone | String: False | Must be at least a 10 character string. |
city | String: false | City the company is located at |
state | String: false | State the company located at |
package_ID | Int: true | Package ID which will only be 1, 2, 3, or 4, will default to 1. |
URL Parameters
Property | Required | Description |
---|---|---|
company_ID | Int: true | Integer value of company's ID |
GET Company Snacks
These are the snacks the company has selected to be delivered.
Example Response
{
"name": "Lambda School",
"snacks": [
{
"name": "Original Skittles",
"brand": "Wrigley",
"uom": "54 oz bag",
"img_url": "https://images-na.ssl-images-amazon.com/images/I/71dHUI2QzEL._SX425_.jpg",
"quantity": 2
},
{
"name": "Original Doritos",
"brand": "Frito-Lay",
"uom": "16 x 9oz bags",
"img_url": "https://target.scene7.com/is/image/Target/GUEST_ac2b08b4-12e8-496c-ab09-dd530740da9c?wid=488&hei=488&fmt=pjpeg",
"quantity": 3
}
]
}
Endpoint
GET /company/{company_ID}/snacks
URL Parameters
Property | Required | Description |
---|---|---|
company_ID | Int: true | Integer value of company's ID |
POST Company Snacks
This will manifest the snack to the company's selected snacks.
It will automatically set the quantity to 1 for the snack.
Example Response
{
"company_ID": 1,
"snack_ID": 4,
"quantity": 1
}
Endpoint
POST /company/{company_ID}/snacks/{snack_ID}
URL Parameters
Property | Required | Description |
---|---|---|
company_ID | Int: true | Integer value of company's ID |
snack_ID | Int: true | Integer value of snack ID |
PUT Company Snacks
This will primarily update the quanitity requested on the users
Example PUT Request
{
"quantity": 3
}
Example Response
{
"company_id": 1,
"snack_id": 2,
"quantity": 3
}
Endpoint
PUT /company/{company_ID}/snacks/{snack_ID}
Body Parameters
Property | Required | Description |
---|---|---|
quantity | Int: true | Integer value of the quantity requested |
URL Parameters
Property | Required | Description |
---|---|---|
company_ID | Int: true | Integer value of company's ID |
snack_ID | Int: true | Integer value of snack ID |
DELETE Company Snack
This will remove the specific snack ID from the company ID. Don't worry, it's not gonna delete any snacks from the database.
Example Response
{
"snack": "Original Doritos",
"message": "Successfully destroyed snacks existance from company"
}
Endpoint
DELETE /company/{company_ID}/snacks/{snack_ID}
URL Parameters
Basically the exact same as the POST
Parameter | Required | Description |
---|---|---|
company_ID | Int: true | Company ID. |
snack_ID | Int: true | Snack ID. |
GET Company Suggested Snacks
Example Response
{
"name": "Lambda School",
"snacks": [
{
"name": "Smokehouse Almonds",
"brand": "Blue Diamond",
"uom": "16 oz bag",
"img_url": "https://www.riteaid.com/shop/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/0/4/041570030837.jpg",
"suggested_by": [
"Steve Ballmer",
"Brad Pitt",
"Benedict Cumberbatch"
]
},
{
"name": "Original Skittles",
"brand": "Wrigley",
"uom": "54 oz bag",
"img_url": "https://images-na.ssl-images-amazon.com/images/I/71dHUI2QzEL._SX425_.jpg",
"suggested_by": ["Tom Holland", "Jimmy Fallon"]
}
]
}
These are the gooey yum yum's those employees desperately crave.
These are the snacks suggested by the company's users.
Endpoint
GET /company/{company_ID}/suggestions
URL Parameters
Property | Required | Description |
---|---|---|
company_ID | Int: true | Integer value of company's ID |
POST Company User
Example POST request
{
"name": "Captain Kirk",
"email": "kirk@starfleet.com"
}
Example response
{
"message": "sent Captain Kirk your company_code"
}
This will be the "email" sent to the user in order for them to sign up with the company code.
Endpoint
POST /company/{company_id}/users
Body Parameters
Property | Required | Description |
---|---|---|
name | String: true | name of the person being added |
String: true | email to send the company code to |
GET Company Users
Example Response
{
"name": "Lambda School",
"users": [
{
"name": "Amanda Lane",
"email": "amanda@lambdaschool.com",
"admin": true,
"user_ID": 1,
"snacks": [
"Original Almonds",
"Flaming hot Cheetos",
"Olive Hummus"
]
},
{
"name": "Elon Musk",
"email": "elon@lambdaschool.com",
"admin": false,
"user_ID": 2,
"snacks": ["Mars Bars", "Milkyway Bars"]
},
{
"name": "George Washington",
"email": "george@lambdaschool.com",
"admin": false,
"user_ID": 3,
"snacks": ["Cherries"]
}
]
}
Retrieve all the users and their snacks from the mainframe that are assocaited with the company.
NOTE: The response on the right is subject to change... I may just return all the data to you if it's easier.
Endpoint
GET /company/{company_ID}/users
URL Parameters
Property | Required | Description |
---|---|---|
company_ID | Int: true | Integer value of company's ID |
DELETE Company User
Need to determine if I'm going to remove the user from teh database or just set a revoked flag onto the user.
If I set revoked, I'd have to unset flag to let them back in If I delete it, then they can just add back in, but then the user would have to create another acccount.
Endpoint
DELETE /company/{company_ID}/users/{user_ID}
URL Parameters
Property | Required | Description |
---|---|---|
company_ID | Int: true | Integer value of company's ID |
user_ID | Int: true | Integer value of user's ID |
Users
The users endpoints are for users of a company but NOT the admins.
GET User Info
Will only allow a user to request their own information. This is assuming that only admins will need to access all of the users and that can be done at GET /company/{company_ID}/users
Example Response
{
"company_ID": 2,
"company_name": "Lambda School",
"name": "Amanda Lane",
"email": "amanda@lambdaschool.com",
"admin": true,
"snacks": [
{
"name": "Smokehouse Almonds",
"brand": "Blue Diamond",
"uom": "16 oz bag",
"img_url": "https://www.riteaid.com/shop/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/0/4/041570030837.jpg"
},
{
"name": "Original Skittles",
"brand": "Wrigley",
"uom": "54 oz bag",
"img_url": "https://images-na.ssl-images-amazon.com/images/I/71dHUI2QzEL._SX425_.jpg"
}
]
}
Endpoint
GET /users/{user_ID}
URL Parameters
Property | Required | Description |
---|---|---|
user_ID | Int: true | Integer value of the users ID |
PUT User Info
Example PUT request
{
"name": "Jimbo Fisher",
"email": "jimbo@fisher.com",
"img_url": "jimbos-fat-face.myfancyurl.com"
}
Endpoint
PUT /users/{user_ID}
Body Parameters
Parameter | Required | Description |
---|---|---|
name | String: true | Must be at least 1 character long... |
String: true | Must be a valid email address. Throw away emails will get rejected. | |
img_url | String: false | Will be the url to their gravatar |
POST User Snacks
Example Request URL:
/users/2/snacks/5
Example Response
{
"user_ID": 2,
"snack_ID": 5
}
Endpoint
POST /users/{user_ID}/snacks/{snack_ID}
URL Parameters
Property | Required | Description |
---|---|---|
user_ID | Int: true | Integer value of the users ID |
snack_ID | Int: true | Integer value of the snacks ID |
DELETE User Snacks
Will remove the specific user's suggested snacks.
Example Response
{
"status": true,
"message": "Successfully destroyed suggested snack from user and user's suggested snacks"
}
Endpoint
DELETE /users/{user_ID}/snacks/{snack_ID}
URL Parameters
Property | Required | Description |
---|---|---|
user_ID | Int: true | Integer value of the users ID |
snack_ID | Int: true | Integer value of the snacks ID |
DELETE User
This is permenantly delete the user from the database and remove the association from the company
Endpoint
DELETE /users/{user_ID}
Packages
GET Packages
Response
[
{
"name": "small",
"description": "0 - 10 employees",
"price": 199.0,
"snacks": 10
},
{
"name": "medium",
"description": "11 - 50 employees",
"price": 399.0,
"snacks": 25
},
{
"name": "large",
"description": "51 - 100 employees",
"price": 599.0,
"snacks": 60
},
{
"name": "mega",
"description": ">100 employees",
"price": 1999.0,
"snacks": 100
}
]
Again, if you can't figure this one out... idk what to do.
Endpoint
GET /packages
Snacks
The snacks endpoint will return a paginated result of the snacks that are available
GET Snacks
Endpoint
GET /snacks
Example Request
/snacks?page=2&limit=15
Example Response
{
"previous": {
"page": 1,
"limit": 15
},
"next": {
"page": 3,
"limit": 15
},
"snacks": [
{
"name": "Smokehouse Almonds",
"brand": "Blue Diamond",
"uom": "16 oz bag",
"img_url": "https://www.riteaid.com/shop/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/0/4/041570030837.jpg"
},
{
"name": "Original Skittles",
"brand": "Wrigley",
"uom": "54 oz bag",
"img_url": "https://images-na.ssl-images-amazon.com/images/I/71dHUI2QzEL._SX425_.jpg"
},
{
"name": "Original Doritos",
"brand": "Frito-Lay",
"uom": "16 x 9oz bags",
"img_url": "https://target.scene7.com/is/image/Target/GUEST_ac2b08b4-12e8-496c-ab09-dd530740da9c?wid=488&hei=488&fmt=pjpeg"
}
]
}
Example Request
/snacks?search=original
{
"snacks": [
{
"name": "Original Skittles",
"brand": "Wrigley",
"uom": "54 oz bag",
"img_url": "https://images-na.ssl-images-amazon.com/images/I/71dHUI2QzEL._SX425_.jpg"
},
{
"name": "Original Doritos",
"brand": "Frito-Lay",
"uom": "16 x 9oz bags",
"img_url": "https://target.scene7.com/is/image/Target/GUEST_ac2b08b4-12e8-496c-ab09-dd530740da9c?wid=488&hei=488&fmt=pjpeg"
}
]
}
Query Parameters
Parameter | Default | Description |
---|---|---|
search | '' | The search query to search by name of snacks |
page | 1 | The start "page" to get snacks. Eg. Page = 2, Limit = 15: start at snack ID of 15 and go to Snack 30 |
limit | 20 | The number of snacks you want back |
Response Description
Property | Description |
---|---|
previous/page | The page number to get the previous limit number of snacks |
previous/limit | The same limit given or default of 20 |
next/page | The page number to get the next limit number of snacks |
next/limit | The same limit given or default of 20 |
snacks/name | Name of the snack. |
snacks/brand | Company brand of the snack. |
snacks/oum | Unit of Measure. If the user changes the quantity, this is how much it will increment or decrement by. |
snacks/img_url | A url for an unformatted picture of the snack. |
Billing
The snacks endpoint will return a paginated result of the snacks that are available
POST Stripe
Example Request
{
"price": 199.00,
"token": <token>
}
Example Success Response
{
"message": "Successfully charged the user"
}
Example Failue Response
{
"message": "Application shit the bed"
}
Endpoint
POST billing/stripe
Body Description
Property | Required | Description |
---|---|---|
price | Float: true | The price to charge the user |
token | String: true | The token returned by stripe to authorize the charge |
Errors
The Snackify API uses the following error codes:
Error Code | Meaning |
---|---|
400 | Bad Request -- Your request is invalid. |
401 | Unauthorized -- Your Session Token is not set or invalid. |
403 | Forbidden -- The info requested is hidden for administrators only. |
404 | Not Found -- The specified kitten could not be found. |
405 | Method Not Allowed -- You tried to access an endpoint with an invalid method (i.e. POST, GET, PUT, DELETE). |
406 | Not Acceptable -- You requested a format that isn't json. |
409 | Missing Info -- Your request is missing informaion. |
410 | Gone -- The info requested has been removed from our servers. |
418 | I'm a teapot. |
429 | Too Many Requests -- You're requesting too much data! Slow down! |
500 | Internal Server Error -- We had a problem with our server. Try again later. |
503 | Service Unavailable -- We're temporarily offline for maintenance. Please try again later. |