I am getting Connection timeout error while executing java program.
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Base64;
// HTTP basic authentication example in Java using the RTC Server RESTful API
public class Base64Encoding {
public static void main(String[] args) throws IOException, InterruptedException {
// Customer ID
final String customerKey = "";
// Customer secret
final String customerSecret = "";
// Concatenate customer key and customer secret and use base64 to encode the concatenated string
String plainCredentials = customerKey + ":" + customerSecret;
String base64Credentials = new String(Base64.getEncoder().encode(plainCredentials.getBytes()));
// Create authorization header
String authorizationHeader = "Basic " + base64Credentials;
HttpClient client = HttpClient.newHttpClient();
// Create HTTP request object
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.mypurecloud.com/api/v2/routing"))
.GET()
.header("Authorization", authorizationHeader)
.header("Content-Type", "application/json")
.build();
// Send HTTP request
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
Hello, you must use one of the supported authorization methods: https://developer.genesys.cloud/authorization/platform-auth/ .
yes, i am using client credentials with Grant method. if possible could you please share any sample java program that i can refer ?
Please refer to the client credentials documentation for how to authorize using client credentials. Your example code is not implementing this grant type.
You might also choose to use the Java SDK https://developer.genesys.cloud/devapps/sdk/docexplorer/purecloudjava/
Thanks Tim, but i tried using same code for authorization still getting connection timeout.
I Guess its proxy related issue, is there a way to use kerberos call for authentication?
package com.api.Genesys;
import java.io.IOException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.mypurecloud.sdk.v2.ApiClient;
import com.mypurecloud.sdk.v2.ApiException;
import com.mypurecloud.sdk.v2.ApiResponse;
import com.mypurecloud.sdk.v2.Configuration;
import com.mypurecloud.sdk.v2.api.UsersApi;
import com.mypurecloud.sdk.v2.extensions.AuthResponse;
import com.mypurecloud.sdk.v2.model.User;
import com.mypurecloud.sdk.v2.model.UserMe;
import com.mypurecloud.sdk.v2.model.UserEntityListing;
import com.mypurecloud.sdk.v2.PureCloudRegionHosts;
@SpringBootApplication
public class GenesysApplication {
public static void main(String[] args) throws IOException, ApiException {
SpringApplication.run(GenesysApplication.class, args);
String clientId = "";
String clientSecret = "";
//Set Region
PureCloudRegionHosts region = PureCloudRegionHosts.us_west_2;
ApiClient apiClient = ApiClient.Builder.standard().withBasePath(region).build();
ApiResponse<AuthResponse> authResponse = apiClient.authorizeClientCredentials(clientId, clientSecret);
// Don't actually do this, this logs your auth token to the console!
System.out.println(authResponse.getBody().toString());
// Use the ApiClient instance
Configuration.setDefaultApiClient(apiClient);
// Create API instances and make authenticated API requests
UsersApi apiInstance = new UsersApi();
UserEntityListing response = apiInstance.getUsers(null, null, null, null, null, null, null, null);
System.out.print(response);
}
}
Please work with your network security team to diagnose your network issues that are preventing you from accessing the login service/API.
No, you can only use the supported authorization methods I linked to previously.
Thanks @tim.smith issue was related to firewall block.
system
Closed
October 23, 2022, 6:11am
8
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.