m-ld / timeld

Live shared timesheets
MIT License
1 stars 1 forks source link

API example from docs not working? #106

Closed michielbdejong closed 1 year ago

michielbdejong commented 1 year ago

Following the instructions from https://github.com/m-ld/timeld/blob/main/doc/api.md#import I see:

curl -X POST -d @./example.ndjson  -u $CREDENTIALS -H 'Content-Type: appon/x-ndjson' https://timeld.org/api/import
{"code":"InternalServer","message":"caused by Error: Could not parse row {\"@type\":\"Project\",\"@id\":\"org1/pr1\",\"external\":{\"@..."}

Did the API change or am I doing something wrong in my curl command?

This is the contents of example.ndjson:

cat example.ndjson 
{"@type":"Project","@id":"org1/pr1","external":{"@id":"http://ex.org/project/1"}}
{"@type":"Timesheet","@id":"org1/ts1","project":[{"@id":"org1/pr1"}],"external":{"@id":"http://ex.org/timesheet/1"}}
{"@type":"Entry","session":{"@id":"org1/ts1"},"activity":"orging","duration":60,"start":{"@value":"2022-06-22T16:40:55.946Z","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},"vf:provider":{"@id":"test"},"external":{"@id":"http://ex.org/timesheet/1/entry/1"}}
mcalligator commented 1 year ago

Could you describe the setup you're using to do this? Is it straight from the GitHub repo, from the test suite that Yvo created, or the Docker images? That would help with reproducing the issue :-).

michielbdejong commented 1 year ago

This is testing against your production server, note that the URL is https://timeld.org/api/import You can just run this curl command as-is from any internet-connected machine, just make sure you set the $CREDENTIALS env var to <your-user> + : + <your-key>

gsvarovsky commented 1 year ago

Please can you try using --data-binary?

When -d, --data is told to read from a file like that, carriage returns and newlines will be stripped out.

michielbdejong commented 1 year ago

Ah. that helps! Added this in https://github.com/m-ld/timeld/pull/107

But I'm still getting {"code":"Forbidden","message":""} as the response. That is probably because I need to replace the strings "org1/pr1" and "org1/ts1". How do I know which values to put in there?

michielbdejong commented 1 year ago

Ah, I think I found mine - "fedb/fedt" and "fedb/from-ponder-source-testing", with the following I get a 200 response:

{"@type":"Project","@id":"fedb/fedt","external":{"@id":"http://ex.org/project/1"}}
{"@type":"Timesheet","@id":"fedb/from-ponder-source-testing","project":[{"@id":"fedb/fedt"}],"external":{"@id":"http://ex.org/timesheet/1"}}
{"@type":"Entry","session":{"@id":"fedb/from-ponder-source-testing"},"activity":"orging","duration":60,"start":{"@value":"2022-06-22T16:40:55.946Z","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},"vf:provider":{"@id":"test"},"external":{"@id":"http://ex.org/timesheet/1/entry/1"}}