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
(PureBasic) MercadoLibre - Cargar factura (Upload Invoice)Cargar factura en detalle de venta For more information, see https://developers.mercadolibre.com.ar/es_ar/cargar-factura
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkHttpRequest.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; First get our previously obtained OAuth2 access token. jsonToken.i = CkJsonObject::ckCreate() If jsonToken.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkJsonObject::ckLoadFile(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 sbPath.i = CkStringBuilder::ckCreate() If sbPath.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbPath,"/packs/$PACK_ID/fiscal_documents?access_token=$ACCESS_TOKEN") ; Use an actual pack ID. numReplaced.i = CkStringBuilder::ckReplace(sbPath,"$PACK_ID","2000000089077943") numReplaced = CkStringBuilder::ckReplace(sbPath,"$ACCESS_TOKEN",CkJsonObject::ckStringOf(jsonToken,"access_token")) req.i = CkHttpRequest::ckCreate() If req.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpRequest::setCkHttpVerb(req, "POST") CkHttpRequest::setCkPath(req, CkStringBuilder::ckGetAsString(sbPath)) CkHttpRequest::setCkContentType(req, "multipart/form-data") success = CkHttpRequest::ckAddFileForUpload2(req,"fiscal_document","/home/user/.../Factura_adjunta.pdf","application/pdf") CkHttpRequest::ckAddHeader(req,"Expect","100-continue") CkHttpRequest::ckAddHeader(req,"content-type","multipart/form-data;") resp.i = CkHttp::ckSynchronousRequest(http,"api.mercadolibre.com",443,1,req) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) CkStringBuilder::ckDispose(sbPath) CkHttpRequest::ckDispose(req) ProcedureReturn EndIf sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodySb(resp,sbResponseBody) jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttpResponse::ckStatusCode(resp) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttpResponse::ckHeader(resp) Debug "Failed." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) CkStringBuilder::ckDispose(sbPath) CkHttpRequest::ckDispose(req) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(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 strVal.s i.i = 0 count_i.i = CkJsonObject::ckSizeOfArray(jResp,"ids") While i < count_i CkJsonObject::setCkI(jResp, i) strVal = CkJsonObject::ckStringOf(jResp,"ids[i]") i = i + 1 Wend CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) CkStringBuilder::ckDispose(sbPath) CkHttpRequest::ckDispose(req) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.