{"id":1212,"date":"2023-01-19T09:32:16","date_gmt":"2023-01-19T09:32:16","guid":{"rendered":"https:\/\/infobip.com\/developers\/?p=1212"},"modified":"2023-09-11T14:32:11","modified_gmt":"2023-09-11T14:32:11","slug":"send-sms-over-a-query-parameter-with-java","status":"publish","type":"post","link":"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java","title":{"rendered":"Send SMS over a query parameter with Java"},"content":{"rendered":"\n<p>This blog post will walk you through the steps to send an SMS over query parameters (over GET method) using Infobip SMS API and Java as the chosen programming language.<\/p>\n\n\n\n<p>So why would we use a GET query method instead of a typical way of sending an SMS using a POST Send SMS call?<\/p>\n\n\n\n<p>There are at least a couple of reasons: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You want to form a query string dynamically (on a set of conditions) instead of declaring each parameter separately without forming a more complicated JSON body.<\/li>\n\n\n\n<li>GET assumes a different authorization approach (login\/pass), which could be preferable to POST (should have IBSSOToken or APIKey or Basic or OAuth2).<\/li>\n\n\n\n<li>GET call is simpler in comparison to POST.<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"Prerequisites\">Prerequisites<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.infobip.com\/signup\">Infobip Account<\/a> with SMS credits<\/li>\n\n\n\n<li>Java 8+<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"Import-okhttp3-dependency\">Import okhttp3 dependency<\/h1>\n\n\n\n<p>okhttp3 is a HTTP client with straight-forward semantic that allows to do HTTP calls to Infobip API without additional complications.<\/p>\n\n\n\n<p>We&#8217;ve included maven and gradle samples for you to choose from depending on which build automation tool you used in your project.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">maven<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-java\" data-lang=\"Java\"><code>&lt;dependency&gt;\n    &lt;groupId&gt;com.squareup.okhttp3&lt;\/groupId&gt;\n    &lt;artifactId&gt;okhttp&lt;\/artifactId&gt;\n    &lt;version&gt;4.10.0&lt;\/version&gt;\n&lt;\/dependency&gt;<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">gradle<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-java\" data-lang=\"Java\"><code>implementation &quot;com.squareup.okhttp3:okhttp:4.10.0&quot;<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"Copy-an-example\">Copy an example<\/h1>\n\n\n\n<p>This program downloads a URL and returns a response object to process. Just replace necessary placeholders.<\/p>\n\n\n\n<p>Please note that <code>username<\/code>, <code>password<\/code>, and <code>to<\/code>  are required parameters.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-java\" data-lang=\"Java\"><code>OkHttpClient client = new OkHttpClient().newBuilder().build();\nRequest request = new Request.Builder()\n    .url(&quot;https:\/\/89.api.infobip.com\/sms\/1\/text\/query?username=&lt;LOGIN&gt;&password=&lt;PASS&gt;&from=&lt;SENDER_NAME&gt;&to=&lt;MOBILE_NUMBER&gt;&text=&lt;YOUR_MESSAGE&gt;&quot;)\n    .method(&quot;GET&quot;, null)\n    .addHeader(&quot;Accept&quot;, &quot;application\/json&quot;)\n    .build();\nResponse response = client.newCall(request).execute();<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"Expected-outcome\">Possible failure messages<\/h1>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-json\" data-lang=\"JSON\"><code>401: {&quot;requestError&quot;:{&quot;serviceException&quot;:{&quot;messageId&quot;:&quot;UNAUTHORIZED&quot;,&quot;text&quot;:&quot;Invalid login details&quot;}}}  \u2190 invalid login\/pass or user unauthorized to execute remote API\n200: {&quot;messages&quot;:[{&quot;to&quot;:&quot;&lt;MOBILE_NUMBER&gt;&quot;,&quot;status&quot;:{&quot;groupId&quot;:5,&quot;groupName&quot;:&quot;REJECTED&quot;,&quot;id&quot;:19,&quot;name&quot;:&quot;REJECTED_ROUTE_NOT_AVAILABLE&quot;,&quot;description&quot;:&quot;Route not available&quot;,&quot;action&quot;:&quot;Contact account manager&quot;},&quot;messageId&quot;:&quot;36635455539401630909&quot;,&quot;smsCount&quot;:1}]}  \u2190 no SMS credits on your Infobip account\n200: {&quot;messages&quot;:[{&quot;to&quot;:&quot;&lt;OTHER_MOBILE_NUMBER&gt;&quot;,&quot;status&quot;:{&quot;groupId&quot;:5,&quot;groupName&quot;:&quot;REJECTED&quot;,&quot;id&quot;:18,&quot;name&quot;:&quot;REJECTED_DESTINATION_NOT_REGISTERED&quot;,&quot;description&quot;:&quot;Destination not registered&quot;},&quot;messageId&quot;:&quot;36635482970837212230&quot;,&quot;smsCount&quot;:1}]}  \u2190 mobile phone is in rejected destination\/area.<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"Additional-examples\">Additional examples<\/h1>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-java\" data-lang=\"Java\"><code>String run(String url) throws IOException {\n  Request request = new Request.Builder()\n      .url(url)\n      .build();\n \n  try (Response response = client.newCall(request).execute()) {\n    return response.body().string();\n  }\n}<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This blog post will walk you through the steps [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_import_markdown_pro_load_document_selector":11,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[28,255],"tags":[43,46,62],"coauthors":[132],"class_list":["post-1212","post","type-post","status-publish","format-standard","hentry","category-blog-post","category-infobip-products","tag-api","tag-developer-docs","tag-tutorial"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Send SMS over a query parameter with Java - Infobip Developers Hub<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Send SMS over a query parameter with Java - Infobip Developers Hub\" \/>\n<meta property=\"og:description\" content=\"This blog post will walk you through the steps [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java\" \/>\n<meta property=\"og:site_name\" content=\"Infobip Developers Hub\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/infobip\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-19T09:32:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-11T14:32:11+00:00\" \/>\n<meta name=\"author\" content=\"Igor Demin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InfobipDev\" \/>\n<meta name=\"twitter:site\" content=\"@InfobipDev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Igor Demin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java\"},\"author\":{\"name\":\"Igor Demin\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/195e5d77b9ea7aadfdc909574dd64d5d\"},\"headline\":\"Send SMS over a query parameter with Java\",\"datePublished\":\"2023-01-19T09:32:16+00:00\",\"dateModified\":\"2023-09-11T14:32:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java\"},\"wordCount\":212,\"publisher\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/#organization\"},\"keywords\":[\"API\",\"developer docs\",\"tutorial\"],\"articleSection\":[\"Blog Post\",\"Infobip Products\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java\",\"url\":\"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java\",\"name\":\"Send SMS over a query parameter with Java - Infobip Developers Hub\",\"isPartOf\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/#website\"},\"datePublished\":\"2023-01-19T09:32:16+00:00\",\"dateModified\":\"2023-09-11T14:32:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.infobip.com\/developers\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Send SMS over a query parameter with Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#website\",\"url\":\"https:\/\/www.infobip.com\/developers\/\",\"name\":\"Infobip Developers Hub\",\"description\":\"Build meaningful customer relationships across any channel\",\"publisher\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.infobip.com\/developers\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#organization\",\"name\":\"Infobip Developers Hub\",\"url\":\"https:\/\/www.infobip.com\/developers\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2023\/03\/Infobip_logo_favicon.png\",\"contentUrl\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2023\/03\/Infobip_logo_favicon.png\",\"width\":696,\"height\":696,\"caption\":\"Infobip Developers Hub\"},\"image\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/infobip\/\",\"https:\/\/x.com\/InfobipDev\",\"https:\/\/www.youtube.com\/channel\/UCUPSTy53VecI5GIir3J3ZbQ\",\"https:\/\/github.com\/infobip-community\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/195e5d77b9ea7aadfdc909574dd64d5d\",\"name\":\"Igor Demin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/image\/ee6dd81f823409e8bc6cd76d75d5ba4c\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/41b4828619215311722ab10b4b38943455cf2afb6a1032767c4f9be6e44dd151?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/41b4828619215311722ab10b4b38943455cf2afb6a1032767c4f9be6e44dd151?s=96&d=mm&r=g\",\"caption\":\"Igor Demin\"},\"description\":\"Igor is a senior humble Engineer at Infobip, working in the Platform BA team.\",\"url\":\"https:\/\/www.infobip.com\/developers\/blog\/author\/igor-demin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Send SMS over a query parameter with Java - Infobip Developers Hub","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java","og_locale":"en_US","og_type":"article","og_title":"Send SMS over a query parameter with Java - Infobip Developers Hub","og_description":"This blog post will walk you through the steps [&hellip;]","og_url":"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java","og_site_name":"Infobip Developers Hub","article_publisher":"https:\/\/www.facebook.com\/infobip\/","article_published_time":"2023-01-19T09:32:16+00:00","article_modified_time":"2023-09-11T14:32:11+00:00","author":"Igor Demin","twitter_card":"summary_large_image","twitter_creator":"@InfobipDev","twitter_site":"@InfobipDev","twitter_misc":{"Written by":"Igor Demin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java#article","isPartOf":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java"},"author":{"name":"Igor Demin","@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/195e5d77b9ea7aadfdc909574dd64d5d"},"headline":"Send SMS over a query parameter with Java","datePublished":"2023-01-19T09:32:16+00:00","dateModified":"2023-09-11T14:32:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java"},"wordCount":212,"publisher":{"@id":"https:\/\/www.infobip.com\/developers\/#organization"},"keywords":["API","developer docs","tutorial"],"articleSection":["Blog Post","Infobip Products"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java","url":"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java","name":"Send SMS over a query parameter with Java - Infobip Developers Hub","isPartOf":{"@id":"https:\/\/www.infobip.com\/developers\/#website"},"datePublished":"2023-01-19T09:32:16+00:00","dateModified":"2023-09-11T14:32:11+00:00","breadcrumb":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.infobip.com\/developers\/blog\/send-sms-over-a-query-parameter-with-java#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.infobip.com\/developers\/"},{"@type":"ListItem","position":2,"name":"Send SMS over a query parameter with Java"}]},{"@type":"WebSite","@id":"https:\/\/www.infobip.com\/developers\/#website","url":"https:\/\/www.infobip.com\/developers\/","name":"Infobip Developers Hub","description":"Build meaningful customer relationships across any channel","publisher":{"@id":"https:\/\/www.infobip.com\/developers\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.infobip.com\/developers\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.infobip.com\/developers\/#organization","name":"Infobip Developers Hub","url":"https:\/\/www.infobip.com\/developers\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/logo\/image\/","url":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2023\/03\/Infobip_logo_favicon.png","contentUrl":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2023\/03\/Infobip_logo_favicon.png","width":696,"height":696,"caption":"Infobip Developers Hub"},"image":{"@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/infobip\/","https:\/\/x.com\/InfobipDev","https:\/\/www.youtube.com\/channel\/UCUPSTy53VecI5GIir3J3ZbQ","https:\/\/github.com\/infobip-community"]},{"@type":"Person","@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/195e5d77b9ea7aadfdc909574dd64d5d","name":"Igor Demin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/image\/ee6dd81f823409e8bc6cd76d75d5ba4c","url":"https:\/\/secure.gravatar.com\/avatar\/41b4828619215311722ab10b4b38943455cf2afb6a1032767c4f9be6e44dd151?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/41b4828619215311722ab10b4b38943455cf2afb6a1032767c4f9be6e44dd151?s=96&d=mm&r=g","caption":"Igor Demin"},"description":"Igor is a senior humble Engineer at Infobip, working in the Platform BA team.","url":"https:\/\/www.infobip.com\/developers\/blog\/author\/igor-demin"}]}},"_links":{"self":[{"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/posts\/1212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/comments?post=1212"}],"version-history":[{"count":13,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/posts\/1212\/revisions"}],"predecessor-version":[{"id":2123,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/posts\/1212\/revisions\/2123"}],"wp:attachment":[{"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/media?parent=1212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/categories?post=1212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/tags?post=1212"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/coauthors?post=1212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}