I want to run a login endpoint to get Auth before I run any other endpoint, I currently use a script but I need to get a service URL to point to the right URL per environment. Is there a better way to do this or how can I get a specific service base URL?
Hi Waldeedle ,
Good day Yes, you’re absolutely right! Apidog’s Service Base URL feature is perfect for this scenario. Here’s how it can help:
Group Endpoints by Service:
You can group endpoints under a specific service in Apidog.
Each service can have its own base URL defined for different environments (e.g., Development, Testing, Production).
Dynamic Base URL Selection:
When making a request, Apidog automatically selects the base URL of the service corresponding to the current running environment.
This eliminates the need for hardcoding or manually switching base URLs.
How to Set It Up:
Navigate to the Services section in Apidog.
Define a new service and specify its base URLs for each environment.
Link your login endpoint (and any other relevant endpoints) to this service.
When you switch environments in Apidog, the correct base URL is applied automatically.
This approach ensures your login endpoint always points to the correct service base URL, simplifying your workflow and reducing the chance of errors.
Ref- Overview - Apidog Docs
Thanks for choosing Apidog!
but how can I reference a specific service in my custom pre processor script?
Hi Waldeedle , regarding your query I recommend you to read this atricle - Environments & services - Apidog Docs .
Tahnk you.
i did
its not written
Hi Waldeedle ,
There is another releven t reference -Environments & services - Apidog Docs
The link demonstrates that in a custom script, you can use pm.request.getBaseUrl() to dynamically fetch the base URL of the current endpoint’s service in Apidog. This method ensures the correct base URL is retrieved for the active environment, simplifying requests tied to specific services.
That’s the current endpoints baseurl
I want a separate services url
Waldeedle , To get the service URL in Apidog, you can use the pm.request.getBaseUrl() method in your custom script.
Sir that’s the current url
I want a different service
Waldeedle , Can you please declare the variable first within the environment? If you are using login.test.com, for every environment , you can declare it as a global variable and once you run it ( pm.request.getBaseUrl() ), will have it as service URL (as a base URL).