SNflows / flows

Flows Pipeline
https://flows.phys.au.dk
GNU General Public License v3.0
3 stars 4 forks source link

Make target_save.php POST request available via API, (to update redshift and ztfid). #117

Open emirkmo opened 2 years ago

emirkmo commented 2 years ago

Currently, editing the target is possible via the website. The endpoint is /target_save.php

It takes a referrer with some targetid: https://flows.phys.au.dk/target_edit.php?target=114

It also requires cookie and a sessionID to be set, so a logged in client. It would be great if this endpoint was also available via making a POST request to api/target.php?target=114 or something like api/target_save.php?target=114, with the data containing the updated target info. Obviously, the targetid/name should not be updatable, but everything else should be. So that it can be used from within the API without having to make a logged-in client and spoof headers etc.

just for reference, these are the fields (minus targetid/targetname). {'target_name': '2020wtp', 'targetid': 114, 'ra': 124.99880293333, 'decl': 7.79367375, 'catalog_downloaded': True, 'discovery_mag': 19.22, 'inserted': '2020-10-26 09:52:06.485412', 'redshift': 0.07, 'redshift_error': None, 'discovery_date': '2020-10-13 11:25:26.4', 'project': 'ztf-ia', 'host_galaxy': 'api_edited', 'ztf_id': 'ZTF20aciugdl', 'target_status': 'target', 'sntype': 'Ia'}

@rhandberg Could you add this endpoint, and also, could you please provide a list of API endpoints to me as well, so that I have access to them?

Currently, these are the known ones: https://github.com/SNflows/tendrils/blob/da578e1eb56b9e75b3e0fd09d9de52fb13748994/tendrils/utils/urls.py#L13-L26

class RemoteUrls:
    base_url: str = 'https://flows.phys.au.dk/api/'
    datafiles_url: str = 'datafiles.php'
    targets_url: str = 'targets.php'
    sites_url: str = 'sites.php'
    set_photometry_status_url: str = 'set_photometry_status.php'
    photometry_url: str = 'download_photometry.php'
    photometry_upload_url: str = 'upload_photometry.php'
    cleanup_photometry_status_url: str = 'cleanup_photometry_status.php'
    catalogs_url: str = 'reference_stars.php'
    catalogs_missing_url: str = 'catalog_missing.php'
    filters_url: str = 'filters.php'
    lightcurves_url: str = 'lightcurve.php'
    targets_post_url: str = 'targets_add.php'
rhandberg commented 2 years ago

It should actually be possible to modify a target using the exact same API endpoint as for adding a target. Only thing is that you have to add the targetid to the POST request. Only problem is that you have to add all the information about the target. I.e. you have to provide the full dict. It should be easy to make the Python API pull down the current target information, modify what needs to be modified in the dict, and post it back to the web-API.

emirkmo commented 2 years ago

I did try this but it returns with the error that target already exists. Are you sure? I tried pulling a random target, modifying only the host, and passing in the targetid. But it's possible I did something wrong.

rhandberg commented 2 years ago

It should work... What is the exact error message that you get?