cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
454
Views
0
Helpful
1
Replies

Exception in thread "main" com.ciscospark.SparkException: io error

GVODAPAL
Level 1
Level 1

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.

1 Accepted Solution

dstaudt
Cisco Employee
Cisco Employee

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() );
    }
}

View solution in original post

1 Reply 1

dstaudt
Cisco Employee
Cisco Employee

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() );
    }
}