API Call from External

Dear Farmbot Team,

just reading through the documentation of the API and was wondering the the API Reference get deprecated with the version 1.3. It that correct ?

We want to call the Farmbot Web App with an external App using the Farmbot API (REST, JSON…)
Could you stick me to the right documentation how to do that or explain how to do that ?

Thanks in advance

@Cosmsonic

The latest REST API documentation is available here. I have updated the documentation just now so it is the most up-to-date version for my.farmbot.io.

One thing to keep in mind is that we use the REST server only for data storage. This means that you cannot control FarmBot via REST. If you wish to write an application that will control a FarmBot, you will need to use the MQTT server.

Resources

Does that help? Please let me know if you have any other questions about using the API.

HI Rick,

tried to generate the Token but didn’t get the running. Could your provide a simple example how to geht the token, when using the farmbot web app.

Thanks in advance.

HI Rick,

got it ! Used the correct POST command of the API and put the right text in the Body:

POST /api/tokens

Request

{
“user”: {
“email”: "nona_schaden@sporerkohler.net",
“password”: “password”
}
}

Body must be declared as JSON in postman :wink:

Post it here, if anybody else would have the same question.
Now I got the token and will continue with testing the REST API.
Will give you feedback how it works within our app.

Cheers

1 Like

Hi Rick,
I’ve started to make a swaggerDoc-File for the rest-api to improve the overview (and documentation).
Do you have an idea for the correct directory for such a thing in the git-repo?

Here a short summary about swagger:

  • it’s an REST-API-Specification (OAS / OpenAPI) (this is the swaggerDoc-File - json or yaml)
  • there a several ways to create an swaggerDoc:
    • Design-First: use an online-editor like editor.swagger.io or studio.restlet.com
    • Code-First: Annote the endpoints in source-code and use a swagger-framework to generate a swaggerDoc and to generate an documented HTML-RestClient for the API

Yes, swagger has a ruby-lib :wink: unfortunately I’m not very familiar with ruby so I decided to start with a Design-First approch.
In the long run it would be cool to have a well documented swagger-ui with a mock-farmbot. That would decrease the barrier to develop software against the farmbot REST-API (IMHO).

@fafi That’s great to hear! A swagger/ folder at the project root might work fine. Did you put it up on Github yet?

I’m familiar with Swagger, and would probably chose it as our documentation format when we have the time to implement. I’ve tried to adopt it in the past, but my main reason for not using it is simply a lack of time.

The API is 4 years old, so there are a lot of edge cases that must be documented.

@RickCarlino,
nice to hear from you. Is everything from https://gist.github.com/RickCarlino/10db2df375d717e9efdd3c2d9d8932af already implemented or is that more an design-document?

I discovered some design decisions which are very unsual for REST-APIs (IMHO) e.g.

  • DELETE-Verbs with an array of IDs (DELETE /api/points/23,24,25,26,27,28)
  • DELETE-Verbs with a request-body (/api/sequences/52)
  • IDs in path-vars and requestbody (/api/users/verify/14d93f65-a933-4621-a33f-784; /api/users/verify/a091cb01-d27e-48dd-9d2d-d98) here
  • Is there a difference between problem & error (POST /csp_reports vs. (NOT OK) POST /api/points)

The discussion continues here: