API test

Dear Sen4CAP team,

we want to integrate Sen4CAP into our system. I tried to use postman to test your API. But I could not send any request and always get the request time out error.
Here are two examples that I have tried:

POST: http://IPofVM/login?user=USERNAME&pwd=PASSWORD#
GET: http://IPofVM/downloader/sources/

How shall I authorize the request? I tried to just simply using the username and password for the web interfache.

Best regards,
Shengyin

Hallo,

i changed the URL to https and filled out the form-data with user and pass, now I can send out the request, but got an 404 not found error.

Best regards
Shengyin

Dear Shengyin,

As of now, except for one case, the endpoints do not require authentication.
The endpoints’ base URL is http://IPofVM:8081. Please note the port 8081 which was missing from your example.
The only endpoint requiring an authentication token is:
GET: http://IPofVM:8081/products/?userId=&siteId=&productTypeId=&authToken=
Note that this method is not indented to be used directly (since it requires internal IDs that may be not know to the user), but from the simplified product browsing and download interface.
This is accessible at http://IPofVM:8081/ and it requires you to authenticate via a login form.

In a subsequent version, all the endpoints will require authentication (basic authentication) and will be over HTTPS.

Hope this helps,
Cosmin.

Hallo Cosmin,

I thought Sen4CAP system has already included Sen4CAP Services, because there is no seperate packadge of Sen4CAP Services on the Sen4CAP Website.
But recently I found in GitHub https://github.com/Sen4CAP/sen4cap-services the Sen4CAP services. Do I need to first build it up in order to use and test the Endpoint services?

and which page of Sen4CAP user manual are you refering to by saying “Follow the Sen4CAP user manual to configure the database connection and integrate them into the Sen4CAP system.”?

Best regards
Shengyin

Hello Shengyin,

Sen4CAP system includes the Sen4CAP services module, so you just need to install the system.
For the other question, I think my other colleague (also named Cosmin :slight_smile: ) has sent you something, and I don’t know what was that about. The database connection string may be changed in the file /usr/share/sen2agri/sen2agri-services/config/services.properties. But I advise not to change that if you just installed the system following the instructions.

Best regards,
Cosmin.

Hallo Cosmin,

Thank you for your answer. Your colleage didn’t send me anything. The sentence I quoted was from the README.md of Sen4CAP-services on GitHub. We have installed the Sen4CAP system on CREODIAS, but the Sen4CAP endpoint services still cannot be called.

I still have the same problem with postman (cannot send request because of request time out error) after specified the port 8081. I have tried without authentification, and
no matter the URL start with “http” or “https”, I cannot send the request.

Best regards,
Shengyin

Hello Sengyin,

I would assume (since you have mentionned PostMan) that you try to issue the requests from your local machine to the CreoDIAS machine. On CreoDIAS, only some ports are opened by default to be accessible from remote location. 8081 is not one of them.
Hence, you have two solutions:

  1. Open the 8081 port from the CreoDIAS administration console. Here I cannot guide you.
  2. Do a port forwarding using a SSH tunnel (you should already have a SSH connection to that machine). For example, using Putty, you’d do the following:
  • Open Putty
  • On the Session node, enter the public IP address of the machine, leave 22 as port value;
  • On the Connection > SSH > Auth node, browse and select your SSH ppk key;
  • On the Connection > SSH > Tunels, set source port as 8081, and destination as 127.0.0.1:8081;
  • Open the connection and leave the terminal open (don’t close it);
    Then, you should be able to issue http GET requests from portman at http://localhost:8081, as long as you have the Putty session open.

Best regards,
Cosmin.

Hallo Cosmin,

I tried both solutions, and they result in a same error: connect ECONNREFUSED 127.0.0.1:8081

Best regards
Shengyin

Hi Shengyin,
Please check in “/usr/share/sen2agri/sen2agri-services/config/services.properties” what is set for key “server.port”.
Could be that you have 8080 there which is default value for install.

best regards,
Florin

Hallo Florin,

I just checked, it was 8080, I changed it to 8081. However the error remains the same: connect ECONNREFUSED 127.0.0.1:8081

Best regards
Shengyin

Did you restart sen2agri-services after the change?
regards,
Florin

Yes, I did.

regards
Shengyin

Hello Cosmin,
you mentioned in your reply that, except one case (/products/), all the other endpoints do not require authentication right now. They would be required in the subsequent version.

Does that mean, that (until the updated Version is available) anyone who knows the IP of a specific VM can possibly manipulate the Sen4CAP System via the endpoint services, like starting or stopping the download? If yes, this would cause serious security concern which could lead to the decision not to use Sen4CAP within our PAs monitoring system. Is there a way to prevent unwanted access? I expect this is also relevant for other countries/PAs.

I would like to mention that our Sen4CAP system is running on CREODIAS.

Can you tell me when we can expect the mentiones new version, which requires authentication for all endpoints?

Apart from this, I am not able to call some endpoints, because the provided description of their parameters is not so clear and not detailed enough for me. For example, I want to call the “/parcel” action, but I don’t know what the parameter “practice” means, and which possible values can be given to this parameter. I would strongly appreciate if you could provide us with more information in the API description.

Regards,
Jonathan

Does Sen4cap 3.0 REST API has authentication now?
I see in change log, that API is updated to support administrative operations, so authentication seems necessary but I can’t find that in user manual.

I updated system to 3.0 and I can’t get markers DB data via Requests no more (Response 401). So I’m hoping for hints to solve the issue now.

Hello Zane,

yes there is an authentification now. You should create a token to call you requests.

Here is an exemple of script for the API (in R script) with the by default user and pwd :

usr = list( user = 'sen4cap', pwd = 'sen4cap')
login = paste0("http://",ip_address,":",port,'/login')

authentication <- POST(login, content_type("application/x-www-form-urlencoded"), query=usr)
authentication
authentication <- fromJSON(content(authentication, "text"))
token <- authentication[['data']][['sessionToken']]

call <- paste0('http://',ip_address,':',port,'/','markers/names?site=',site_short_name,'&productType=',markers_type,'&year=',year)
#call <- paste0('/markers/names?site=',site_short_name,'&productType=',markers_type,'&year=',year)
print(call)
response <- GET(call,add_headers("X-Auth-Token" = token))

I hope it’s help.
Diane

Thank you, Diane! It helped.

Now I have another problem - response says that products doesn’t exist although they are present in Product browser.

Which type of products/markers are you trying to analyse ?
Have you performed the marker extraction step (MDB1) ?

I’m trying to analyse mean_NDVI from MDB1.

/markers/names?site=test&productType=mean_NDVI&year=2021
/markers/names?site=test&productType=mdb1&year=2021
both returns message: product type not found.

I succeed to GET all markers from MDB1 before updating to 3.0.

Could it be useful to try to launch new marker database extraction as a custom job now?

Normally the extraction done with the v2 should work with the v3
Can you try :

/markers/names?site=test&productType=s4c_mdb1&year=2021
or
/markers?site=test&productType=s4c_mdb1&year=2021&markers=mean_NDVI

Thank you very much, Diane!
These strings work.