How to mock a 3rd party API call?

419 views
Skip to first unread message

Sachin Saikrishna

unread,
Nov 29, 2017, 7:22:28 AM11/29/17
to wiremock-user
I had a problem on how to mock a third party call. We use a 3rd party SDK which internally uses AWS Upload endpoint. I am not able to mock the call to the amazon AWS. How do we do that? I can post more details as someone replies.

Tom Akehurst

unread,
Nov 29, 2017, 4:04:30 PM11/29/17
to wiremock-user
Does the SDK have a configuration option to change the base URL of the API?

Alternatively, can you use it over HTTP, or does it have to be HTTPS? If HTTP is possible, then you can use WireMock as a forward proxy.

Sachin Saikrishna

unread,
Nov 30, 2017, 4:01:55 AM11/30/17
to wiremock-user
The SDK does not have a configuration option to change the base URL of the API. The base url is fetched from a call to another API which I was able to mock and send a sample URL, instead of the original AWS url. 

bynderService.stubFor(post(urlPathEqualTo("/api/upload/init/"))
.withHeader("Content-Type", equalTo("application/x-www-form-urlencoded"))
.withRequestBody(equalTo("filename=200w-1.gif"))
.willReturn(aResponse()
.withStatus(202)
.withHeader("Content-Type", "application/json")
.withBodyFile("bynder/mediaUploadInit.json")));
stubFor(post(urlMatching("http://bynder-sample-1.s3.amazonsampleaws.com/"))
.willReturn(aResponse().proxiedFrom("http://localhost:8090/api/v4/media/")));

Can you think this can work? This is how I am proxying. 

Tom Akehurst

unread,
Nov 30, 2017, 5:58:02 AM11/30/17
to wiremock-user
Ah, well if you're mocking the initial response that returns the base URL, then you can make that URL localhost:<port> based, right?

So you wouldn't need to do anything with proxying at all. You'd just create one stub for the initial call, return the URL relative to localhost and the port you're running on, then create a second stub that matches that URL.

Sachin Saikrishna

unread,
Nov 30, 2017, 8:36:05 AM11/30/17
to wiremock-user
Hey Tom,

Nice idea and this fixes the issue. I did the same. The request body somehow keeps changing and I have ignored it in the stubbing and this should work.
Reply all
Reply to author
Forward
0 new messages