List of Advertisements - noemenend/Nodepop GitHub Wiki
List of Advertisements
We must bear in mind that for this it is necessary to pass a token data by query to confirm the authentication, otherwise the api will not give us access to anything.
Result: List of advertisements paginated that meet the filter criteria specificated in the request.
URL : /api/v1/advertisements?token=xxxxxxxxxx where xxxxxxx= token generated throught the authenticate method.
Method: GET
Parameters:
start: optional, 0 by default
limit: optional, null by default. If this parameter is not specificated in the request, the api will return 20
elements in each call.
sort: sort=precio, by example, return the ads list ordered by price.
venta: true/false, optional
precio: optional,
precio=10-50: Adverts which price is >= 10 y <= 50
precio=10-: Adverts which price is >= 10
precio=10: Adverts which price is = 10
precio=-50: Adverts which price is <= 50
nombre: filter by ads name , optional. The api will return all adverts from the collection which name starts by
the value of the parameter.
tag: optional, tag=mobile returns all adverts that contain this tag.
Example:
http://localhost:3000/api/v1/advertisements?precio=200-&start=2&sort=precio
{"success":true,
"number":2,
"result":[{"foto":"http://localhost:3000/images/anuncios/moto.jpeg",
"tags":["lifestyle","motor"],
"_id":"5b5abba89bad1d32c4125a61",
"nombre":"Motocicleta Scooter Roja",
"venta":true,
"precio":567.45,
"__v":0},
{"foto":"http://localhost:3000/images/anuncios/van.jpeg",
"tags":["lifestyle","motor"],
"_id":"5b5abba89bad1d32c4125a65",
"nombre":"Volkswagen van",
"venta":false,
"precio":4500,
"__v":0}]}
Validation errors
If one of these parameters specificated bellow, don't meet with the type of the value expected by the API, it will return an array of validation error messages in JSON format.
- venta: If the value is not a boolean (true/false), returns the following error message:venta is not a boolean value.
- start: If the value is not an integer, returns the following error message:start is not an int value
- limit: If the value is not an integer, returns the following error message:limit is not an int value
- tag: If the value does not belong to the following values ['lifestyle','motor','work','mobile], returns the following error message: The tag parameter must belongs to [mobile,motor,lifestyle,work]
Example:
http://localhost:3000/api/v1/advertisements?start=ccc&limit=ttt&venta=23
{"errors":[
{"location":"query",
"param":"venta",
"value":"23",
"msg":"venta is not a boolean value"},
{"location":"query",
"param":"start",
"value":"ccc",
"msg":"start is not an int value"},
{"location":"query",
"param":"limit",
"value":"ttt",
"msg":"limit is not an int value"}]}