Documentación Mercado Libre
Descubre toda la información que debes conocer sobre las APIs de Mercado Libre.Documentación
Upload invoices
Upload invoices
In order to upload an invoice you must make a POST as form.data with key: type file and fiscal_document value that references the fiscal_document (document file you attach), pack_id (pack ID) and access_token (public token).
To know the pack_id, you must obtain the “pack_id” field in the response of /orders / <order_id>.
If the pack id contains a null value, must take the order id by default, keeping the resource /packs in the API request.
Request:
curl -X POST https://api.mercadolibre.com/packs/$PACK_ID/fiscal_documents
-H 'Authorization: Bearer $ACCESS_TOKEN'
-H 'Content-Type: multipart/form-data' \
-F 'fiscal_document=@/home/user/.../Factura_adjunta.pdf'
Example:
curl -X POST https://api.mercadolibre.com/packs/2000000089077943/fiscal_documents
-H 'Authorization: Bearer $ACCESS_TOKEN'
-H 'content-type: multipart/form-data'
-F 'fiscal_document=@/home/user/.../Factura_adjunta.pdf'
Response:
{
"ids" : ["415460047_a96d8dea-38cd-4402-938e-80a1c134fc5d"]
}
Attach XML file
Currently, you can choose to attach the invoice in associated XML, making the following POST and specifying one of the following formats:
- application/pdf
- application/xml
- text/xml
Request:
curl -X POST https://api.mercadolibre.com/packs/$PACK_ID/fiscal_documents
-H 'Authorization: Bearer $ACCESS_TOKEN'
-H 'content-type: multipart/form-data'
-F 'fiscal_document=@/home/user/.../Factura_adjunta.pdf'
-F 'fiscal_document=@/home/user/.../Factura_adjunta.xml'
Example:
curl -X POST 'https://api.mercadolibre.com/packs/2000000089077943/fiscal_documents'
-H 'Authorization: Bearer $ACCESS_TOKEN'
-H 'content-type: multipart/form-data'
-F 'fiscal_document=@/home/user/.../Factura_adjunta.pdf'
-F 'fiscal_document=@/home/user/.../Factura_adjunta.xml'
Response:
{
"ids" : ["415460047_a96d8dea-38cd-4402-938e-80a1c134fc5d",
"415460047_4c942945-ae16-46f2-98fa-a772322c7e70" ]
}
Possible errors in uploading an invoice
The user is not authorized to upload an invoice:
{
"message": "Access Denied, you are not authorized.",
"error": "forbidden",
"status": 403,
"cause": []
}
The file can not be null or file not found:
{
"message": "File cannot be empty",
"error": "bad_request",
"status": 400,
"cause": []
}
File type not supported:
{
"message":"File type: $FILE_TYPE is not allowed",
"error":"bad_request",
"status":400,
"cause":[
]
}
File exceeds maximum size:
{
"message":"File Not allowed, exceeds maximum size",
"error":"bad_request",
"status":400,
"cause":[]
}
More than one file attached:
{
"message":"Files Not allowed, you can upload only two files, one of each type",
"error":"bad_request",
"status":400,
"cause":[]
}
Attach more than one file in a pack of the same type:
{
"message":"Files Not allowed, you can upload only one file of type: $FILE_TYPE",
"error":"conflict",
"status":409,
"cause":[]
}
Attach a file in a pack that already has the maximum number of files previously loaded:
{
"message":"File Not allowed, the max amount of files already exist for the pack: $PACK_ID and seller: $SELLER_ID",
"error":"conflict",
"status":409,
"cause":[]
}
Attach a file of a type in a pack that already has a file of that type previously loaded:
{
"message":"File Not allowed, a file already exists for the pack: $PACK_ID and seller: $SELLER_ID of the type: $FILE_TYPE",
"error":"conflict",
"status":409,
"cause":[
]
}
File attached with empty name:
{
"message":"Filename cannot be empty",
"error":"bad_request",
"status":400,
"cause":[]
}
Obtain invoices IDs
In order to obtain the invoice id, you must make a GET request. The response will depend on the role of the user making the query and may be:
Rol vendedor: the id of the invoices you loaded in the pack.
Buyer role: all the ids of the invoices that belong to the pack.
Request:
curl -X GET -H 'Authorization: Bearer $ACCESS_TOKEN' https://api.mercadolibre.com/packs/$PACK_ID/fiscal_documents
Example:
curl -X GET -H 'Authorization: Bearer $ACCESS_TOKEN' https://api.mercadolibre.com/packs/2000000089077943/fiscal_documents
Response:
{
"pack_id": 2000000089077943,
"fiscal_documents":[
{
"id":"fc76f79d-1599-43ed-8675-569482e2ec21",
"date":"2020-04-27T23:10:21Z",
"file_type":"application/pdf"
"filename":"factura.pdf"
}
]
}
Errors obtaining the invoices ids
The user is not authorized to obtain the invoices ids associated with the pack:
{
"message": "Access Denied, you are not authorized.",
"error": "forbidden",
"status": 403,
"cause": []
}
If the pack does not have any invoices charged:
{
"message": "The pack_fiscal_document with pack_id: %d does not exist",
"error": "not_found",
"status": 404,
"cause": []
}
If the user does not have any invoices loaded by him within the pack:
{
"message": "The pack_fiscal_document with pack_id: %d does not have any fiscal_document attached for the user_id: %d",
"error": "not_found",
"status": 404,
"cause": []
}
Obtain invoices
To obtain invoices, you must make a GET request with the filename, i.e., the ID´s file. The response will be successful when it returns the file requested.
Request:
curl -X GET -H 'Authorization: Bearer $ACCESS_TOKEN' https://api.mercadolibre.com/packs/$PACK_ID/fiscal_documents/$FISCAL_DOCUMENT_ID
Example:
curl -X GET -H 'Authorization: Bearer $ACCESS_TOKEN' https://api.mercadolibre.com/packs/2000000089077943/fiscal_documents/415460047_a96d8dea-38cd-4402-938e-80a1c134fc5d
Errors obtaining the invoices
The user is not authorized to delete the invoices linked to the pack:
{
"message": "Access Denied for user with id : ${ID} to the fiscal_document with id: ${ID}.",
"error": "forbidden",
"status": 403,
"cause": []
}
The fiscal_document requested does not exist:
{
"message": "The fiscal_document with id: ${ID} does not exist",
"error": "bad_request",
"status": 400,
"cause": []
}
The invoices could not be found in the server, try again in some seconds:
{
"message": "The fiscal_document with id: ${ID} could not be retrieved from storage",
"error": "not_found",
"status": 404,
"cause": []
}
Delete invoices
To delete an invoice you must make a DELETE call specifying the pack_id i.e., the pack ID. This way, you will delete the invoices belonging to this pack.
Request:
curl -X DELETE -H 'Authorization: Bearer $ACCESS_TOKEN' https://api.mercadolibre.com/packs/$PACK_ID/fiscal_documents
Example:
curl -X DELETE -H 'Authorization: Bearer $ACCESS_TOKEN' https://api.mercadolibre.com/packs/2000000089077943/fiscal_documents
If the seller has only 1 file attached to the PACK_ID, this is the response:
{
"message" : "The fiscal_document with "id" : 415460047_a96d8dea-38cd-4402-938e-80a1c134fc5d was deleted"
}
If you have more than one file attached (PDF and XML), the response is:
{
"message" : "The fiscal_documents with the following ids: 415460047_a96d8dea-38cd-4402-938e-80a1c134fc5d, 415460047_4c942945-ae16-46f2-98fa-a772322c7e70 were deleted
}
Possible errors deleting an invoice
Deleting a non-existing or already deleted invoices from a pack:
{
"message":"Cannot delete. The pack: 2000000089077943 doesn't have a fiscal_document attached",
"error":"not_found",
"status":404,
"cause":[]
}
User is not authorized to delete the invoices linked to the pack:
{
"message": "Access Denied, you are not authorized.",
"error": "forbidden",
"status": 403,
"cause": []
}
Possible errors requesting billing data
The body is empty:
{
"message": "The body of the request cannot be empty",
"error": "internal_server_error",
"status": 500,
"cause": []
}
Could not retrieve body of request:
{
"message": "Error retrieving the body from the request",
"error": "internal_server_error",
"status": 500,
"cause": []
}
The user is not authorized to request tax data:
{
"message": "Access Denied, you are not authorized.",
"error": "forbidden",
"status": 403,
"cause": []
}
If the user can not use the messaging:
{
"message": "You cannot ask for the billing_info because you are not allowed to use the messaging service",
"error": "forbidden",
"status": 403,
"cause": []
}
If the text exceeds the maximum number of characters:
{
"message": "The text content is too long, max characters allowed are: 500",
"error": "bad_request",
"status": 400,
"cause": []
}
If the text is empty:
{
"message": "The text content cannot be empty",
"error": "bad_request",
"status": 400,
"cause": []
}
If the text is not valid:
{
"message": "You cannot ask for the billing_info because the text is not valid. Check Messaging Post Sale documentation for more information",
"error": "not_acceptable",
"status": 406,
"cause": []
}
General errors
The order id do not be part of a pack:
{
"message": "The order belong to a pack/purchase",
"error": "bad_request",
"status": 400,
"cause": []
}
Pack_id empty or non-numeric:
{
"message": "pack.id must be numeric and not empty",
"error": "bad_request",
"status": 400,
"cause": []
}
Negative pack_id or 0:
{
"message": "pack.id is invalid",
"error": "bad_request",
"status": 400,
"cause": []
}
Access token error
If you make the query without the corresponding ACCESS_TOKEN, you will get the following error:
{
"message": "access_token was not sent",
"error": "access_token_not_granted",
"status": 403,
"cause": []
}
Error for access from unauthorized site
In case you want to use the API from a site where it is not available, you will get the following error:
{
"message": "Access Denied, this API is not available on your site: MLB",
"error": "forbidden",
"status": 403,
"cause": []
}