0

Any one successfully use smartsheet sdk java 2.25 with proxy autnentication and CredentialsProvider? Below Apache httpclient 4.5 sample code works in our company, but smartsheet sdk api not works at all with proxy autnentication. I try to find out smartsheet object if it can set CredentialsProvider but unfortunately I don't see any method to set credentialprovider.

Any one know how to implement user name and password with smartsheet api proxy authentication ?

CredentialsProvider credsProvider = new BasicCredentialsProvider();
        
        credsProvider.setCredentials(
                new AuthScope("proxy", 8080),
                new UsernamePasswordCredentials("username", "password"));
                
        CloseableHttpClient httpclient = HttpClients.custom()
                .setDefaultCredentialsProvider(credsProvider).build();
        try {
            HttpHost target = new HttpHost("api.smartsheet.com", 443, "https");
            HttpHost proxy = new HttpHost("proxy", 8080);

            RequestConfig config = RequestConfig.custom()
                .setProxy(proxy)
                .build();
            HttpGet httpget = new HttpGet("/2.0/sheets");
            httpget.setConfig(config);

            System.out.println("Executing request " + httpget.getRequestLine() + " to " + target + " via " + proxy);

            CloseableHttpResponse response = httpclient.execute(target, httpget);
            try {
                System.out.println("----------------------------------------");
                System.out.println(response.getStatusLine());
                System.out.println(EntityUtils.toString(response.getEntity()));
            } finally {
                response.close();
            }
        } finally {
            httpclient.close();
        }

I have tried Apache sameple code and it works well with proxy authentication.

  • I'm not familiar with the Smartsheet Java SDK, but seems like someone asked a similar question here a few years ago: https://stackoverflow.com/questions/44163553/smartsheet-api-proxy-setup-for-java. Perhaps the QR Code sample app linked to in the answer on that thread would be helpful? (an example of customizing the HTTP stack): https://github.com/smartsheet-samples/QRScanner – Kim Brandl May 03 '23 at 14:10
  • yeah , I have check this sample before I ask this question , the sample only implement proxy but did not include authentication , smartsheet sdk did too much encapsulation that I can not use CredentialsProvider with smartsheet.httpclient – Sean Li May 03 '23 at 22:28
  • Ah, okay -- understood. Sorry I can't be of any help with this, my knowledge of Java is fairly limited. – Kim Brandl May 04 '23 at 01:08

0 Answers0