10-10-2022 10:23 AM
Exception in thread "main" com.ciscospark.SparkException: io error
i am trying to post a message to a webex group, i have given the roomid and access token but getting the above exception while running the application
i am able to post the messages from the developer portal using the api's, but not able to do it using the java application.
Solved! Go to Solution.
10-10-2022 01:42 PM
Guessing you may be trying to use the Java SDK...
Unfortunately, it looks like that SDK has not been updated in >3 years, and still points to the old/deprecated Webex REST API endpoint (https://api.ciscospark.com/v1) vs. the new/current one (https://webexapis.com/v1).
You could possibly update the URL in the Java SDK source files yourself (e.g. here), or it looks like you can provide the base URL at runtime (see README.md)
In the end, given the apparent low focus on the Java SDK, it may be better to just make native Java REST calls based on the interactive docs. For example:
package samples.source;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class POSTmessages {
public static void main( String[] args ) throws URISyntaxException, IOException, InterruptedException {
// Build message JSON object
String payload = "{ \"roomId\": \"Y2lzY29zcGFyazovL3VzL1JPT00vOGQ4YmEwZTAtMTlkNy0xMWU2LTg1OWEtOWYxODkzNjRkMGUx\", \"text\": \"Hello World!\"}";
// Build HTTP POST request
HttpRequest request = HttpRequest.newBuilder()
.uri( new URI( "https://webexapis.com/v1/messages" ) )
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("Authorization", "Bearer MjE2Zjg2ODctNDQyredacted4-ad72cae0e10f")
.POST( HttpRequest.BodyPublishers.ofString( payload ) )
.build();
// Execute the request
HttpResponse<String> response = HttpClient.newHttpClient()
.send( request, HttpResponse.BodyHandlers.ofString() );
System.out.println( response.body() );
}
}
10-10-2022 01:42 PM
Guessing you may be trying to use the Java SDK...
Unfortunately, it looks like that SDK has not been updated in >3 years, and still points to the old/deprecated Webex REST API endpoint (https://api.ciscospark.com/v1) vs. the new/current one (https://webexapis.com/v1).
You could possibly update the URL in the Java SDK source files yourself (e.g. here), or it looks like you can provide the base URL at runtime (see README.md)
In the end, given the apparent low focus on the Java SDK, it may be better to just make native Java REST calls based on the interactive docs. For example:
package samples.source;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class POSTmessages {
public static void main( String[] args ) throws URISyntaxException, IOException, InterruptedException {
// Build message JSON object
String payload = "{ \"roomId\": \"Y2lzY29zcGFyazovL3VzL1JPT00vOGQ4YmEwZTAtMTlkNy0xMWU2LTg1OWEtOWYxODkzNjRkMGUx\", \"text\": \"Hello World!\"}";
// Build HTTP POST request
HttpRequest request = HttpRequest.newBuilder()
.uri( new URI( "https://webexapis.com/v1/messages" ) )
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("Authorization", "Bearer MjE2Zjg2ODctNDQyredacted4-ad72cae0e10f")
.POST( HttpRequest.BodyPublishers.ofString( payload ) )
.build();
// Execute the request
HttpResponse<String> response = HttpClient.newHttpClient()
.send( request, HttpResponse.BodyHandlers.ofString() );
System.out.println( response.body() );
}
}
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide