csweb api authentication

Discussions about syncing data via Bluetooth, Dropbox, FTP, and using CSWeb
Post Reply
wis
Posts: 5
Joined: November 14th, 2019, 1:46 am

csweb api authentication

Post by wis »

Hi Everyone

I have trouble authenticating to csweb using API in csweb from terminal with curl.

Curl command entered:

Code: Select all

curl -i -X POST URL/csweb/api/token -d "grant_type=password" -u username:password
Response:

Code: Select all

HTTP/1.1 400 Bad Request
Date: Thu, 14 Nov 2019 06:58:33 GMT
Server: Apache/2.4.39 (Win64) PHP/7.2.18
X-Powered-By: PHP/7.2.18
Cache-Control: no-store, private
Content-Length: 100
Connection: close
Content-Type: application/json

{"type":"error","status":400,"code":"invalid_client","message":"The client credentials are invalid"}
Please help with authentication.

Thanks
josh
Posts: 2401
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: csweb api authentication

Post by josh »

The token endpoint expects JSON content containing the username and password. Try something like the following:

Code: Select all

curl -H 'Content-Type: application/json' -X POST -d '{"client_id":"cspro_android","client_secret":"cspro","grant_type":"password","username":"username","password":"password"}' http://www.mycsweb.com/api/token
You should get a response like:

Code: Select all

{access_token":"c736f2206138c61d0e242a4518e1327a9c99afa9","expires_in":3600,"token_type":"Bearer","scope":null,"refresh_token":"9691e6e0c12d5afba51af52efd5e5ba2gabd7c3a"}
You can then use the access_token in the authorization header for future requests. With the above response the header would be:

Code: Select all

Authorization: Bearer c736f2206138c61d0e242a4518e1327a9c99afa9
The CSWeb REST API is documented in the file www/csweb/src/api/app/swagger.json. If you haven't used Swagger before they have some nice online tools for viewing Swagger specifications. Try https://swagger.io/tools/swagger-ui/.
wis
Posts: 5
Joined: November 14th, 2019, 1:46 am

Re: csweb api authentication

Post by wis »

Thanks very Josh.

It worked, now I can play around with the rest of the API's.

Thanks.
Karan
Posts: 1
Joined: November 16th, 2019, 4:07 am

Re: csweb api authentication

Post by Karan »

hi there,
this is karan from india , i would like to know something about csweb , somebody help me for solving their problems which i face like,
when i want to use csweb option into "deploy application" there it is asking "usename & password" . guys i don't understand which usename or password it is asking , if i use my this site username & password then it give error massage like given below...
Doc1.docx
(120.13 KiB) Downloaded 356 times

Regards
Karan.
josh
Posts: 2401
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: csweb api authentication

Post by josh »

Please start a new topic rather than responding to someone elses unrelated post and please just post your question once (I deleted the other post in tools).

Please see the help on synchronization that describes the different server options: Dropbox, CSWeb and FTP: https://www.csprousers.org/help/CSPro/s ... ation.html

More details on how to set up a CSWeb server can be found in the help for CSWeb: https://www.csprousers.org/help/CSWeb/
wis
Posts: 5
Joined: November 14th, 2019, 1:46 am

Re: csweb api authentication

Post by wis »

Hi everyone

I need help and clarity in the following. I am using CSEntry for data collection and CSWeb for server.

I was looking at the .csdb file stored in csentry directory in a tablet, I could see the cases table from the DB but I could not see the data that was captured in any of the tables.

My question is where is the data that is collected via CSEntry Application stored in the the .csdb, and are there any CSWeb APIs to query captured data from the table on the CSWeb.

Your assistance will be highly motivated.

Thanks.

Edit...
What I am trying to achieve is to be able to capture data on tablet 1 and sync data to server and launch the captured questionnaire on tablet 2.
Gregory Martin
Posts: 1845
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: csweb api authentication

Post by Gregory Martin »

Have you looked at the syncdata function help: https://www.csprousers.org/help/CSPro/s ... ction.html

There are three parameters, GET, PUT, and BOTH, that control the transmission of data. If you want to get data on tablet 2, you can use syncdata with GET to retrieve data from the server. If you only want to transmit certain data (e.g., data from a certain region), you can add a universe to the syncdata call.
Post Reply