Skip to main content

Download Code Data

Prerequisites

UAT token permissions

The UAT token needs to have access to the following permissions:

  • codes_view

The UAT token must be set in the header fields of all requests as described in Authentication & Tokens.

Download Code Steps

  1. Call the /codes/download endpoint to generate the code document
  2. Check the document generation status with /documents/<document_key>, document_key is returned from the last API call.
  3. Generate download link with /documents/<document_key>/get-download-link.
  4. Open the generated link in browser, or use python package requests, or download the document with generic download tools like curl, wget.

API references

Generate code document

GET /api/v2/codes/download/

parameters

ParameterRequired?DescriptionExample
campaignoptionalCampaign ID1234
brandsoptionalBrand ID1234
productsoptionalProduct ID (not SKU)1234
workorderoptionalWorkorder ID1234
activated_atoptionalSCM activation datetime (ISO format) or range (comma seperated)2018-12-21, 2018-12-21T00:00:00Z, or 2018-01-01,2019-01-01
updated_atoptionalSCM update datetime (ISO format) or range (comma seperated)2018-12-21, 2018-12-21T00:00:00Z, or 2018-01-01,2019-01-01
statusoptionalinactive=0, active=1, blacklisted=20, 1, or 2
blacklistedoptionalinactive=0, active=1, blacklisted=2true or false
statusoptionalinactive=0, active=1, blacklisted=21
scm_*optionalAny SCM field as parameter, scm field value as valuescm_case_number=1234
serial_numberoptionalserial number of the codeabcdefgh
extended_idoptionalextended ID of the codeabcdefghijkl
activated_byoptionalID of the user that activated the codes1234

API call example

  • GET /api/v2/codes/download/?workorder=1234
  • GET /api/v2/codes/download/?campaign=1234
  • GET /api/v2/codes/download/?activated_at=2024-01-01,2024-02-01&scm_product_country=US&campaign=1234

Response example

{
"document": {
"key": "pq2sd90uh269",
"task": "b'rq:job:2a175027-ad94-41d2-81f1-c57365391e76'"
}
}

How to find your campaign ID

  1. Log on to the portal and click on CAMPAIGNS in the left hamburger menu
  2. On the campaign for which you want to download the data, click the DASHBOARD icon
  3. When the dashboard opens, the URL in the browser will show https://portal.scantrust.com/#/dashboard?tabIndex=0&campaignId=126&page=1
  4. The campaign-id needed is in the value of the parameter campaignId=

How to find your campaign SCM Field Keys (optional)

  1. Log on to the portal and click on CAMPAIGNS in the left hamburger menu
  2. On the campaign for which you want to download the data, click the OPTIONS icon
  3. Click the SCM T&T tab
  4. From the right pabel, copy the keys of each of the active fields (in brackets behind the label).
  5. Use these keys to filter the code-search if required

Check document generation status

GET /api/v2/documents/<document_key>

Path Parameter: document_key should be extracted from the /api/v2/codes/download/ API call response.

Response example

{
"key": "pq2sd90uh269",
"description": "",
"status": "complete",
"category": "code",
"doctype": "search-result",
"related_id": null,
"parameters": {
"workorder": "10917"
},
"error_data": {},
"file_size": 959,
"row_count": 50,
"expires_at": "2024-07-18T08:57:54.448174Z",
"is_expired": false,
"created_at": "2024-07-16T08:57:54.012068Z",
"company": 7472,
"owner": 11014,
"created_by": 11014
}

GET /api/v2/documents/<document_key>/get-download-link

path Parameter: document_key should be extracted from the /api/v2/codes/download/ API call response.

The response will contain a secured download link to the search result CSV file:

Response Example

{
"link": "https://api.staging.scantrust.io/api/v2/documents/download/yNKtdRwgAdLYUTKMLSOYkJHDGgSBLxUS/"
}

Download the CSV file

When that link is downloaded, the server will send a response as a 302 - redirect The response sends the client to the CSV file in the Scantrust Amazon S3 bucket

Note: After following the link, the download link becomes invalid. Please ensure the download happens as soon as possible after generating the link

Note:

  • the CSV file is compressed in zip-format and needs to be unpacked
  • the CSV file is formatted as comma-separated double-quoted with header.

Response (200): Status OK

Example CSV:

"extended_id","serial_number","brand","product","sku","status","blacklist_reason","scm_updated_by","scm_updated_at","activated_by","activated_at","workorder_id","farm_name","organic","harvest_date","sent_to_plant","plant","sell_by_date","temp_humid_in_ph","shipped_from_plant","arrived_in_dc","dc_name","temp_humid_in_dc","shipped_from_dc","case_number"
"D7BDCA03B80610826432DAD3","","American Pork","Pork","259052703982","active","none","","","","","3413","","","","","","","","","","","","",""
"DE8429F00C043SMPHGG3SCE54D3DBE2","","American Pork","Pork","259052703982","active","none","","2019-06-14T09:35:08.207234+00:00","jelle@test.com","2020-02-13T08:43:54.256017+00:00","3414","","","","","","","","","","","","",""
"F628FC48BC043SMPHGG3S4E54681B26","","Queen Victoria","Lettuce","060556200408","active","none","j@test.com","2018-06-14T20:03:33.627564+00:00","","","3414","Aliso Farms","No","2018-06-14","2018-06-14","Packaging Plant 1","2018-06-14","36°F 95%","2018-06-15","2018-06-15","UST","36° 95%","2018-06-16","52C3F83EAA043SMPHGG3S9E4483193F"
"70E19832F1043SMPHGG3S64644B7B66","","American Pork","Pork","259052703982","active","none","j@test.com","2018-06-13T23:21:40.214562+00:00","","","3414","Aliso Ranch","No","2018-06-14","2018-06-14","Processing Plant 1","2018-06-21","36°F 85%","2018-06-15","2018-06-15","UST","36°F 85%","2018-06-15","FD27177428043SMPHGG3S2824AA697A"
"4324CAC06E043SMPHGG3SF124F8BADE","","Queen Victoria","Lettuce","060556200408","active","none","scmuser@test.com","2018-05-26T17:14:12.055232+00:00","","","3414","ST Test","","","","","","","","","","","",""

For a glossary of all the code fields see Code Data Glossary