How to make an http call from an Atlas function?

Hello,

I cannot find any information anywhere on how to make an http call from within a MongoDB Atlas function. Here’s what I have tried so far:

  • node-fetch - fails installation, cannot add to the dependencies list.
  • axios - idem.
  • I found some vague mentions of MongoDB Atlas providing its own http library and I have tried the following to import it:
    const http = context.services.get("http");
    This has failed with an error: Error: Cannot access member 'get' of undefined

Nothing else comes to mind. So how to make an http request from a MongoDB Atlas function?

Hi @Vladimir,

The error is being returned because the context.services.get method is deprecated.

Does the following work for you instead : https://www.mongodb.com/docs/atlas/app-services/functions/context/#std-label-context-http

Regards,
Jason

2 Likes

Thank you very much Jason!

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.