Skip to content

Python Script API request payload

Rob Thayer edited this page Apr 4, 2022 · 1 revision

Welcome to the NSA Professional Services GitHub repository. This script is a sample script that reads a Sync.PurchaseOrder BOD and creates an IDM search item API request in json format.

Feel free to use and modify the script to suit your needs


Also included is an ION Script that you can import into your own ION desk scripting application.

Instructions to use the script - createRequest.py:

  1. If you don't already have Python installed, you will need to download and install python from Python.org
  2. You can use the attached Sync.PurchaseOrder.xml to test it out.
  3. If you choose to use a different BOD, you will want to:
  • Download a new BOD to the same directory as the script
    
  • Change the following line in the script to reflect the name of the new file: `def getPO(): with open("Sync.PurchaseOrder.xml") as INPUT:`
    
  • Update the poNo variable to search the correct path in the new BOD
    

The request payload that is generated can be used for an IDM "Items" POST request.

It is valid for:

  • /items/count
  • /items/search
  • /items/search/item/resource
  • /items/search/item/resource/stream
  • /items/search/item/resource/{conversion}
  • /items/search/item/resource/{conversion}/stream

You will also want to change the following values so that your payload is valid when requesting a document from IDM.

This is the document type in IDM

* entity = "Purchase_Order"

This is the attribute name

* keyattr = "Order_Number"

This is the comparison operator

* operator = "="

This variable sets the textSearch value to True or False

* textSearch = False

You can create another function in the DataInput class or reuse the existing function and change the search node

* keyvalue = inputdata.getPO()

Optional

* logicalType = ""

After you are done editing the script you can run it as usual to get the json output payload:

image

Feel free to try it out, change it suit your needs or add it to a project of your own.