IBM i Global

IBM i 

A space for professionals working with IBM’s integrated OS for Power systems to exchange ideas, ask questions, and share expertise on topics like RPG and COBOL development, application modernization, open source integration, system administration, and business continuity.


#Power


#IBMi
 View Only
  • 1.  Uploading multipart document using QSYS2.HTTP_POST_VERBOSE

    Posted Fri June 28, 2024 10:26 AM

    Hello Everyone. 

    I need your help figuring out how to use  QSYS2.HTTP_POST_VERBOSE to send a file to Azure blob. 

    I can use the POSTMAN to upload using that end point. 

    Here is my code. 

    ifsFile_NAME =  '/LIB01/text.csv';
            ifsFile_NL = %len(ifsFile_NAME);
            ifsFile_FO = SQFOVR; // Overwrite any existing file

            url = 'https://simple-storage.apps.cloud/api' +
                  '/v1/repositories/ecsh-ist/documents/ecshTest/cidTestSearch2.txt';


            //Extract the IFS file
            exec sql
                    // SELECT GET_CLOB_FROM_FILE(:ifsFile, 1)
                    SELECT GET_CLOB_FROM_FILE('va967/cidmrg(CIDMRG)', 1)
                    INTO :data1
            FROM SYSIBM.SYSDUMMY1;

            //Setup the body
            exec sql Set :Req_BODY = json_object(
                    'document_content' value 'Text',
                    'document_attribute' value json_object (
                            'document_name' value :data1,
                            'description' value 'This is a test file'
                            ),
                    'folder' value  json_object (
                            'folder_path' value '/ecshTest/'
                            ),
                    'document_metadata' value json_object (
                            'metadata_items' value json_array (
                                    json_object('key' value 'DocumentType',
                                                'value' value 'text/plain'),
                                    json_object('key'  value 'ClientID',
                                                'value' value '010174132822100',
                                            'index' value '1')
                                    )
                            )
                    );

            //Setup the header
            exec sql Set :Header = json_object(
                    'header' value ('content-type,multipart/form-data;'
                    'header' value 'content-length, 3000',                    
                    'header' value 'x-channel-id, Branch',
                    'header' value 'x-originating-appl-code, CAD',
                    'header' value 'x-country-code, CA',
                    'header' value 'Host, simple-storage-ist.apps.cloud.bns'


            exec sql
                    select response_http_header, response_message
                    into :rsp_hdr ,
                         :rsp_msg
                    from table(QSYS2.HTTP_POST_VERBOSE(
                            :url, :Req_BODY, :Header));

    I am using that uere, but I am getting 405 error. 

    Here is the error text (rsp_msg):

    {"data":null,"notifications":[{"code":"405","message":"Request method 'POST' not supported. Supported methods: 
    [GET, PUT, DELETE]","severity":"ERROR","category":null,"description":null,"action":null,"metadata":{},
    "uuid":"134a24be-e6cf-4648-8663-69bb0d4c5729","timestamp":"2024-06-28T14:18:36.622072Z","field_name":"HTTP request method"}]}

    Here is the composed header value (Header):

    {"header":"content-type,multipart/form-data;",
    "header":"content-length, 3000","header":"x-channel-id, Branch",
    "header":"x-originating-appl-code, CAD",
    "header":"x-country-code, CA","header":"Host, simple-storage-ist.apps.cloud.bns"}

    Here is the BODY JSON (Req_BODY):

    █Ì{"document_content":"Text","document_attribute":{"document
    _name":"\u009C011171143347239716285021820103\u00020213482034
    45977015339154803115\u0003020177164040528015266170520643K020
    349132346648021352172209015\u0002021039135722544015356191057
    623\u0002014053131229543021298104025474\u0001021305111955410
    019170115624317\u008D020070150912956018011060615714\u0002015
    082130228311015006113341028\u0002015082130228311716227124818
    847\u009D016141060421696018152165920711\u0002018262114049052
    018228101203924\u0002019273172751014021239144838000õ01819008
    2104117021347113826725\u0001995170008656970021065120758501\u
    0002099348155150336019080122829140\t498310000767008616224011
    921828\u0086012065164444589021349200755763\u0086012065164444
    589015364100937267\u0001016103134256660021097155629718\u008E
    021238121222819021243123009620ä02104222461794401707317421465
    8\u0002019039072454899017304220900170\u000102134720211157802
    1347203921131\t018040215952050020117015043282\u0002716227110
    006543016239180523689=021351152238566021195083542759\u000202
    1352113749475021224071000008ï021313194725742017053125922350\
    u0001010053160601614017298130931276\t09930813313409502008814
    5140328\u0001009264124055430017170135607616","description":"
    This is a test file"},"folder":{"folder_path":"/ecshTest/"},
    "document_metadata":{"metadata_items":[{"key":"DocumentType"
    ,"value":"text/plain"},{"key":"ClientID","value":"0101741328
    22100","index":"1"}]}} 

    Any help would be appriciated. 

    Thanks



    ------------------------------
    Sarvan Veluppillai
    ------------------------------


  • 2.  RE: Uploading multipart document using QSYS2.HTTP_POST_VERBOSE

    Posted Mon July 01, 2024 10:19 AM

    I do not think the QSYS2 tools support multipart form data, try sending the data as application/octet-stream.



    ------------------------------
    Nadir K Amra
    ------------------------------



  • 3.  RE: Uploading multipart document using QSYS2.HTTP_POST_VERBOSE

    Posted Mon July 01, 2024 11:48 AM

    Looks like that error message is coming from the server and saying it does not support POST.  You probably have to do that as a PUT with an appropriate data type.  Depends on what the Azure endpoint is expecting.



    ------------------------------
    Vincent Greene
    IT Consultant
    Technology Expert labs
    IBM
    Vincent.Greene@ibm.com


    The postings on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
    ------------------------------



  • 4.  RE: Uploading multipart document using QSYS2.HTTP_POST_VERBOSE

    Posted Tue July 02, 2024 11:49 AM

    @Nadir I think you are correct..  I saw post from Scott saying that QSYS2 do not support multipart.  I was hopping if anyone able to get this done using QSYS2. 

    Well, I use HTTPAPI from Scott and it worked well.  

    @Vincent Greene - The end point do support POST.  I was able to upload the file using POSTMAN.  The POSTMAN request do use POST. 

    Thanks



    ------------------------------
    Sarvan Veluppillai
    ------------------------------