How to do API calls?

Hello together,

I am trying to do an API call to Github, how can something like this be achieved?
If someone could show me the right direction, that would be awesome.

Best,

Niklas

1 Like

You can’t make onchain calls to offchain entities.

Create a simple web-server that will pull the data you need from github and push it on chain (this things are called oracles).

Ahh ok, thanks, will something like this be supported in the future?

It just can’t be supported. It’s another kind of software.

Try to make a call to github from solidity smart-contract.

As a Cannister is implemented as a Wasm module, what prevents the IC runtime from making network functions available to the modules in the future and having these functions available in the Motoko base library? Presumably the runtime could track network usage for billing purposes.

Every canister state update should be deterministic (the same every time). It is needed because your code runs on multiple nodes and they all need to agree on some state, so they all need to calculate the exact same result.

When you making a call to an offchain service, you can’t be 100% sure (at least without some circuit proof) that the service does exactly what you want, so you violate the determinism.

1 Like

Ok, but theoretically the IC could allow for outbound API calls. Just retrieving the results from the API and processing it isn’t possible then. But doing an API call without expecting a result is not an update it’s just a query.

Just theoratically :slight_smile:

I created a small repository where there is an example on how to send an email (sendgrid) using a “Queue Canister”, a NodeJS worker (using redis) “oracle”, that fetch tasks periodically from a queue canister and then trigger some API calls.

Worker code is here: https://github.com/davidp94/icqs-demo/tree/master/worker

Queue Canister: https://github.com/davidp94/icqs-demo/blob/master/src/icqs_demo/main.mo

Example of your canister adding a task to the Queue Canister: https://github.com/davidp94/icqs-demo/blob/master/src/icqs_demo_developer_canister/main.mo

5 Likes