Firestore Creating a Document

Hello! I’m trying to store data in Firestore. I’ve gotten the script to create a document, but for some reason it can’t add fields to it.

I have tested using Postman to see the format needed for the POST.

It looks like this:
{ "name": "", "fields": { "as": { "stringValue": "asf" }, "aaa": { "stringValue": "aa" } }, "createTime": "2020-05-02T15:09:43.602950Z", "updateTime": "2020-05-02T15:09:43.602950Z" }
I have the following code:

local data = {
	fields = {
		['hi'] = {
			['stringValue'] = "yes"
		},
	}
}
local request = HttpService:PostAsync(database.."?documentId=test12", "", Enum.HttpContentType.ApplicationUrlEncoded, false, data)

But I get the following error: "Header "fields" must have its value be a string!"
If anyone can help, that would greatly be appreciated

This can help you: [Open Source] FirebaseService

Its make Firebase like DataStore and easy to operate.

Hi, I’ve seen that, but I’m trying to use Firestore, not the realtime database

Then your error message is the Headers

Example you can use: “X-HTTP-Method-Override”
But you also need to tell that Json

so dont froget this header: “content-type:application/json”

Hi, I’ve added in the content-type header, but I still get the same error

Pretty sure it means what it says, no? The current value of fields is a table and it’s expecting a string. Furthermore, if you’re using the ApplicationUrlEncoded HttpContentType, then you need to UrlEncode both the keys and values.

More information can be found by looking at PostAsync’s documentation page:

I don’t quite know much about roblox requests, how would I make the table be a string?

Ok so I switched the content type to ApplicationJSON, as well as tried to encode the data as a JSON, but then it gave an error saying headers value must be a dictionary!

1 Like

If you can help it would be nice