Fail to import events in csv format throught web api

Hi dear Community

I am trying to import the below csv file with the following command without success (into play.dhis2.org/2.35.0):

curl -d @events-6.csv "https://play.dhis2.org/2.35.0/api/events.csv?skipFirst=true&dryRun=false&payloadFormat=csv" -H "Content-Type:application/csv" -u "admin:district" -v

Please let me know what I am doing wrong.

Note: events-6.csv file is working well when used with Import/Export App.

Content of events-6.csv:

event,status,program,programStage,enrollment,orgUnit,eventDate,dueDate,latitude,longitude,dataElement,value,storedBy,providedElsewhere,completedDate,completedBy,geometry
bcdf88cedc2,ACTIVE,VBqh0ynB2wv,pTo4uMt3xur,,DiszpKrYNg8,2020-08-24T00:00:00.000,2020-08-24,8.06311527044516,-11.4283223849698,F3ogKBuviRA,"[-11.4234147333302,8.04129958345372]",bjorn,false,,,"POINT (-11.4283223849698 8.06311527044516)"
bcdf88cedc2,ACTIVE,VBqh0ynB2wv,pTo4uMt3xur,,DiszpKrYNg8,2020-08-24T00:00:00.000,2020-08-24,8.06311527044516,-11.4283223849698,oZg33kd9taw,Female,bjorn,false,,,"POINT (-11.4283223849698 8.06311527044516)"
bcdf88cedc2,ACTIVE,VBqh0ynB2wv,pTo4uMt3xur,,DiszpKrYNg8,2020-08-24T00:00:00.000,2020-08-24,8.06311527044516,-11.4283223849698,qrur9Dvnyt5,23,bjorn,false,,,"POINT (-11.4283223849698 8.06311527044516)"

The above curl command returns no error message (see below) but obviously the event has been imported:
https://play.dhis2.org/2.35.0/api/events/bcdf88cedc2.json
=> ERROR: “Event not found for ID bcdf88cedc2”

  • Trying 34.243.233.59:443…
  • TCP_NODELAY set
  • Connected to play.dhis2.org (34.243.233.59) port 443 (#0)
  • ALPN, offering h2
  • ALPN, offering http/1.1
  • successfully set certificate verify locations:
  • CAfile: /etc/ssl/certs/ca-certificates.crt
    CApath: /etc/ssl/certs
  • TLSv1.3 (OUT), TLS handshake, Client hello (1):
  • TLSv1.3 (IN), TLS handshake, Server hello (2):
  • TLSv1.2 (IN), TLS handshake, Certificate (11):
  • TLSv1.2 (IN), TLS handshake, Server key exchange (12):
  • TLSv1.2 (IN), TLS handshake, Server finished (14):
  • TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
  • TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
  • TLSv1.2 (OUT), TLS handshake, Finished (20):
  • TLSv1.2 (IN), TLS handshake, Finished (20):
  • SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
  • ALPN, server accepted to use h2
  • Server certificate:
  • subject: CN=play.dhis2.org
  • start date: Nov 5 02:01:55 2020 GMT
  • expire date: Feb 3 02:01:55 2021 GMT
  • subjectAltName: host "play.dhis2.org" matched cert’s "play.dhis2.org"
  • issuer: C=US; O=Let’s Encrypt; CN=Let’s Encrypt Authority X3
  • SSL certificate verify ok.
  • Using HTTP2, server supports multi-use
  • Connection state changed (HTTP/2 confirmed)
  • Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
  • Server auth using Basic with user ‘admin’
  • Using Stream ID: 1 (easy handle 0x5564c1f0df20)
    > POST /2.35.0/api/events.csv?skipFirst=true&dryRun=false&payloadFormat=csv HTTP/2
    > Host: play.dhis2.org
    > authorization: Basic YWRtaW46ZGlzdHJpY3Q=
    > user-agent: curl/7.68.0
    > accept: /
    > content-type:application/csv
    > content-length: 806
    >
  • Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
  • We are completely uploaded and fine
    < HTTP/2 200
    < server: nginx/1.17.10
    < date: Wed, 25 Nov 2020 13:09:08 GMT
    < content-type: application/json;charset=UTF-8
    < content-length: 877
    < set-cookie: JSESSIONID=186AB380AE0F47BA77888B42BC5C5C82; Path=/2.35.0; SameSite=Lax; Secure; HttpOnly
    < x-content-type-options: nosniff
    < x-xss-protection: 1; mode=block
    < x-frame-options: SAMEORIGIN
    < strict-transport-security: max-age=15768000
    <
  • Connection #0 to host play.dhis2.org left intact

Post request response:
{
“httpStatus”: “OK”,
“httpStatusCode”: 200,
“status”: “OK”,
“message”: “Import was successful.”,
“response”: {
“responseType”: “ImportSummaries”,
“status”: “SUCCESS”,
“imported”: 0,
“updated”: 0,
“deleted”: 0,
“ignored”: 0,
“importOptions”: {
“idSchemes”: {},
“dryRun”: false,
“async”: false,
“importStrategy”: “CREATE_AND_UPDATE”,
“mergeMode”: “REPLACE”,
“reportMode”: “FULL”,
“skipExistingCheck”: false,
“sharing”: false,
“skipNotifications”: false,
“skipAudit”: false,
“datasetAllowsPeriods”: false,
“strictPeriods”: false,
“strictDataElements”: false,
“strictCategoryOptionCombos”: false,
“strictAttributeOptionCombos”: false,
“strictOrganisationUnits”: false,
“requireCategoryOptionCombo”: false,
“requireAttributeOptionCombo”: false,
“skipPatternValidation”: false,
“ignoreEmptyCollection”: false,
“force”: false,
“firstRowIsHeader”: true,
“skipLastUpdated”: false,
“mergeDataValues”: false,
“skipCache”: false
},
“importSummaries”: [],
“total”: 0
}
}

1 Like

Resolved :slight_smile:. We need to replace -d by --data-binary in the curl command:

curl --data-binary @events-6.csv 
"https://play.dhis2.org/2.35.0/api/events.csv?skipFirst=true&dryRun=false&payloadFormat=csv"
 -H "Content-Type:application/csv" -u "admin:district" -v