https://linen.dev logo
#help
Title
# help
t

TheUsharik

06/20/2023, 9:34 AM
Hello! I'm looking into the way how can I import the prerecorded scenario with several requests into the running Wiremock instance with Admin REST API. I need to import the whole folder with multiple recorded mock JSON files but here I can se how I can do that only with Java API? https://docs.wiremock.io/import-export/wiremock/ Is there a way to do that with pure REST API?
t

Tom

06/20/2023, 9:56 AM
Hi @TheUsharik if you’d like to use WireMock Java to upload a folder to WireMock Cloud, you need to do something like:
Copy code
WireMock wm = WireMock.create()
                    .scheme("https")
                    .host("my-mock-api.wiremockapi.cloud")
                    .port(443)
                    .authenticator(new ClientTokenAuthenticator("<API token>"))
                    .build();

wm.loadMappingsFrom("/path/to/folder"); // Should be the parent folder of "mappings"
t

TheUsharik

06/20/2023, 10:36 AM
Thank you, but we are using Wiremock as a docker container and we need to change the path to the mapping folder on the run. Is that possible with admin REST API?
o

Oleg Nenashev

06/20/2023, 10:48 AM
WireMock Docker image loads the configuration files on startup. While you can definitely use the admin API to add more mappings, for me it seems to be going against the best practices. Normally it is advised to use a static image where all the configurations are bundled Why wouldn't you need to add it on the flight?
t

TheUsharik

06/20/2023, 11:12 AM
Because we have several scenaries and we need to switch between them.
t

Tom

06/20/2023, 11:56 AM
In this case I suggest pulling the single, all-stubs JSON from the API e.g.
GET http://<docker host>:<docker port>/__admin/mappings
then posting this to the WireMock Cloud import API endpoint, which is
/__admin/mocklab/imports