API token generation

Hi guys,

I am trying to get started with API usage, so my level is more or less beginner, but I think I should be able to learn quick. I have some issues to generate the Farmbot token. Here are my steps to generate the token using curl:

  1. windows terminal started (OS win10 64 with curl pre installation)
  2. command entered:
curl -d '{"user":{"email":"myEMAIL","password":"myPASSWORD"}}' -H "Content-Type:application/json" -X POST https://my.farmbot.io/api/tokens

The output is:
{“status”:400,“error”:“Bad Request”}

What am I missing? Do I need to have it send as a file?

I already tried to get the information from github, but I cannot find a detailed description on API token generation, except the one provided. But that one wasn´t helpful for me.

Thanks for your help!

*** EDIT ***

I am able to use the Python snippet for token generation. Somehow there must be a mistake in my POST command, but I don´t know what´s wrong -.-

@Fuooor a 400 error means “that the server is unable to process the request sent by the client, due to an issue that is perceived by the server to be a client problem.”

I was able to successfully create a token using the code you provided (as was @connor when I shared the snippet with him). My guess is that your local terminal app or text editor is inserting bad characters somewhere.

A few steps to take:

  • Run your JSON through a JSON validator (a Google search will provide many options).
  • Ensure that your terminal or text editor is not replacing characters (especially quote characters).
  • Review the API example requests to ensure that your request is properly formatted (it appears to be correct as posted).

Are there any other special tools on your local development environment?

Hey Rick,

thank you for your prompt reply. I tried it out with postman, and it worked too. I tried lots of stuff. In the end I figured out, that my Windows 10 machine isn´t properly configured and openSSL capable. Somehow I am unable to combine curl with openSSL. Do you have any idea how to do that? I ran out of ideas and google wasn´t helpful at all …

Btw, I retried the token snippet with my Linux System, and - oh wonder - it worked properly.

If you have any idea that would be great!


@Fuooor Interesting. I am glad that you were at least able to isolate the root cause.

Unfortunately, I am not a Windows user, so I can’t offer too much assistance. I found this response on StackOverflow that seems to suggest CURL requires special setup for SSL in Windows.