Moralis HTTPRequest Cloud function not storing data in Database

Hi Moralis Community,

I am reaching out looking for help with cloud functions.

With Cloud functions HTTP Request I am able to,

  1. Successfully call -> API and return results

I checked the logs, there are results showing up but not storing in the database. Has anyone else encountered this problem? Appreciate any help. Thank you very much.

Code below

Moralis.Cloud.define(“GetData”, async (request) => {
const logger = Moralis.Cloud.getLogger();
const userAddress = request.params.userAddress; + “This is user address in params”);“request details” + JSON.stringify(request));
const response = await Moralis.Cloud.httpRequest({
url: url,
Headers: {
‘content-type’: ‘application/json;charset=utf-8’
let results = await response.text;
return response;
const data = JSON.stringify(response);“this is response” + response);

const transactionsDetail = response.transactions;"This is transactions" + transactionsDetail);

  const Transaction = Moralis.Object.extend("TestTransaction");

transactionsDetail.forEach(async (transaction) => {
const transactionQuery = new Transaction();
const query = new Moralis.Query(transactionQuery);
const isData = await query.find();
if (isData.length === 0) {
await;“Data is saved”);
} else {“The transaction already exists.”);
return userAddress;
return data;
return transactionsDetail;

You can try to see if there are any exceptions or if it really makes it to the line where it tries to save to db. In cloud code you can also use master key if needed. It should work without problems to save in db from a cloud code function.

1 Like

I don’t see any exceptions in the logs.

The input is showing.

The results are showing in logs…

But the data is not in DB. Could you please let me know why masterkey is needed? Do you see any issues in the code above that could cause data to note store?

I think that you have to write some lines of code to log the exceptions. Master key is needed in some case where public write is not set for that particular table

1 Like

If I run the same function as a regular javascript function, its working. But when using the cloud function its not storing the data to the table.

In the logs i can see the data come through with successful response with 200. But the data isn’t storing on table.

Input: {“userAddress”:“user address here”}
Result: {“status”:200,“headers”:{“content-type”:“application/json; charset=utf-8”,“content-length”:“5857”,“connection”:“close”,“date”:“Wed, 23 Feb 2022 14:11:47 GMT”,“x-amzn-requestid”:“0afdfb32-0815-4b67-98aa-ca70610b7761”,“access-control-allow-origin”:"*",“access-control-allow-headers”:“Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With”,“x-amz-apigw-id”:“N_8JnFVAIAMFWIA=”,“access-control-allow-methods”:“GET,HEAD,PUT,PATCH,POST,DELETE”,“x-amzn-remapped-date”:“Wed, 23 Feb 2022 14:11:47 GMT”,“access-control-allow-credentials”:“true”,“x-cache”:“Miss from cloudfront”,“via”:“1.1 (CloudFront)”,“x-amz-cf-pop”:“EWR53-C3”,“x-amz-cf-id”:“G5B0yOGW_1xgW56hArHG0vwfZ5RoMzDg15gPMJSKXelwkRPzrqsfGw==”},“buffer”:{“type”:“Buffer”,“data”:[]},“text”:"{“page”:1,“total_pages”:1,“items_on_page”:25,“total_txs”:8,“transactions”:[{“id”:"0x55b30c32a43a30a80b42fe528b7994e9677649f51c13da36… (truncated)

this is the part that doesn’t work?

I think so. .save command was supposed to save data to instantiated data class isn’t? I don’t see issues in the code cause the response is coming through but not storing though.

I am a bit puzzled for almost a week trying to figure this out. I Appreciate any help on how to resolve this.

you could do simple tests to try to save, add more logging, I don’t see why it would not work

what puzzles me here is, when i use this as a regular javascript function, it works.

when using moralis cloud function its not saving to database.

do you have a simple example that doesn’t save from cloud code?

to be sure that is the problem and not something else