Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) MercadoLibre - Cargar factura (Upload Invoice)Cargar factura en detalle de venta For more information, see https://developers.mercadolibre.com.ar/es_ar/cargar-factura
load ./chilkat.dll # This example assumes the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set http [new_CkHttp] # First get our previously obtained OAuth2 access token. set jsonToken [new_CkJsonObject] set success [CkJsonObject_LoadFile $jsonToken "qa_data/tokens/mercadolibre.json"] # Implements the following CURL command: # curl -X POST https://api.mercadolibre.com/packs/$PACK_ID/fiscal_documents?access_token=$ACCESS_TOKEN # -H 'content-type: multipart/form-data;' # -F 'fiscal_document=@/home/user/.../Factura_adjunta.pdf' # Use the following online tool to generate HTTP code from a CURL command # Convert a cURL Command to HTTP Source Code set sbPath [new_CkStringBuilder] CkStringBuilder_Append $sbPath "/packs/$PACK_ID/fiscal_documents?access_token=$ACCESS_TOKEN" # Use an actual pack ID. set numReplaced [CkStringBuilder_Replace $sbPath "$PACK_ID" "2000000089077943"] set numReplaced [CkStringBuilder_Replace $sbPath "$ACCESS_TOKEN" [CkJsonObject_stringOf $jsonToken "access_token"]] set req [new_CkHttpRequest] CkHttpRequest_put_HttpVerb $req "POST" CkHttpRequest_put_Path $req [CkStringBuilder_getAsString $sbPath] CkHttpRequest_put_ContentType $req "multipart/form-data" set success [CkHttpRequest_AddFileForUpload2 $req "fiscal_document" "/home/user/.../Factura_adjunta.pdf" "application/pdf"] CkHttpRequest_AddHeader $req "Expect" "100-continue" CkHttpRequest_AddHeader $req "content-type" "multipart/form-data;" # resp is a CkHttpResponse set resp [CkHttp_SynchronousRequest $http "api.mercadolibre.com" 443 1 $req] if {[CkHttp_get_LastMethodSuccess $http] == 0} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkJsonObject $jsonToken delete_CkStringBuilder $sbPath delete_CkHttpRequest $req exit } set sbResponseBody [new_CkStringBuilder] CkHttpResponse_GetBodySb $resp $sbResponseBody set jResp [new_CkJsonObject] CkJsonObject_LoadSb $jResp $sbResponseBody CkJsonObject_put_EmitCompact $jResp 0 puts "Response Body:" puts [CkJsonObject_emit $jResp] set respStatusCode [CkHttpResponse_get_StatusCode $resp] puts "Response Status Code = $respStatusCode" if {$respStatusCode >= 400} then { puts "Response Header:" puts [CkHttpResponse_header $resp] puts "Failed." delete_CkHttpResponse $resp delete_CkHttp $http delete_CkJsonObject $jsonToken delete_CkStringBuilder $sbPath delete_CkHttpRequest $req delete_CkStringBuilder $sbResponseBody delete_CkJsonObject $jResp exit } delete_CkHttpResponse $resp # Sample JSON response: # (Sample code for parsing the JSON response is shown below) # { # "ids": [ # "415460047_a96d8dea-38cd-4402-938e-80a1c134fc5d" # ] # } # Sample code for parsing the JSON response... # Use the following online tool to generate parsing code from sample JSON: # Generate Parsing Code from JSON set i 0 set count_i [CkJsonObject_SizeOfArray $jResp "ids"] while {$i < $count_i} { CkJsonObject_put_I $jResp $i set strVal [CkJsonObject_stringOf $jResp "ids[i]"] set i [expr $i + 1] } delete_CkHttp $http delete_CkJsonObject $jsonToken delete_CkStringBuilder $sbPath delete_CkHttpRequest $req delete_CkStringBuilder $sbResponseBody delete_CkJsonObject $jResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.