"Invalid credentials" when posting a status to a Pleroma instance #1423
|
I am switching from another JS library for the mastodon api called Tusk. Is Masto,js incompatible with Pleroma completely? For what it's worth, I found this documentation explaining some differences between the mastodon and pleroma apis And this is anecdotal, but to get the Tusk library to work for me on a pleroma instance, I had to set a parameter to force tusk to send a multipart form request instead of a url query, in order to post a status. That leads me to believe the http method may be different for pleroma vs mastodon. Thanks for any help or guidance. |
Replies: 4 comments
|
OK I think I found that "create" actions are always POSTed https://github.com/neet/masto.js/blob/main/src/adapters/action/dispatcher-http.ts So if POST is the required method for Pleroma to create a status, then that must not be the problem. I'll see if I can apply a custom header to set "Content-type" = "multipart/form-data" in my request, and see if that fixes it like it did with the Tusk lib. |
|
Setting multipart/form-data header in my request didn't work. Neither did setting encoding to multipart-form Here are headers from a response I'm getting when I get the error Here's what my code looks like: const masto = createRestAPIClient({
url: instance_url,
access_token: access_token,
timeout: 60*1000, // optional HTTP request timeout in milliseconds to apply to all requests.
})
function post() {
const statusParams = {
status: "test 1",
visibility: "direct"
}
const httpParams = {
encoding : "multipart-form",
requestInit: {
headers: new Headers({ "content-type" : "multipart/form-data" }),
}
}
masto.v1.statuses.create(statusParams, httpParams) //.$raw // raw isn't working for me
.then( function (promiseObject) { ... }I tried passing the httpParams with either the requestInit headers for "multipart/form-data" alone, or just the encoding : "multipart-form", or both together, none of those combinations helped. |
|
here's how I can curl my Pleroma instance # using form data
curl -X POST -H "Authorization: Bearer $myToken" \
-F 'status=test1' \
-F 'visibility=direct' \
https://myPleromaSever.com/api/v1/statuses
# or json
curl -X POST -H "Authorization: Bearer $myToken" \
-H 'Content-Type: application/json' \
-d '{"status" : "test1", "visibility" : "direct"}'
https://myPleromaSever.com/api/v1/statusesI just tested both and they work on my Pleroma server using my auth token. |
|
ok I went down a rabbit hole on setting the multipart/form-data header, but it doesn't make a difference. Plus, I found out that no matter what custom data I put in a HttpMetaParams object, the encoding gets overwritten to application/json by dispatcher-http-hook-mastodon.inferEncoding if the request is "create." But I know my real problem is "Invalid Credentials." So I cheated and modified your source to add my auth token into the request headers... and it worked! Then I tested inserting my token into a custom auth header passed through a HttpMetaParams object, and that worked too. While debugging, I found your function that merges custom headers into the request. And that is where I think I found the problem. So it was user error all along! (๑•́ω•̀๑) |
ok I went down a rabbit hole on setting the multipart/form-data header, but it doesn't make a difference. Plus, I found out that no matter what custom data I put in a HttpMetaParams object, the encoding gets overwritten to application/json by dispatcher-http-hook-mastodon.inferEncoding if the request is "create."
But I know my real problem is "Invalid Credentials." So I cheated and modified your source to add my auth token into the request headers... and it worked!
Then I tested inserting my token into a custom auth header passed through a HttpMetaParams object, and that worked too.
While debugging, I found your function that merges custom headers into the request. And that is where I thi…