This topic contains 1 reply, has 2 voices, and was last updated by  Duo_Liang 2 months, 2 weeks ago.

  • Author
    Posts
  • Participant
    Hattabitos
    Newbie
    Member since: 18.12.2015
    Number of posts: 19

    Can you please provide us a code on how to update sender language and the timezone of the sender account

    Keymaster
    Duo_Liang
    Guru
    Member since: 14.06.2018
    Number of posts: 688

    Score

    0

    Hi there,

    For temporarily, timezone Id can be updated through Java SDK but not language, since these two settings are often be changed, you can use Rest API method instead.
    Below is the sample code I created for you:

    private void updateSenderLanguageAndTimezone(String api_url, String api_key, String senderId, String language,
    			String timezoneId) throws IOException {
    		URL sourceClient = new URL(api_url + "/account/senders/" + senderId);
    		HttpURLConnection sourceConn = (HttpURLConnection) sourceClient.openConnection();
    		sourceConn.setRequestProperty("Content-Type", "application/json; esl-api-version=11.21");
    		sourceConn.setRequestProperty("Accept", "application/json; esl-api-version=11.21");
    		sourceConn.setRequestProperty("Authorization", "Basic " + api_key);
    		sourceConn.setRequestMethod("POST");
    		sourceConn.setDoOutput(true);
    		sourceConn.setDoInput(true);
    
    		String payloadJSON = "{ \"language\": \"" + language + "\",\"timezoneId\": \"" + timezoneId + "\"}";
    		System.out.println(payloadJSON);
    		OutputStream os = sourceConn.getOutputStream();
    		os.write(payloadJSON.toString().getBytes());
    		os.flush();
    		os.close();
    
    		int sourceResponseCode = ((HttpURLConnection) sourceConn).getResponseCode();
    		if (sourceResponseCode != 200) {
    			Reader ir = new InputStreamReader(sourceConn.getErrorStream());
    			BufferedReader in = new BufferedReader(ir);
    			String inputLine;
    			StringBuffer response = new StringBuffer();
    
    			while ((inputLine = in.readLine()) != null) {
    				response.append(inputLine);
    			}
    
    			in.close();
    			sourceConn.disconnect();
    			throw new RuntimeException(response.toString());
    		}
    
    	}
    
    Sample Usage:
    updateSenderLanguageAndTimezone("API_URL", "API_KEY", "sender_id", "fr", "GMT");

    Duo Liang
    OneSpan Junior Technical Evangelist
    • This reply was modified 2 months, 2 weeks ago by  Duo_Liang.

You must be logged in to reply to this topic.