Importez des échantillons cURL d’API

Les commandes curl nécessaires pour effectuer une opération d’importation à l’aide d’un fichier CSV sont reprises ci-dessous. Les étapes :

1. Initient l’importation
2. Vérifient son statut
3. Obtiennent les informations sur le rapport
4. Interrogent l’état du rapport d’exception
5. Obtiennent le rapport d’exception
6. Analysent ou copient les erreurs et avertissements dans un fichier
7. Approuvez l’importation
8. Vérifient son état une nouvelle fois.

Assurez-vous de saisir un nom d’utilisateur et un mot de passe valides. Les services d’eau canadiens qui se connectent à BEACON sur https://beaconama.ca doivent modifier les URL dans ces exemples en api.beaconama.ca.

La sortie curl étendue a été abrégée dans les exemples ci-dessous.


# set username and password
$ export BDEUSER="<username>"
$ export BDEPASS="<password>"    

# combinez-les dans le paramètre curl auth
$ export BDEAUTH="-u $BDEUSER:$BDEPASS"    


# define destination BDE API host (https://api.beaconama.net)
$ export BDEAPI=https://api.beaconama.net    


# (1) créez une nouvelle importation à l’aide du fichier ’import_file.csv’
$ curl -v $BDEAUTH -F data=@import_file.csv $BDEAPI/v1/bde/import
HTTP/1.1 202 Accepted
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json
Date: Mer, 09 nov 2016 20:41:03 GMT
Content-Length: 82
Connection: keep-alive  

{	
    "bdeUUID":"6149697131109497959",
    "statusUrl":"/v1/bde/import/6149697131109497959"
}   

# record BDEUUID returned from the import-call
$ export BDEUUID=6149697131109497959    

# (2) vérifiez l’état de l’importation jusqu’à voir "state"="done"
$ curl -v $BDEAUTH $BDEAPI/v1/bde/import/$BDEUUID
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json
Date: Mer, 09 nov 2016 20:42:21 GMT
Content-Length: 125
Connection: keep-alive    

{	
    "dryRun":true,    
    "importFile": "import_file.csv",	
    "reportUrl":"/v1/bde/import/6149697131109497959/report",	
    "message":"import operation succeeded",	
    "state":"done"
}    

# (3) obtenez les informations du rapport
$ curl -v $BDEAUTH $BDEAPI/v1/bde/import/$BDEUUID/report
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/jsonDate: Wed, 09 Nov 2016 20:43:33 GMT
Vary: Accept-Encoding
Content-Length: 401
Connection: keep-alive    

{	
    "mDryRun":true,	
    "dryRun":true,	
    "dateCreated":"2016-11-09T20:43:13Z",	
    "warningCount":5,	
    "errorCount":5,	
    "okCount":1,	
    "originalUrl":"/v1/content/8022223330445118400/imports/6149697131109497959/import_source.txt",	
    "errorUrl":"/v1/content/8022223330445118400/imports/6149697131109497959/unique_exceptions.json",	
    "errorSheetUrl":"/v1/content/8022223330445118400/imports/6149697131109497959/import_troubles.csv"
}  

# (4) obtenez l’emplacement du rapport d’exception
$ curl -v $BDEAUTH -X GET $BDEAPI/v1/content/8022223330445118400/imports/6149697131109497959/import_troubles.csv
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/jsonDate: Mer, 09 nov 2016 21:45:33 GMT
Content-Length: 230
Connection: keep-alive
Location: https://bmi-prod-portfolios.s3.amazonaws.com/123456789/imports/6149697131109497959/import_troubles.csv?Signature=abcdefg%3D&Expires=1522769025&AWSAccessKeyId=ASIAABCDEFGHIJKLMN&x-amz-security-token=FQoCVCAPBa904fL/SKiA/cD7/lGvrvZYu4bgvL29KsIsO4p5yPD7u4WLciTgx1h4K4A7huRi4r6uamKhjWhU0YtR65h... 
 
# (5) Obtenez via l’en-tête d’emplacement ci-dessus, n’envoyez pas d’authentification 
$ curl -v -X GET https://bmi-prod-portfolios.s3.amazonaws.com/123456789/imports/6149697131109497959/import_troubles.csv?Signature=abcdefg%3D&Expires=1522769025&AWSAccessKeyId=ASIAABCDEFGHIJKLMN&x-amz-security-token=FQoCVCAPBa904fL/SKiA/cD7/lGvrvZYu4bgvL29KsIsO4p5yPD7u4WLciTgx1h4K4A7huRi4r6uamKhjWhU0YtR65h
Date: Tue, 03 Apr 2018 15:07:47 GMT
Last-Modified: Tue, 03 Apr 2018 15:07:40 GMT
x-amz-expiration: expiry-date="Thu, 04 Apr 2019 00:00:00 GMT", rule-id="DE expiry"ETag: "b81ee6536413445da7fc120b3"
x-amz-meta-content-type: text/csv
Accept-Ranges: bytes
Content-Type: binary/octet-streamContent-Length: 16287
Server: AmazonS3

record number,errors,warnings,account_id,account_first_name,account_last_name,account_full_name,account_email,account_phone,account_phone_extension,billing_address_line1,billing_address_line2,billing_address_line3,billing_city,billing_state,billing_zip,billing_country,person_id,account_status,account_portal_status,account_billing_cycle,location_id,location_name,location_address_parity,location_address_line1,location_address_line2,location_address_line3,location_city,location_state,location_zip,location_county_name,location_country,location_latitude,location_longitude,location_building_type,location_building_number,location_site,location_funding,location_main_use,location_water_type,location_area,location_irrigated_area,location_population,location_irrigation,location_year_built,location_pool,location_bathrooms,location_district,location_dhs_code,location_parcel_number,location_et_jan,location_et_feb,location_et_mar,location_et_apr,location_et_may,location_et_jun,location_et_jul,location_et_aug,location_et_sep,location_et_oct,location_et_nov,location_et_dec,service_point_id,service_point_type,service_point_cycle,service_point_route,service_point_class_code,service_point_class_code_normalized,service_point_latitude,service_point_longitude,service_point_timezone,meter_id,meter_sn,meter_manufacturer,meter_model,meter_size,meter_note,meter_continuous_flow,register_number,register_unit_of_measure,register_resolution,meter_install_date,meter_install_start_read,meter_removal_date,meter_removal_end_read,sa_start_date,sa_end_date,endpoint_sn,endpoint_type,endpoint_install_date,endpoint_removal_date,read_sequence,alert_code,high_read_limit,low_read_limit,utility_use_1,utility_use_2...

# (6) la liste des erreurs et avertissements sera renvoyée dans le corps de la réponse, que vous devrez analyser dans votre code ou enregistrer dans un fichier et ouvrir dans un programme comme Microsoft Excel. code ou enregistrer dans un fichier et ouvrir dans un programme comme Microsoft Excel.

# (7) approuvez la même importation
$ curl -v $BDEAUTH -X PUT $BDEAPI/v1/bde/import/$BDEUUID
HTTP/1.1 200 OKCache-Control: max-age=0, private, must-revalidate
Content-Type: application/json
Date: Mer, 09 nov 2016 21:53:12 GMT
Content-Length: 82
Connection: keep-alive    
{
    "bdeUUID":"6149697131109497959",
    "statusUrl":"/v1/bde/import/6149697131109497959"
}    

# (8) vérifiez à nouveau l’état de l’importation
$ curl -v $BDEAUTH $BDEAPI/v1/bde/import/$BDEUUIDHTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json
Date: Mer, 09 nov 2016 21:53:25 GMT
Content-Length: 126
Connection: keep-alive


 
Knowledge Base

User Guide
Follow via Email

Enter your email address to get new content notifications by email.