Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This document describes the mechanism via the REST API method with using curl commands. You can use what programming language you are familiar with to implement the API usage.

Request and implement credential

First time request

If you are not an API user yet, and plan to automate your file handling processedprocess. Then please request an API credential from WMDA support team to email support@wmda.info. And please follow steps below:

  1. Send email to support@wmda.info with a PGP/GPG public key.  Or if you have other secure way to communicate the credential, please identify that in the email. Below we provide guide how can you generate PGP public key
  2. WMDA will provide you the credential and send email to notify you.
  3. You test the credential is working and can call endpoint in sandbox system. You can follow the steps below at "Implementation of Generating Bear Token" and  "Using the REST API" to test the credential:
    1. Implement the credential.
    2. Refresh Bear upload user guide below.


Note

For migration from legacy Data Upload system to Data Manager, if you are already an API user for legacy Data Upload system, then you need only take action of step 3 , WMDA will send out email to notify about the credential for Bear Token.


Guide to generate PGP/GPG key:

  • Use windows based tool Kleopatra

Expand
titleClick here to expand: The user guide to generate public key using Kleopatra

After install Kleppatra, follow steps below:

  1. Generate key pair: In File→New OpenPGP Key Pair . Please use the "Advanced Settings" to use at least RSA 2048 bits  + RSA 3072 as the algorithm. 
    Image Added









    Image Added

    Image Added

  2. After generate the key, click on the key that you generated, and a new window will be open.
    Image Added


  3. Click on the "Export" button. To review the public key that generated. It will be something like below.
    Image Added

  4. Please keep the secret key safe to decrypt the file that WMDA will send back.



Implementation of Generating Bear Token

Data Manager uses Bear Token for the authorization as all WMDA API services, please follow user guide for API authentication to implement https://share.wmda.info/x/8I7RFw.

Update credential because of expiration

WMDA API credential is only available for one year currently. If your credential is expired, please send to WMDA support team to request a new one. 
Currently, WMDA is implementing a new feature to let API user to request a new credential by themselves before the credential expires, we will send announcement when this feature is available.

Refresh Bear Token

Using the REST API

To get more knowledge for usage of curl, we recommend member to read the doc for curl   https://ec.haxx.se/usingcurl-netrc.html

Data Manager API specification is in the swagger doc: https://apispecs.wmda.info/?urls.primaryName=Data%20Manager%20Data%20Exchange%20API


Below is an example to guide how to list ion(s) that you have access:There are 2 steps 

Step 1: Request the credential from WMDA if you are not a API user yet.Set up the credential by following the instruction above in the "Implementation of Generating Bear Token" 

Step 2: Test to use the API in WMDA Data Manager sandbox.
            You can use the API doc in swagger: https://brave-forest-04a379103.azurestaticapps.net/?urls.primaryName=Data%20Manager%20Data%20Exchange%20API#/

Step 3: Implement the API.

If you are already familiar with the API  implementation, then you can skip Step 2, and test from your own implementation.

Below is an example to guide how to get the information to upload a file:

URL
SERVER URL

sandbox Sandbox system: https://sandbox-datamanager-api.wmda.info

Production system: https://datamanager-api.wmda.info (Only process the file after get clean notification from WMDA)

URI

/api/v1/filesions/uploadlist

METHODPOST
Full URL path example

For donor for organization with ION-1234, the full path is as below:

https://sandbox-datamanager-api.wmda.info/api/v1/filesions/uploadlist

Request formbody
no request body needed
HEADER

Authorization and Content-Type are required, the other ones are optional

AuthorizationBear Token

Upload

Below is suggestion for curl call based on the swagger doc

Content-Type
application/json

Step 3:

Run curl call as below to get the ion(s) you have access.  You may get one or multiple ions based on your access permission.
"-i" option can be used to check the details of the communication if something go wrong.

Code Block
titleData Manager API ion list linux
curl -i 'https://sandbox-datamanager-api.wmda.info/api/v1/ions/list' \
--header 'Authorization: Bearer ••••••' \
--header 'Content-Type: application/json'


For windows user, please use double quote instead single quote for the reqest:

Code Block
titleData Manager API ion list for windows
curl -i "https://sandbox-datamanager-api.wmda.info/api/v1/ions/list" \
--header "Authorization: Bearer ••••••" \
--header "Content-Type: application/json"

Upload

Below is a suggestion for curl call based on the Data Manager swagger doc to upload a file for an ION. 

Code Block
titleData Manager API file upload
curl
Code Block
titleInvalid after update from Oct, 27, 2022
curl -i POST --location 'https://sandbox-datamanager-api.wmda.info/api/v1/files/upload' \
--header 'Authorization: Bearer ••••••' \
--header 'Content-Type: multipart/form-data' \
--form 'file=@c:@/path/to/file/ION-0999-D.gpg' \
--form 'ion="9999"' \
--form 'folder="upload"'


Something to be aware of for windows based cmd:

  1. please use double quote instead single quote for the request.
  2.  Line break "\" dose not work, so use the curl script in one line, or use specific break that works for your script.
  3. Use "\" to escape the double quote for the value.
  4. The path separator for the file dose not matter, both Linux used "/" and windows used  "\" works.
Code Block
titleData Manager API file upload windows
curl "https://sandbox-datamanager-api.wmda.info/api/v1/files/upload" --header "Authorization: Bearer ••••••" --header "Content-Type: multipart/form-data" --form "file=@C:/path/to/file/ION-0999-D.gpg" --form "ion=\"9999\"" --form "folder=\"upload\""

Download

Download reports

You may use the API also to fetch your reports . And you may need 2 steps are needed
For windows based cmd syntax, please see the example in the "Upload" part.

1.Fetch the files list and get the file names.

Use the following curl and endpoint file list API to fetch an array of file list for the folder "report"report:

Code Block
titleData Manager API file list
curl curl --location 'https://sandbox-datamanager-api.wmda.info/api/v1/files/list' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ••••••' \
--data '{
  "ion": 9999,
  "folder": "report"
}'

...

2.  Fetch all the reports or the one you need.

Use the file download API to download the file you needed. You can only download one file a time. 

Code Block
titleData Manager API file download
curl --location 'https://sandbox-datamanager-api.wmda.info/api/v1/files/download' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ••••••' \
--data '{
  "ion": 9999,
  "folder": "report",
  "fileName": "ION-0999-C.gpg<filename>.txt"
}'

In RESTLET :

...

 \
--output <filename>.txt


Image Removed

Response should be 200:

Image Removed

Download full dataset

For those registries that are permitted to use the full dataset the statement below will fetch that. Please change the ION workspace to match your ION.You can download the file in the folder "download"

Code Block
titleData Manager API file download
curl https://sandbox-datamanager-api
Code Block
curl -O GET -H "Authorization:Basic .............." 'https://dataupload.wmda.info/api/v2v1/io/downloads/ION1804/bmdw4data.zip.gpg' -o 'wmda_data_v22.zip.gpg'

In windows cmd, the -o dose not work, and the cmd is as below:

Code Block
curl -H "Authorization:Basic .............." "https://dataupload.wmda.info/api/v2/io/downloads/ION1804/bmdw4data.zip.gpg" > wmda_data_v22.zip.gpg 

We noticed sometimes the download maybe terminated because of some temp network limitation, and the "-C -" option can be used to continue the download.
-v is for more details of the track info

Code Block
curl -v -H "Authorization:Basic .............." -o 'files/download \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ••••••' \
--data '{
  "ion": 9999,
  "folder": "download",
  "fileName": "wmda_data_v22.zip.gpg'"
} \
-C - 'https://dataupload.wmda.info/api/v2/io/downloads/ION1804/output wmda_data_v22.zip.gpg' 

FAQ

Question : My report states : File could not be processed due to a file decryption error, when using the API upload? Why?

Answer :

...

The Dataupload's API endpoint /io streams file(s) directly to the workspace. We have detected that premature file pickups may occur and attempt to move/delete files while content is still being appended or processed. We have taken actions to reduce this behaviour by decreasing the frequency for file pickup which in turn does lower the chance for premature pick. We have also implemented gpg error validation to check integrity based on its messages.

Note: Files are picked from the workspaces for processing every 10 minutes. And file will only picked up if it is not updated for 5 mins.

Some key messages:

  • Known internal gpg messages for corrupted files during API uploads: "invalid packet", "invalid encoding" and "failed". 
  • Report message that uploader users would receive in case of corrupted gpg file upload:   File could not be processed due to a file decryption error. Please make sure file is properly encrypted. 


Guide for troubleshooting of API usage

Q: I get 401 error when using endpoint?

A: This means you do not have access to the endpoint or you did no provide the token correctly. Please double check whether you have extra space or miss space for the parameter "Authorization: Bearer <token>". And if you confirm that and still get 401, please contact support@wmda.info.

Q: I see 403 error for endpoint upload/download, what is next step?

A:  If you can call the endpoint of ions/list, and then get 403 error for upload/download, most possible is because the request body is invalid. Please double check whether any single or double quote or options are wrongly used

...

.