question

BaharSaffarian avatar image
BaharSaffarian asked

Run time error while calling telnyx createMessage Api on JAVA8

Hi My Project is on java 8 and I'm trying to develop an integration with telnyx messaging api, I've done every thing mentioned in sample code. But in run time when this method is called:

"com.telnyx.sdk.api.MessagesApi.createMessage.createMessage(CreateMessageRequest createMessageRequest)"

I take this error in console :

java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll(Ljava/lang/Object;[Ljava/lang/Object;)V

 at org.glassfish.jersey.client.ClientRequest.accept(ClientRequest.java:323)
 at org.glassfish.jersey.client.JerseyInvocation$Builder.accept(JerseyInvocation.java:224)
 at org.glassfish.jersey.client.JerseyInvocation$Builder.accept(JerseyInvocation.java:147)
 at com.telnyx.sdk.ApiClient.invokeAPI(ApiClient.java:906)
 at com.telnyx.sdk.api.MessagesApi.createMessageWithHttpInfo(MessagesApi.java:178)
 at com.telnyx.sdk.api.MessagesApi.createMessage(MessagesApi.java:132)

Could you please help me with that?

messagingerrorjava
2 comments
10 |600

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

vidhan avatar image vidhan ♦♦ commented ·

Hi @BaharSaffarian , kindly share your code/ code snippet

0 Likes 0 ·
klane@telnyx.com avatar image klane@telnyx.com ♦♦ commented ·

Appreciate your patience, this is in queue to be answered by our developer team. Check back for updates soon :)

0 Likes 0 ·
BaharSaffarian avatar image
BaharSaffarian answered

Here is the code in Kotlin:

@Test fun telnyxSendSmsTest() {

     val telnyxNumber = "+12702008692"
     val telnyxApiKey = "KEY0182A10DC8EBE12F39CDF6C3B3DA1466_9bGXhFiOTB2x1f12u7a8dP"
     val toPhone = "+6156528352"
     val messageContext = "Something"

     val defaultClient : ApiClient = Configuration.getDefaultApiClient()
     defaultClient.basePath = "https://api.telnyx.com/v2"

     // Configure HTTP bearer authorization: bearerAuth
     val bearerAuth = defaultClient.getAuthentication("bearerAuth") as HttpBearerAuth
     bearerAuth.bearerToken = telnyxApiKey

     val apiInstance = MessagesApi(defaultClient)
     // CreateMessageRequest | Message payload
     val createMessageRequest = CreateMessageRequest()
         .from(telnyxNumber)
         .to(toPhone)
         .text(messageContext)
     try {
         val telnyxResponse = apiInstance.createMessage(createMessageRequest)
         assertNotNull(telnyxResponse)
     } catch (e: Exception) {
         System.err.println("Exception when calling MessagesApi#createMessage");
         e.printStackTrace();
     }
 }

And this is the maven dependency I've used:

    <dependency>
         <groupId>com.telnyx.sdk</groupId>
         <artifactId>telnyx</artifactId>
         <version>2.8.0</version>
         <scope>compile</scope>
     </dependency>
10 |600

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

$$ANON_USER$$ avatar image
$$ANON_USER$$ answered

Here the code in Kotlin:

 @Test
 fun telnyxSendSmsTest() {

     val telnyxNumber = "+12702008692"
     val telnyxApiKey = "KEY0182A10DC8EBE12F39CDF6C3B3DA1466_9bGXhFiOTB2x1f12u7a8dP"
     val toPhone = "+6156528352"
     val messageContext = "Something"

     val defaultClient : ApiClient = Configuration.getDefaultApiClient()
     defaultClient.basePath = "https://api.telnyx.com/v2"

     // Configure HTTP bearer authorization: bearerAuth
     val bearerAuth = defaultClient.getAuthentication("bearerAuth") as HttpBearerAuth
     bearerAuth.bearerToken = telnyxApiKey

     val apiInstance = MessagesApi(defaultClient)
     // CreateMessageRequest | Message payload
     val createMessageRequest = CreateMessageRequest()
         .from(telnyxNumber)
         .to(toPhone)
         .text(messageContext)
     try {
         val telnyxResponse = apiInstance.createMessage(createMessageRequest)
         assertNotNull(telnyxResponse)
     } catch (e: Exception) {
         System.err.println("Exception when calling MessagesApi#createMessage");
         e.printStackTrace();
     }
 }
10 |600

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

vlad avatar image
vlad answered

Hey there!

I think there might be some bad pathing/nesting in the create request. Can you try running this in Kotlin and see if it works on your end?

 import com.telnyx.sdk.*;
 import com.telnyx.sdk.api.MessagesApi;
 import com.telnyx.sdk.api.NumberSearchApi;
 import com.telnyx.sdk.auth.*;
 import com.telnyx.sdk.model.*;
 import java.util.Arrays;
 import java.util.List;
 import java.util.UUID;
 import java.util.stream.Collectors;
    
 public class MessagingExample {
    
     private static final String YOUR_TELNYX_NUMBER = "YOUR_TELNYX_NUMBER";
     private static final String YOUR_MOBILE_NUMBER = "YOUR_TEST_NUMBER";
     private static final String YOUR_TELNYX_API_KEY = "API_KEY";
    
     public static void sendMessageExample() {
         ApiClient defaultClient = Configuration.getDefaultApiClient();
         defaultClient.setBasePath("https://api.telnyx.com/v2");
    
         // Configure HTTP bearer authorization: bearerAuth
         HttpBearerAuth bearerAuth = (HttpBearerAuth) defaultClient.getAuthentication("bearerAuth");
         bearerAuth.setBearerToken(YOUR_TELNYX_API_KEY);
    
         MessagesApi apiInstance = new MessagesApi(defaultClient);
          // CreateMessageRequest | Message payload
         CreateMessageRequest createMessageRequest = new CreateMessageRequest()
                 .from(YOUR_TELNYX_NUMBER)
                 .to(YOUR_MOBILE_NUMBER)
                 .text("Hello From Telnyx")
                 .mediaUrls(Arrays.asList(
                         "https://upload.wikimedia.org/wikipedia/en/5/5f/Original_Doge_meme.jpg"
                 ));
         try {
             MessageResponse result = apiInstance.createMessage(createMessageRequest);
             System.out.println(result);
         } catch (ApiException e) {
             System.err.println("Exception when calling MessagesApi#createMessage");
             System.err.println("Status code: " + e.getCode());
             System.err.println("Reason: " + e.getResponseBody());
             System.err.println("Response headers: " + e.getResponseHeaders());
             e.printStackTrace();
         }
     }
1 comment
10 |600

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

BaharSaffarian avatar image BaharSaffarian commented ·

Hi Thanks for the answer, What you write is the same with my code. But I tried it any way and nothing has been changed. So the problem is not solved.

0 Likes 0 ·

Manage Your Content