Skip to content
  • 0 Votes
    5 Posts
    404 Views
    julianJ

    Please see this topic 😄

  • 1 Votes
    6 Posts
    691 Views
    K

    @julian that's awesome thanks a lot!

  • 0 Votes
    1 Posts
    244 Views
    K

    Hi all,

    I'm trying to use the recently introduced WriteAPI to create topics and concurrently upload a file.
    I'm doing it via Python and I've already succeeded in create a simple topic without a file using something lilke

    payload = { "cid": cid, "title": title, "content": message } headers = { 'Authorization': 'Bearer '+nodebbToken, 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=json.dumps(payload))

    but when it's about files using

    payload = { "cid": backstage_cid, "title": backstage_title, "content": backstage_message } headers = { 'Authorization': 'Bearer '+nodebbToken, 'Content-Type': 'multipart/form-data' } verifySSL = False print (payload) if (useFile): with open(backstage_file, 'rb') as f: response = requests.request("POST", url, headers=headers, data=payload, verify=verifySSL, files={backstage_file: f})

    it returns
    Error: Required parameters were missing from this API call: cid, title, content cause passing the parameters in a plain dictionary rather than a JSON object seems not doable.

    The switch from JSON to dictionary is needed otherwise I wouldn't have been able to pass a file together with such header

    headers = { 'Authorization': 'Bearer '+nodebbToken, 'Content-Type': 'multipart/form-data' }

    Has anybody valuable suggestions here?

    Thanks in advance, Riccardo

  • 0 Votes
    1 Posts
    396 Views
    dogsD

    Hey!

    Is it possible to post as Guest via the write API?

    I tried to reply to a topic via:

    const bodyParameters = { _uid: 0, content: "It works!" };

    But it does not work. Is it possible to post as a Guest and set a username with the request or is it only possible to use the write api with a existing uid?

    Looking forward to your answers.

  • 0 Votes
    7 Posts
    4k Views
    G

    To anyone searching the same thing, I resolved the problem using the custom write-api hooks, I wasn't aware of:

    Link Preview Image nodebb-plugin-write-api/routes/v1/index.js at master · NodeBB/nodebb-plugin-write-api

    A RESTful JSON-speaking API allowing you to write things to NodeBB - nodebb-plugin-write-api/routes/v1/index.js at master · NodeBB/nodebb-plugin-write-api

    favicon

    GitHub (github.com)

    filter:plugin.write-api.routes

    that gives you data, I used it in this way:

    function(data, callback) { var app = data.router; var apiMiddleware = data.apiMiddleware; var middleware = data.middleware; var errorHandler = data.errorHandler; app.post('/route', apiMiddleware.requireUser, function(req, res) { // do stuff }); callback(null, { router: app }); };

    Obviously you should have nodebb-plugin-write-api installed.

  • 0 Votes
    3 Posts
    2k Views
    E

    Bad gateway might occur due to an incorrect setting in your Proxy.

    It is recommended by me to use Nginx as it is easy to setup and apparently automatically recovers after a bad gateway.

    What Operating System Are you using?

  • 0 Votes
    6 Posts
    3k Views
    julianJ

    @Tilen-Štraus Glad you got it working, and thank you for sharing your solution for others who may run into the same trouble 😄

  • 0 Votes
    14 Posts
    7k Views
    Tanguy Bodin-HullinT

    Thank you.
    I did disable the option in the API-write module, and now it's working in a shell terminal when I send the above CURL command.
    But when I try to use CURL in HTTPS within my PHP program,
    I get this message (401) : A valid login session was not found. Please log in and try again.
    I don't understand why I get this message, because :

    I'm sending the Master token in the Header by calling the PHP function curl_setopt with the option CURLOPT_HTTPHEADER I try to send the credentials (login/password) by calling the PHP function curl_setopt with the option CURLOPT_USERPWD and login/password.
  • 0 Votes
    11 Posts
    4k Views
    Coman CosminC

    @pitaj said:

    npm install

    It works now. Thanks a lot for your help. Would have never figured out by myself:)

    Awesome idea with this API btw, i almost gave up because i'm not familiar with nodejs, but when i found this plugin i realised that this is no longer an issue:)

    Great work guys

  • 0 Votes
    5 Posts
    3k Views
    M

    Jonny
    Don't ever apologies for providing advice, that after all is why we are all here 👍 and the great thing about advice is that the user can choose what to do with it. In this case I shall be applying it to the letter.

    D

  • 3 Votes
    23 Posts
    14k Views
    zaasmiZ

    @baris Please help
    nothing happened after save changes again at same screen.

    3e9f330e-3679-4261-a0ff-e37362fb5134-image.png