Error when Making HTTP POST Request from Motoko Canister to MongoDB Atlas Data API

Hello community,

I’m currently facing an issue while attempting to make an HTTP POST request from a Motoko canister to MongoDB Atlas using the Data API. It’s worth noting that when I perform the same HTTP POST request using Postman, it works perfectly fine. However, I encounter errors when making the request within my Motoko canister.

Here are the details of the errors I’m experiencing:

Local Environment Error:

Call was rejected:
Request ID: 30319254c0033871ef4cefbd0df07870cf8bb91388ef2c3d5199b14f68def3c2
Reject code: 4
Reject text: Connecting to ap-south-1.aws.data.mongodb-api.com failed: Request through socks proxy failed: error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known

Mainnet Deployment Error:

Call was rejected:
Request ID: 83c70d5e80c999f15a5bb635e5b62b214b401e8d29ee3d4676be3da1cbff0b36
Reject code: 4
Reject text: Connecting to ap-south-1.aws.data.mongodb-api.com failed: Request failed: error trying to connect: tcp connect error: Network is unreachable (os error 101)

I’m seeking assistance from the community to understand the root causes behind these errors and explore potential solutions. Given that the same request works in Postman.

Any insights or guidance on resolving this issue would be greatly appreciated. Thank you in advance for your help!

1 Like

Hey @ahdrahees ,
Http Outcalls only hit IPv6 addresses and looking into the error, it seems the request url you are trying to hit is IPv4, which is throwing error.

3 Likes

But mongoDB Atlas only support IPv4.
And my friend @7_ox_7 tried in windows locally and its working on the first call (http post request) after clearing cache and certificates. And when calling second time this function again throwing error. It only working once locally. Do you have suggestions or solutions?

If its IPv4, there is no way to directly outcall it from canister. One thing you can do is put a IPv6 proxy server in the middle.

1 Like