0

I'm new and super excited about doing stuff directly from the console! : )

Today I was playing around with the meaningcloud API for Lemmatization etc. and it is working great when I input text directly into the URL as a parameter like txt=here%20my%20text.

However, when trying to feed input from a file, using the doc= parameter as described in their docs, I keep getting the following response:

{"status":{"code":"200","msg":"Missing required parameter(s) - [txt]", ...

The docs read that I can use either doc, url or txt as parameter to specify the source of the text input, but it seems I am doing something wrong here.

I tried around for a while with different versions of absolute and relative paths, but couldn't figure out how to get it to take input directly from a file.

Here's one example call that I was making, maybe someone can point me to my error (In the real calls I have my API key in there instead of {my_key_here}!):

curl -K -XPOST "https://api.meaningcloud.com/parser-2.0?key={my_key_here}&of=json&lang=es&doc=Users/Martin/Documents/text.txt" >> output.json

I tried the more general answers here but just got the same error response. I'm wondering whether this is a general error of mine, or whether it's specific to the API.

Thanks for any tips!

Community
  • 1
  • 1
martin-martin
  • 3,274
  • 1
  • 33
  • 60
  • 1
    The `-K` option is totally wrong there though, as it will then treat `-XPOST` as a file name to read from... You probably meant lowercase `-k`. – Daniel Stenberg Feb 10 '17 at 07:16
  • Oh! Thanks a lot. Yes, I copied this without checking up on it! Read up on it now here: https://curl.haxx.se/docs/manpage.html and there's no need for this at all. – martin-martin Feb 10 '17 at 08:27
  • It's still not working, though, so there must be some other issue in there. – martin-martin Feb 10 '17 at 08:29
  • Well, sure, you can't just make things up to your own wishes. You already wrote an answer to yourself showing a POST that works so probably a plain GET is not working against that API. – Daniel Stenberg Feb 10 '17 at 08:30

1 Answers1

1

I got it to work with @Lucas Liu 's answer in this thread!

curl  -i  -F doc=@text.txt "https://etc."

And @Daniel Stenberg's nudging helped me to also figure out my initial error (from the curl manual):

@filename

This will make curl load data from the given file (including any newlines), URL-encode that data and pass it on in the POST.

I was passing my file URL as a string - through not prepending the @ symbol. So the working version of the original call (in the API's suggested format) looks like that:

curl -XPOST "https://api.meaningcloud.com/parser-2.0?key={my_api_key}&of=json&lang=es&doc=@Users/Martin/Documents/text.txt" -o output.json 
Community
  • 1
  • 1
martin-martin
  • 3,274
  • 1
  • 33
  • 60