# Publiceren via Discourse API en Firebase (Cloud Functions)

**URL:** <https://meta.discourse.org/t/posting-via-discourse-api-and-firebase-cloud-functions/225823>\
**Category:** Product Support\
**Created:** [1 mei 2022 om 19:14 UTC](https://meta.discourse.org/t/posting-via-discourse-api-and-firebase-cloud-functions/225823 "2022-05-01T19:14:59Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![kirupa](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kirupa/32/374711_2.png) [@kirupa](https://meta.discourse.org/u/kirupa)\
**Post date:** [1 mei 2022 om 19:14 UTC](https://meta.discourse.org/t/posting-via-discourse-api-and-firebase-cloud-functions/225823/1 "2022-05-01T19:14:59Z")

</div>

Hi everyone!

I’m running into some weird issues that I don’t know how to make sense of. I’m using the Discourse API to allow someone to post without signing-in. For security reasons, this is code that I’ll be running in a server environment, and the environment I’m going with the is the Node.js based Cloud Functions for Firebase.

My full code looks as follows:

```plaintext
const functions = require("firebase-functions");
const fetch = require('node-fetch');
const cors = require("cors")({ origin: true });

exports.makeDiscoursePost = functions.https.onRequest((request, response) => {
  cors(request, response, () => {
    let myHeaders = new Headers();
    myHeaders.append("Api-Key", "<removed>");
    myHeaders.append("Api-Username", "system");
    myHeaders.append("Content-Type", 'application/json');

    let requestOptions = {
      method: 'POST',
      headers: myHeaders,
      redirect: 'follow'
    };

    fetch("https://forum.kirupa.com/posts.json?title=Testingggg Discourse API, Part 2&raw=Making a brand new post using the API and seeing if things still work.", requestOptions)
      .then(r => r.json())
      .then(result => response.send(result))
      .catch(error => response.send(error));
  });
});

```

I’m confident this code works, for when I run the fetch code in isolation a post gets made. It is when it gets run via the functions environment, I get an “Internal Server Error”. When I read the logs, I see “Finished with status: crash”

Does anybody have any thoughts on what may be wrong here? Has anybody managed to get post creation working via Firebase’s functions?

(cc @blake - I followed your Node.js approach via using the HTTP request method, and I got the same results!)

Thanks,  
Kirupa

---

_[View the full topic](https://meta.discourse.org/t/posting-via-discourse-api-and-firebase-cloud-functions/225823)._
