How to use API in NAV2018?

EmazEmaz Member Posts: 8
edited 2020-04-01 in NAV Three Tier
Hi,

I want to use the ZPL Web Service (RESTful API) in NAV2018.

My aim is to send a ZPL-Code and get back a png.

I tried diffrent ways, but failed.

I Always get diffrent Error-Messages. To post them would make no sense...
I tried it with two funktions.

First (using Codeunit 1297)


Second Using DotNet (but it is almost the same as before)



Any helpful hints or codeexamples?

Thanks and best regards

Emaz

Answers

  • xStepaxStepa Member Posts: 106
    Hi, don't know your service, but this is an example using cu1290:
    LOCAL [TryFunction] TryEncodeQR(pRawText : Text;pQRSize : Integer;VAR pvQRCode : TEMPORARY Record TempBlob SECURITYFILTERING(Ignored))
      lSOAPWebServiceRequestMgt.BuildWebRequestMethod(pRawText, 'GET', lXMLWebRequest); //where pRawText is Address with params
      lXMLHttpResponse := lXMLWebRequest.GetResponse;
      lInStream := lXMLHttpResponse.GetResponseStream;
      pvQRCode.Blob.CREATEOUTSTREAM(lOutStream);
      COPYSTREAM(lOutStream, lInStream);
    
    Regards
    xStepa
  • EmazEmaz Member Posts: 8
    Hi,

    thank you, but I find my mistake.
    URL := 'http://api.labelary.com/v1/printers/12dpmm/labels/4x6/0/';
    
    HttpWebRequestMgt.Initialize(URL);
    HttpWebRequestMgt.DisableUI;
    HttpWebRequestMgt.SetMethod('POST');
    HttpWebRequestMgt.SetReturnType('image/png');
    HttpWebRequestMgt.SetContentType('application/x-www-form-urlencoded');
    HttpWebRequestMgt.SetExpect(FALSE);
    HttpWebRequestMgt.AddBodyAsText(ZPL);
    
    TempBlob.INIT;
    TempBlob.Blob.CREATEINSTREAM(InStr);
     
    IF HttpWebRequestMgt.GetResponse(InStr,HttpStatusCode,ResponseHeaders) THEN BEGIN
      IF LabelHeader.GET(LabelCode) THEN BEGIN 
        LabelHeader.Label := TempBlob.Blob;
        LabelHeader.MODIFY;
      END;
    END ELSE
      MESSAGE(ErrorMsg);
    


Sign In or Register to comment.