Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 


#Product
#Analytics
#CognosAnalytics
#Analyticstools
#TechXchange Partner
#TechXchange Session
#TechXchange Presenter
#AI
 View Only
  • 1.  Upload a file through REST API

    Posted 11/23/20 07:20 AM

    Hello,

    I would like to use POST files/import Cognos REST API to upload an excel file from file system.

    Unfortunately I did not figure out how to do that and I have not found any example how to fill fileimport JSON body. Has anyone managed to run this? I will appreciate any help! 

    Thank you!



    ------------------------------
    Jiri Smrz
    ------------------------------

    #CognosAnalyticswithWatson


  • 2.  RE: Upload a file through REST API

    Posted 10/09/23 11:29 AM
    Edited by Andres Parada 10/11/23 09:23 AM

    Did you manage to discover a resolution for this issue? We attempted to use Swagger Docs, but encountered difficulties when attempting to upload a file from the file comments using the POST command with query parameters



    -------------------------- 

    kumar
    ------------------------------



  • 3.  RE: Upload a file through REST API

    Posted 10/09/23 11:30 AM
    Edited by Andres Parada 10/11/23 09:23 AM

    Hi Jiri Smrz

    Did you manage to discover a resolution for this issue? We attempted to use Swagger Docs but encountered difficulties when attempting to upload a file from the file comments using the POST command with query parameters.

    Thanks



    -----------------------------

    vinod kumar
    ------------------------------



  • 4.  RE: Upload a file through REST API

    Posted 10/10/23 06:12 PM

    You might want to contact @Paul Mendelson about this.



    ------------------------------
    Ralf Roeber
    https://linkedin.com/in/ralf-roeber/
    ------------------------------



  • 5.  RE: Upload a file through REST API

    Posted 10/17/23 01:56 PM

    Hello Jiri,
    I've attached a couple of files that should help to get you started. These files were part of the sdk distribution in an earlier release, but didn't make it into the more recent releases. (We will try to get that corrected).
    Hopefully this will help you to be able to make progress.



    ------------------------------
    Kind regards,
    Henk Cazemier
    ------------------------------

    Attachment(s)

    java
    UploadFileExample.java   2 KB 1 version
    java
    AppendFileExample.java   2 KB 1 version
    java
    FileImportHelper.java   8 KB 1 version
    java
    ReplaceFileExample.java   2 KB 1 version


  • 6.  RE: Upload a file through REST API

    Posted 08/19/24 10:30 AM

    @HENK CAZEMIER do you know the jar which we have to use in order to use the Java classes.



    ------------------------------
    Puneet Bansal
    ------------------------------



  • 7.  RE: Upload a file through REST API

    Posted 08/19/24 06:14 PM
    Edited by Andrei Istomine 08/19/24 07:01 PM

    You can check the Python sample out.

    Sample python script to upload a file (csv, xls, xlsx) to Cognos Analytics 11.1.7 and above using the REST API.



    ------------------------------
    Andrei Istomine
    Open to work - anything Cognos
    https://www.linkedin.com/in/andreii/
    ------------------------------



  • 8.  RE: Upload a file through REST API

    Posted 08/21/24 10:11 AM

    Thanks @Andrei Istomine thanks for sharing this, its really helpful but i am using the Spring boot code. I am facing the issue while uploading the file. Could you please tell me what should the body of below type. 

    /files/import/segment/"+segament+"?index=-1"


    ------------------------------
    Puneet Bansal
    ------------------------------



  • 9.  RE: Upload a file through REST API

    Posted 08/21/24 11:20 AM

    Look at the Henk's sample in FileImportHelper.java 

    Each Segment is Read from the file to the buffer.

    You would need to re-factor the sample code to use pure HttpPut

    			// issue series of segment PUTs
    			for (int index = 1; filedata.available() > 0; index++) {
    				byte[] buffer = new byte[Math.min(buffer_size, filedata.available())];
    				filedata.read(buffer);
    
    				HttpPut request = new HttpPut(path + "?" + SEGMENT + "=" + String.valueOf(index));
    				request.setHeader(HttpHeaders.CONTENT_TYPE, contentType);
    				request.setHeader(affinity.getName(), affinity.getValue());
    
    				request.setEntity(new InputStreamEntity(new ByteArrayInputStream(buffer)));
    
    				executeHttpRequest(request, Integer.valueOf(202), null);
    			}


    ------------------------------
    Andrei Istomine
    Open to work - anything Cognos
    https://www.linkedin.com/in/andreii/
    ------------------------------