wekan / wekan

The Open Source kanban (built with Meteor). Keep variable/table/field names camelCase. For translations, only add Pull Request changes to wekan/i18n/en.i18n.json , other translations are done at https://app.transifex.com/wekan/wekan only.
https://wekan.github.io
MIT License
19.6k stars 2.83k forks source link

Problem on curl POST #2014

Closed arradoq closed 4 years ago

arradoq commented 5 years ago

Issue

Add these issues to elsewhere:

Other Wekan issues can be added here.

Server Setup Information:

Problem description:

Currently trying to post using curl, but on the respons does not indicate if i fail or what, and it confuses me, if anyone has been able to use it, i am very pleased to be directed to the right path. Thank you

$ curl -H "Authorization:Bearer x4nrTtezXgUmcgTDxQI49qdy1h3DPrbF6gNhUTfHyi9" -H "Content-type:application/json" -X POST http://localhost:3000/api/boards/RbzK3mgHKj4KfzSPF/lists/EHve7KjQfySsb9ZzA/cards -d '{ "title": "card new title", "description": "hello world", "authorId" : "8jxXS6piXhrL8fMYa" }'

Response: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 93 0 0 100 93 0 297 --:--:-- --:--:-- --:--:-- 297

xet7 commented 5 years ago

Did you login first to Standalone Wekan (Snap/Docker/Source) with user that has Admin Panel rights, to get valid Bearer string like that x4... ? https://github.com/wekan/wekan/wiki/REST-API#example-call---as-form-data

And after that, did you use REST API (or saved exported Wekan JSON) to get correct board ID and list ID ?

arradoq commented 5 years ago

Well, i got the token after login first as noted on the link, and I double check that boardId and list id using robo 3T and script viewer from browser, so, can you please give me some insight on this problem ?

arradoq commented 5 years ago

Error: invalid json<br> &nbsp; &nbsp;at parse (C:\Users\Username\AppData\Local\.meteor\packages\simple_json-routes\2.1.0\npm\node_modules\connect\node_modules\body-parser\lib\types\json.js:83:15)<br> &nbsp; &nbsp;at C:\Users\Qodar\AppData\Local\.meteor\packages\simple_json-routes\2.1.0\npm\node_modules\connect\node_modules\body-parser\lib\read.js:108:18<br> &nbsp; &nbsp;at invokeCallback (C:\Users\Qodar\AppData\Local\.meteor\packages\simple_json-routes\2.1.0\npm\node_modules\connect\node_modules\body-parser\node_modules\raw-body\index.js:262:16)<br> &nbsp; &nbsp;at done (C:\Users\Qodar\AppData\Local\.meteor\packages\simple_json-routes\2.1.0\npm\node_modules\connect\node_modules\body-parser\node_modules\raw-body\index.js:251:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (C:\Users\Qodar\AppData\Local\.meteor\packages\simple_json-routes\2.1.0\npm\node_modules\connect\node_modules\body-parser\node_modules\raw-body\index.js:308:7)<br> &nbsp; &nbsp;at emitNone (events.js:106:13)<br> &nbsp; &nbsp;at IncomingMessage.emit (events.js:208:7)<br> &nbsp; &nbsp;at endReadableNT (_stream_readable.js:1056:12)<br> &nbsp; &nbsp;at _combinedTickCallback (internal/process/next_tick.js:138:11)<br> &nbsp; &nbsp;at process._tickDomainCallback (internal/process/next_tick.js:218:9)

Updated, the first post is when I try to input using git bash, this one comes when I try using cmd to curl. I hope someone somewhere can help with this problem, or should I try to update meteor to solve this?

arradoq commented 5 years ago

@xet7 I am curious, have you try curl-ing from wekan windows version? My goal is to make excel VBA - Wekan connection here, perhaps you could give me some insight in this idea

xet7 commented 5 years ago

@arradoq

I would think in that case you could try using VBA-Web at: https://github.com/wekan/wekan/wiki/Excel-and-VBA

I have not tried that in Excel, I don't have Excel installed currently.

At https://github.com/wekan/wekan is .bat files that also install curl, but I have not used curl to access Wekan on Windows yet.

xet7 commented 5 years ago

For more complete example of accessing Wekan API, you could look at https://github.com/wekan/wekan-gogs .

arradoq commented 5 years ago

Update on error status when trying to send from cmd

Error: invalid json<br> &nbsp; &nbsp;at parse (C:\Users\<UserName>\AppData\Local\.meteor\packages\simple_json-routes\2.1.0\npm\node_modules\connect\node_modules\body-parser\lib\types\json.js:83:15)<br> &nbsp; &nbsp;at C:\Users\<UserName>\AppData\Local\.meteor\packages\simple_json-routes\2.1.0\npm\node_modules\connect\node_modules\body-parser\lib\read.js:108:18<br> &nbsp; &nbsp;at invokeCallback (C:\Users\<UserName>\AppData\Local\.meteor\packages\simple_json-routes\2.1.0\npm\node_modules\connect\node_modules\body-parser\node_modules\raw-body\index.js:262:16)<br> &nbsp; &nbsp;at done (C:\Users\<UserName>\AppData\Local\.meteor\packages\simple_json-routes\2.1.0\npm\node_modules\connect\node_modules\body-parser\node_modules\raw-body\index.js:251:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (C:\Users\<UserName>\AppData\Local\.meteor\packages\simple_json-routes\2.1.0\npm\node_modules\connect\node_modules\body-parser\node_modules\raw-body\index.js:308:7)<br> &nbsp; &nbsp;at emitNone (events.js:106:13)<br> &nbsp; &nbsp;at IncomingMessage.emit (events.js:208:7)<br> &nbsp; &nbsp;at endReadableNT (_stream_readable.js:1056:12)<br> &nbsp; &nbsp;at _combinedTickCallback (internal/process/next_tick.js:138:11)<br> &nbsp; &nbsp;at process._tickDomainCallback (internal/process/next_tick.js:218:9)

arradoq commented 5 years ago

Dear @xet7 for now, I have already move on by using ubuntu bash on windows 10 which works pretty well and also use less memory rather than using docker or VM-ing. But the problem on curl POST still persist. Does it need specific way to enable this? Hope this year, wekan goes better than before

xet7 commented 5 years ago

@arradoq

Is there same problem with using curl on ubuntu bash? I'm trying to read this issue and figure out what is the actual problem.

xet7 commented 5 years ago

@arradoq

What version of Excel are you trying to use with Wekan?

arradoq commented 5 years ago

Currently I use excel 2016. When using curl on ubuntu, is there any necessary path i must take besides getting token?

xet7 commented 5 years ago

@arradoq

First you login with username and password as Form Data: https://github.com/wekan/wekan/wiki/REST-API#example-call---as-form-data

The you change that token to examples to the right side of word "Bearer" in next API calls, so you get list of users, list of boards user has, etc. These calls after login use JSON in queries.

xet7 commented 5 years ago

@arradoq

Did you look at links at this page, using REST API directly with VBA? Did you try it? https://github.com/wekan/wekan/wiki/Excel-and-VBA

arradoq commented 5 years ago

Yes, still no response.content from vba webresponse

arradoq commented 5 years ago

Or could you share some succesfull line ?

arradoq commented 5 years ago

outputvba

Above show my output when I try to post new cards via VBA

xet7 commented 5 years ago

You need to login first with username and password of admin user as form data to get bearer token that you use at next api calls in right side of Bearer word https://github.com/wekan/wekan/wiki/REST-API#example-call---as-form-data

xet7 commented 5 years ago

There are some generated API docs at temporary address: https://github.com/wekan/wekan/pull/1965#issuecomment-455606651

In general, after login as form data, with bearer token you get list of users, board of user, etc

xet7 commented 5 years ago

And after login as form data other API calls are as JSON data (not form data)

xet7 commented 5 years ago

If you get normal html as response then login bearer token is expired

xet7 commented 5 years ago

To api call also you need to change api url, board id etc other ids to replace those in examples

xet7 commented 5 years ago

@arradog

There is also more complete integration example in Javascript at https://github.com/wekan/wekan-gogs

And Python API client at https://github.com/wekan/wekan-python-api-client

Did you have any progress with VBA ?

I have been thinking that maybe I should make more complete examples for different programming languages.

bentiss commented 5 years ago

@arradoq just to check the obvious, do you have WITH_API wekan environment variable set to true?

On a current edge test wekan instance, with WITH_API=true and ROOT_URL set to http://localhost:3000 I can do:

$> curl -X POST "http://localhost:3000/users/login" -H  "accept: application/json" -H  "Content-Type: application/x-www-form-urlencoded" -d "username=admin&password=mypassword"
{
  "id": "ZPnFGmCJ3AKadrC32",
  "token": "5FUA79ozpqP7G0DiqZpuTbb2smO6seJsBC0cZ-5yP1v",
  "tokenExpires": "2019-04-23T09:02:19.742Z"
}%

$> curl -X GET "http://localhost:3000/api/boards" -H  "accept: application/json" -H "Authorization: Bearer 5FUA79ozpqP7G0DiqZpuTbb2smO6seJsBC0cZ-5yP1v"
[
  {
    "_id": "SypYxZ4YzxGwFh47f",
    "title": "Welcome Board"
  }
]%

(note, use JSON content type works better, but for most calls, you can also use the x-www-form-urlencoded ones)

@xet7: as for more concrete examples, with the openapi in place, you can use https://editor.swagger.io/: Just import the wekan.yml file, and use the client generator. The produced client is not entirely compatible as the Authorization token is not standard (I couldn't get this right), but it gives some nice base for an implementation.

I'll also publish soon-ish my python binding that makes use of the openapi and bravado python module for a more pythonic version of the API.

arradoq commented 5 years ago

I don't know about this, but do we must follow rebuild-wekan.sh for source installation? cause I don't really follow that. Which resulted no .build/bundle directory. From start-wekan.sh I found that we must enter to .build/bundle to enable WITH_API. Or is there any other way simpler? Thank you.

xet7 commented 5 years ago

Yes, bundle needs to be created, and WITH_API set, and then run it with node. This needs to be done once to get C/C++ etc dependencies built.

If you are developing, you can run cd wekan && WITH_API=true meteor so that meteor watches does some file change in Wekan directories, and automatically rebuild bundle.

Yes, that rebuild-wekan.sh script is just temporary solution. Usually meteor projects can be built with setting environment variables and then running meteor. Having this in Wekan requires copying Wekan dependecies like wekan-ldap etc repos copied to wekan/packages directory, and some other changes. There is in-progress PR https://github.com/wekan/wekan/pull/2124 to enable this (needs testing and cherry picking), but it remains to be seen does it make thouse build scripts unnecessary, most likely it just makes scripts shorter.

Environment variables are for Wekan settings, in source/Snap/Docker/Sandstorm etc, for the reason that they are user modifiable, and Wekan bundle does not need rebuilding to change settings, because those settings are not hardcoded in source code.