diff --git a/examples/get_token.py b/examples/get_token.py new file mode 100644 index 0000000..d183a06 --- /dev/null +++ b/examples/get_token.py @@ -0,0 +1,30 @@ +# You need use this example code in to the main folder +from __future__ import print_function +import time +import meli +from meli.rest import ApiException +from pprint import pprint +# Defining the host, defaults to https://api.mercadolibre.com +# See configuration.py for a list of all supported configuration parameters. +configuration = meli.Configuration( + host = "https://api.mercadolibre.com" +) + + +# Enter a context with an instance of the API client +with meli.ApiClient() as api_client: +# Create an instance of the API class + api_instance = meli.OAuth20Api(api_client) + grant_type = 'authorization_code' # or 'refresh_token' if you need get one new token + client_id = 'client_id_example' # Your client_id + client_secret = 'client_secret_example' # Your client_secret + redirect_uri = 'redirect_uri_example' # Your redirect_uri + code = 'code_example' # The parameter CODE, empty if your send a refresh_token + refresh_token = '' # Your refresh_token + +try: + # Request Access Token + api_response = api_instance.get_token(grant_type=grant_type, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri, code=code, refresh_token=refresh_token) + pprint(api_response) +except ApiException as e: + print("Exception when calling OAuth20Api->get_token: %s\n" % e) diff --git a/examples/rest_client_get.py b/examples/rest_client_get.py new file mode 100644 index 0000000..dcf55b9 --- /dev/null +++ b/examples/rest_client_get.py @@ -0,0 +1,26 @@ +# You need use this example code in to the main folder +from __future__ import print_function +import time +import meli +from meli.rest import ApiException +from pprint import pprint +# Defining the host is optional and defaults to https://api.mercadolibre.com +# See configuration.py for a list of all supported configuration parameters. +configuration = meli.Configuration( + host = "https://api.mercadolibre.com" +) + + +# Enter a context with an instance of the API client +with meli.ApiClient() as api_client: + # Create an instance of the API class + api_instance = meli.RestClientApi(api_client) + resource = 'sites/MLA/categories' # A resource example like items, search, category, etc. + access_token = 'access_token_example' # Your access token. + +try: + # Resource path GET + api_response = api_instance.resource_get(resource, access_token) + pprint(api_response) +except ApiException as e: + print("Exception when calling RestClientApi->resource_get: %s\n" % e) \ No newline at end of file diff --git a/examples/rest_client_post.py b/examples/rest_client_post.py new file mode 100644 index 0000000..a7cb919 --- /dev/null +++ b/examples/rest_client_post.py @@ -0,0 +1,86 @@ +# You need use this example code in to the main folder +from __future__ import print_function +import time +import meli +from meli.rest import ApiException +from pprint import pprint +# Defining the host, defaults to https://api.mercadolibre.com +# See configuration.py for a list of all supported configuration parameters. +configuration = meli.Configuration( + host = "https://api.mercadolibre.com" +) + + +# Enter a context with an instance of the API client +with meli.ApiClient() as api_client: + # Create an instance of the API class + api_instance = meli.RestClientApi(api_client) + resource = 'items' # A resource like items, search, category etc + access_token = 'access_token_example' # Your access token + + # A body example to post a item in Argentina + body = { + "title": "Item de test - No Ofertar", + "category_id": "MLA5991", + "price": "350", + "currency_id": "ARS", + "available_quantity": "12", + "buying_mode": "buy_it_now", + "listing_type_id": "bronze", + "condition": "new", + "description": "Item de Teste. Mercado Livre SDK", + "video_id": "RXWn6kftTHY", + "pictures": [ + { + "source": "https://http2.mlstatic.com/storage/developers-site-cms-admin/openapi/319968615067-mp3.jpg" + } + ], + "attributes": [ + { + "id": "DATA_STORAGE_CAPACITY", + "name": "Capacidad de almacenamiento de datos", + "value_id": "null", + "value_name": "8 GB", + "value_struct": { + "number": 8, + "unit": "GB" + }, + "values": [ + { + "id": "null", + "name": "8 GB", + "struct": { + "number": 8, + "unit": "GB" + } + } + ], + "attribute_group_id": "OTHERS", + "attribute_group_name": "Otros" + } + ], + "variations": [ + { + "price": 350, + "attribute_combinations": [ + { + "name": "Color", + "value_id": "283165", + "value_name": "Gris" + } + ], + "available_quantity": 2, + "sold_quantity": 0, + "picture_ids": [ + "882629-MLA40983876214_032020" + ] + } + ] + } + + try: + # Resourse path POST + api_response = api_instance.resource_post(resource, access_token, body) + pprint(api_response) + except ApiException as e: + print("Exception when calling RestClientApi->resource_post: %s\n" % e) \ No newline at end of file