1414import org .jetbrains .annotations .NotNull ;
1515
1616import com .contentstack .cms .core .AuthInterceptor ;
17+ import com .contentstack .cms .core .Endpoint ;
1718import com .contentstack .cms .core .Util ;
1819import static com .contentstack .cms .core .Util .API_KEY ;
1920import static com .contentstack .cms .core .Util .AUTHORIZATION ;
@@ -561,6 +562,81 @@ public CompletableFuture<Void> oauthLogout() {
561562 return oauthLogout (false );
562563 }
563564
565+ /**
566+ * Forces a live download of the Contentstack regions registry and replaces
567+ * the in-memory cache. Useful when new regions or service URLs have been
568+ * published since the SDK JAR was built.
569+ *
570+ * <pre>{@code
571+ * int count = Contentstack.refreshRegions();
572+ * // now getContentstackEndpoint() resolves from the freshly downloaded registry
573+ * }</pre>
574+ *
575+ * @return the number of regions loaded from the live registry
576+ * @throws RuntimeException if the download fails
577+ */
578+ public static int refreshRegions () {
579+ return Endpoint .refresh ();
580+ }
581+
582+ /**
583+ * Resolves a Contentstack service endpoint URL for the given region.
584+ *
585+ * <pre>{@code
586+ * // Full URL
587+ * String url = Contentstack.getContentstackEndpoint("eu", "contentManagement");
588+ * // → "https://eu-api.contentstack.com"
589+ *
590+ * // Host only (for Builder.setHost)
591+ * String host = Contentstack.getContentstackEndpoint("eu", "contentManagement", true);
592+ * // → "eu-api.contentstack.com"
593+ * }</pre>
594+ *
595+ * @param region region ID or alias (e.g. {@code na}, {@code eu}, {@code azure-na})
596+ * @param service service key (e.g. {@code contentManagement}, {@code contentDelivery})
597+ * @param omitHttps when {@code true}, strips {@code https://} from the returned URL
598+ * @return the resolved URL string
599+ * @throws IllegalArgumentException if region or service is unknown
600+ */
601+ public static String getContentstackEndpoint (String region , String service , boolean omitHttps ) {
602+ return Endpoint .getContentstackEndpoint (region , service , omitHttps );
603+ }
604+
605+ /**
606+ * Resolves a Contentstack service endpoint URL for the given region (with scheme).
607+ *
608+ * @param region region ID or alias
609+ * @param service service key
610+ * @return the resolved URL including {@code https://}
611+ * @throws IllegalArgumentException if region or service is unknown
612+ */
613+ public static String getContentstackEndpoint (String region , String service ) {
614+ return Endpoint .getContentstackEndpoint (region , service );
615+ }
616+
617+ /**
618+ * Returns all endpoint URLs for the given region as an ordered map.
619+ *
620+ * @param region region ID or alias
621+ * @return map of service name → URL (includes {@code https://})
622+ * @throws IllegalArgumentException if region is unknown or empty
623+ */
624+ public static java .util .Map <String , String > getContentstackEndpoints (String region ) {
625+ return Endpoint .getContentstackEndpoints (region );
626+ }
627+
628+ /**
629+ * Returns all endpoint URLs for the given region as an ordered map.
630+ *
631+ * @param region region ID or alias
632+ * @param omitHttps when {@code true}, strips {@code https://} from every URL
633+ * @return map of service name → URL
634+ * @throws IllegalArgumentException if region is unknown or empty
635+ */
636+ public static java .util .Map <String , String > getContentstackEndpoints (String region , boolean omitHttps ) {
637+ return Endpoint .getContentstackEndpoints (region , omitHttps );
638+ }
639+
564640 public Contentstack (Builder builder ) {
565641 this .host = builder .hostname ;
566642 this .port = builder .port ;
@@ -577,6 +653,16 @@ public Contentstack(Builder builder) {
577653 this .retryConfig = builder .retryConfig ;
578654 }
579655
656+ /** Returns the API hostname this client is configured to target. */
657+ public String getHost () {
658+ return host ;
659+ }
660+
661+ /** Returns the full Retrofit base URL (e.g. {@code https://eu-api.contentstack.com/v3/}). */
662+ public String getBaseUrl () {
663+ return instance .baseUrl ().toString ();
664+ }
665+
580666 public RetryConfig getRetryConfig () {
581667 return retryConfig ;
582668 }
@@ -665,6 +751,30 @@ public Builder setHost(@NotNull String hostname) {
665751 return this ;
666752 }
667753
754+ /**
755+ * Configures the client to target a specific Contentstack region by resolving
756+ * the correct Content Management API host from the bundled regions registry.
757+ *
758+ * <p>This is a convenience alternative to calling {@link #setHost(String)} with
759+ * a manually constructed hostname.
760+ *
761+ * <pre>{@code
762+ * Contentstack client = new Contentstack.Builder()
763+ * .setAuthtoken("authtoken")
764+ * .setRegion("eu")
765+ * .build();
766+ * }</pre>
767+ *
768+ * @param region region ID or alias (e.g. {@code "na"}, {@code "eu"}, {@code "azure-na"},
769+ * {@code "azure-eu"}, {@code "gcp-na"}, {@code "gcp-eu"}, {@code "au"}).
770+ * @return this Builder
771+ * @throws IllegalArgumentException if the region is unknown or empty
772+ */
773+ public Builder setRegion (@ NotNull String region ) {
774+ this .hostname = Endpoint .getContentstackEndpoint (region , "contentManagement" , true );
775+ return this ;
776+ }
777+
668778 /**
669779 * Set port for client instance
670780 *
0 commit comments