Code Examples for Upload API

Example (HTTP Client)

This section explains the use of bulk upload through the postman http client. via web link: https://www.postman.com/ or from the desktop application.

Upload file from API

To start, you must create a new request using the POST method:

You must put the following URL in the indicated section in the HTTP client "Enter Request URL":

To be able to upload the file you need to configure the request body, since it must be sent as form-data:

After attaching the parameters and their values, you can now send the request.

Tracking file uploaded from API

To get the progress information of the previously uploaded file, you must create a new request using the GET method:

You must add the parameters in the lower section in the "Params" option:

After attaching the parameters and their values, you can now send the request.

Download uploaded document from API

To retrieve any of the available parts of the uploaded file, you should use the GET method:

You must add the parameters in the lower section in the "Params" option.

After attaching the parameters and their values, you can now send the request.

📘

Download sample requests

You can help yourself by downloading the following collection of requests to import it into postman: https://public-r6.s3.amazonaws.com/naics_files/BulkUpload.postman_collection.json

Bulk Upload File Example

Below is an example of a Bulk Upload File Example:

Bulk Upload File Example

Java

Upload file from API

package com.relativity6.bulkupload;


import java.io.File;
import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class Naics{

    public static void main(String[] args) throws IOException {
    
      File file = new File("PATH_FILE");
      var token = "YOUR_TOKEN_HERE";
      var description = "description example";
    
      CloseableHttpClient httpclient = HttpClients.createDefault();
      
      FileBody filebody = new FileBody(file, ContentType.DEFAULT_BINARY);
      
      MultipartEntityBuilder entitybuilder = MultipartEntityBuilder.create();
   
      entitybuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

      entitybuilder.addTextBody("token", token);
      entitybuilder.addTextBody("description", description);
      entitybuilder.addBinaryBody("file", file);

      HttpEntity mutiPartHttpEntity = entitybuilder.build();

      RequestBuilder reqbuilder = RequestBuilder.post("https://api.usemarvin.ai/naics/naics/external/upload");
      
      reqbuilder.setEntity(mutiPartHttpEntity);
      
      HttpUriRequest multipartRequest = reqbuilder.build();

      HttpResponse httpresponse = (HttpResponse) httpclient.execute(multipartRequest);

      System.out.println(EntityUtils.toString(httpresponse.getEntity()));
      System.out.println(httpresponse.getStatusLine());
    }

}

Tracking file uploaded from API

package com.relativity6.bulkupload;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class Naics{

    public static void main(String[] args) throws MalformedURLException, IOException {

        var token = "YOUR_TOKEN_HERE";
        var folio = "FILE_FOLIO";

        StringBuilder response = new StringBuilder();
      
        URL url = new URL("https://api.usemarvin.ai/naics/naics/external/upload/file/info?token=" + token + "&folio=" + folio);
        
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        conexion.setRequestMethod("GET");
        
        BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String line;
      
        while ((line = rd.readLine()) != null) {
            resultado.append(line);
        }
        
        rd.close();
        
        System.out.println(response);
    }
}

Download uploaded document from API

package com.relativity6.bulkupload;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Naics{

    public static void main(String[] args) throws IOException {

        var token = "YOUR_TOKEN_HERE";
        var folio = "FILE_FOLIO";
        var part = PART_NUMBER;
        var status = "FILE_STATUS";

        StringBuilder response = new StringBuilder();
        
        URL url = new URL("https://api.usemarvin.ai/naics/naics/external/upload/file/download?folio="+ folio + "&token=" +  token + "&part=" + part + "&fileStatus=" + status);

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        conexion.setRequestMethod("GET");
        
        BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String line;
        
        while ((line = rd.readLine()) != null) {
            resultado.append(line);
        }
        
        rd.close();
        
        System.out.println(response);
    }

}

C#

Tracking file uploaded from API

using System;
using System.IO;
using System.Net;

public class Naics
{
    public static void Main(string[] args)
    {
          
         var token = "YOUR_TOKEN_HERE";
         var folio = "FILE_FOLIO";
         
         var url = "https://api.usemarvin.ai/naics/naics/external/upload/file/info?token="+ token +"&folio="+ folio;

         try
         {
              var httpRequest = (HttpWebRequest)WebRequest.Create(url);
         
              var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
         
              using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
              {
         
                  var result = streamReader.ReadToEnd();
                  Console.WriteLine(result);
              }

              Console.WriteLine(httpResponse.StatusCode);
         }
         catch(Exception e)
         {
         
              Console.WriteLine(e);
         }
    }
}

Download uploaded document from API

using System;
using System.IO;
using System.Net;

public class Naics
{
    public static void Main(string[] args)
    {
    
       var token = "YOUR_TOKEN_HERE";
       var folio = "FILE_FOLIO";
       var part = NUMBER_PART;
       var fileStatus = "FILE_STATUS";
       
       var url = "https://api.usemarvin.ai/naics/naics/external/upload/file/download?folio="+ folio +"&token="+ token +"&part="+ part +"&fileStatus="+ fileStatus;

       try
       {
            var httpRequest = (HttpWebRequest)WebRequest.Create(url);

            var httpResponse = (HttpWebResponse)httpRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                Console.WriteLine(result);
            }
            
            Console.WriteLine(httpResponse.StatusCode);
       }
       catch(Exception e)
       {
         
            Console.WriteLine(e);
       } 
    }
}

Python

Upload file from API

import requests

p = {'token': 'YOUR_TOKEN_HERE','description': 'example description'}
files = {'file': open('PATH_FILE', 'rb')}

url = "https://api.usemarvin.ai/naics/naics/external/upload"

resp = requests.post(url, params = p, files = files)

print(resp.status_code)
print(resp.content)

Tracking file uploaded from API

import requests

p = {'token': 'YOUR_TOKEN_HERE','folio': 'FOLIO_FILE'}

url = "https://api.usemarvin.ai/naics/naics/external/upload/file/info"


resp = requests.get(url, params = p)

print(resp.status_code)
print(resp.content)

Download uploaded document from API

import requests

p = {'token': 'YOUR_TOKEN_HERE', 'folio': 'FOLIO_FILE', 'part': PART_NUMBER, 'fileStatus': 'FILE_STATUS'}

url = "https://api.usemarvin.ai/naics/naics/external/upload/file/download"


resp = requests.get(url, params = p)

print(resp.status_code)
print(resp.content)

Did this page help you?