• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Write api inserting/updating tags doesn't work

Scheduled Pinned Locked Moved NodeBB Development
write-apitagsjavascriptgoogle apps script
6 Posts 3 Posters 2.7k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Tilen ŠtrausT Offline
    Tilen ŠtrausT Offline
    Tilen Štraus
    wrote on last edited by Tilen Štraus
    #1

    Hi guys,

    so the thing is everything was working with the write api so far, topics,posts etc., but I can't insert/update a post to add tags into it. I'm trying to solve this problem all day because I thought it's an issue in my code at first but it seems that it's a bug.

    I've tried:

    • /topics POST inserting the cid,title,content,tags(and yes It's an array)(only the topic showed up with all the data except tags, with no error),

    • /topics PUT with pid,content and tags(again no error and no tags, the content was updated)

    • /posts PUT:pid with content,tags (again content was updated, still no tags,no errors)

    I'm on NodeBB version v1.1.2.

    Thanks in advance!

    1 Reply Last reply
    0
  • julianJ Offline
    julianJ Offline
    julian GNU/Linux
    wrote on last edited by
    #2

    @Tilen-Štraus Confirmed working, can you please post your cURL statement to debug?

    Perhaps you can compare with mine 😄

    curl localhost:4567/api/v1/topics -H "Authorizatin: Bearer my-token" -X POST --data "title=test%20api%20topic&content=test%20content&cid=1&tags[]=one%20tag&tags[]=two%20tags"

    1 Reply Last reply
    0
  • Tilen ŠtrausT Offline
    Tilen ŠtrausT Offline
    Tilen Štraus
    wrote on last edited by
    #3

    Thank you for the quick answer @julian!
    I've tried your curl code and it works fine. The problem was that i've been using the wrong property('tags' instead of 'tags[]'). Now i'm getting a new problem when inserting an array [LJAVA.LANG.OBJECT@695575B6. Does he expect something else instead of the array? Here is my code for better understanding:

    var sub_cat_id = "146"
    var t_title = "test title"
    var t_content = "TESTESTESTESTEST";
    var cars = new Array("Saab", "Volvo", "BMW");

    var headers = {"Authorization" : "Bearer XXX"};
    var url = 'XX/api/v1/topics/';
    var data = {'cid' : sub_cat_id,
    'title' : t_title,
    'content' : t_content,
    'tags[]' : cars
    };

    var options = {
    'method': 'post',
    'headers': headers,
    'payload': data
    };
    var response = UrlFetchApp.fetch(url, options);
    Logger.log(response);

    I just tried almost everything 😃 JSON.stringify-gives only one tag with all of the values in the array. I srsly don't know what to do 😞 .

    Thank you again.

    1 Reply Last reply
    0
  • D Offline
    D Offline
    dimkk
    wrote on last edited by
    #4

    Look at this js example:
    var settings = {
    "async": true,
    "crossDomain": true,
    "url": "http://./api/v1/topics/18/tags",
    "method": "POST",
    "headers": {
    "authorization": "Bearer ",
    "cache-control": "no-cache",
    "content-type": "application/x-www-form-urlencoded"
    },
    "data": {
    "tags[]": [
    "closed",
    "test"
    ]
    }
    }

    $.ajax(settings).done(function (response) {
    console.log(response);
    });

    2 things to consider:

    1. content-type
    2. tools to transform array to querystring - in my case jQuery will transform it to this - tags%5B%5D=closed&tags%5B%5D=test
    1 Reply Last reply
    0
  • Tilen ŠtrausT Offline
    Tilen ŠtrausT Offline
    Tilen Štraus
    wrote on last edited by
    #5

    Works now, i had to JSON.stringify()the data variable, set te contentType to "contentType" : "application/json" and 'tags[]' to 'tags'.

    Thank you all for helping 🙂

    julianJ 1 Reply Last reply
    0
  • julianJ Offline
    julianJ Offline
    julian GNU/Linux
    replied to Tilen Štraus on last edited by
    #6

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

    1 Reply Last reply
    1

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development