@Jeremy-Snyder It may be helpful to see how we do it in our testing suite 🙊
Cannot write data using write-api
Hi, I have some data (username/topic.etc.) and I want to put these into forum using write-api.
curl -H "Authorization: Bearer token here"
--data "username=helloa&password=accccc&[email protected]" http://myhost:4567/api/v1/users
It works and others like topic,post,category also works.
2, Because my data is in excel, so I want use VBA to do this.
I tried two different function in excel VBA and it comes out same error.
Below are VBA code and error.
It seems that the server dosen't get the data.
I am so confused....Can you point out me my error.
@riddle911 I'm not sure if those are GET or POST endpoints but you're definitely mixing a POST request with a GET body there.
I made a mistake that forgot the Header.
XMLHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
@riddle911 Thanks for following up! Others will be happy you came back to offer the solution
I'm not professional in coding. Now I have successfully generated my users on nodebb from the EXCEL data. Guys you may think it is so easy and can be done by serval codes，but it's quite hard for me to understand the http protocols and programing think.
And now thank you I can do it myself.
Here is the code of generating new users on EXCEL VBA. Hope it can help people like me. ; )
Sub newusername() Dim i As Integer Dim data, user, pass, mail As String Dim XMLHTTP As New MSXML2.XMLHTTP, myurl As String myurl = "http://yourhost/api/v1/users/" For i = 6 To 8 user = "username=" & Cells(i, 1) pass = "&password=" & Cells(i, 2) mail = "&email=" & Cells(i, 4) data = user + pass + mail XMLHTTP.Open "POST", myurl, False XMLHTTP.setRequestHeader "Authorization", "Bearer yourtoken" XMLHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded" XMLHTTP.Send data Debug.Print (XMLHTTP.responseText) Next End Sub
Here I set
ias the row, and I put username, password and email in column A,B,and D.
Thank you again!
@riddle911 nice job. I may good at programming but I'm definitely not an expert in Excel. Nice work, and thanks for sharing.