Muestras de comandos cURL de la API de importación

A continuación se muestran los comandos curl necesarios para realizar una operación de importación al usar un archivo CSV. Los pasos realizarán lo siguiente:

1. Iniciar la importación
2. Comprobar su estado
3. Obtener la información del informe
4. Sondear el estado del informe de excepción
5. Obtener el informe de excepción
6. Analizar o copiar los errores y advertencias a un archivo
7. Aprobar la importación
8. Verificar su estado una vez más

Asegúrese de ingresar un nombre de usuario y contraseña válidos. Las empresas de servicios públicos en Canadá que inician sesión en BEACON a través de https://beaconama.ca deberán cambiar los localizadores de recursos uniformes (Uniform Resource Locators, URL) de estos ejemplos a api.beaconama.ca.

La salida detallada de curl se acortó en los ejemplos a continuación.


# Establecer el nombre de usuario y la contraseña
$ export BDEUSER="<username>"
$ export BDEPASS="<password>"
  
  
# Combinarlos en el parámetro de autenticación de curl
$ export BDEAUTH="-u $BDEUSER:$BDEPASS"
  
  
# Definir el host de la interfaz de programación de aplicaciones (Application Programming Interface, API) del Badger Meter Data Exchange (BDE) de destino (https://api.beaconama.net)
$ export BDEAPI=https://api.beaconama.net
  
  
# (1) Crear una nueva importación usando '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: Wed, 09 Nov 2016 20:41:03 GMT
Content-Length: 82
Connection: keep-alive
  
  
{
	"bdeUUID":"6149697131109497959",
	"statusUrl":"/v1/bde/import/6149697131109497959"
}
  
  
# Registrar el identificador único universal del BDE (BDE Universally Unique Identifier, BDEUUID) que obtuvo de la llamada de importación
$ export BDEUUID=6149697131109497959
  
  
# (2) Comprobar el estado de la importación hasta que vea "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: Wed, 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) Obtener la información del informe
$ 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/json
Date: 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) Obtener la ubicación del informe de excepción
$ 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/json
Date: Wed, 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) Obtener a través del encabezado de ubicación anterior, no envíe la autenticación 
$ 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-stream
Content-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 lista de errores y advertencias se mostrará en el cuerpo de la respuesta, la cual debe analizar en su código o guardar en un archivo y abrir en un programa como Microsoft Excel.
 
# (7) Aprobar la misma importación
$ curl -v $BDEAUTH -X PUT $BDEAPI/v1/bde/import/$BDEUUID
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json
Date: Wed, 09 Nov 2016 21:53:12 GMT
Content-Length: 82
Connection: keep-alive
  
  
{"bdeUUID":"6149697131109497959","statusUrl":"/v1/bde/import/6149697131109497959"}
  
  
# (8) Comprobar de nuevo el estado de la importación
$ 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: Wed, 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.

A %d blogueros les gusta esto: