Hattabitos | Posts: 24

Update sender language and time zone

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

Duo_Liang | Posts: 3776

Reply to: Update sender language and time zone

0 votes
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");

Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off