This thread has been locked.

TI-API: Python: Unexpected HTTP status code 500

Part Number: TI-API


Hi, this is David from Performance Motion Devices.

The last question regading Example1.py is solved, thanks for the help! 

I am using Example2.py getting inventory info and placing a test PO. 

When I run it with the ORIGINAL template, the terminal shows two errors, the first error_422 is expected but the second error_500 is not:

1. Because the JSON payload has mock data, it will result in a 422 error.
That means it's working as intended!
WARNING: Unexpected HTTP status code 422.

2. WARNING: Unexpected HTTP status code 500.
Response from server:
{"errors":[{"type":"Unknown","code":"TI-API-00500","reason":"Service unavailable","message":"This service is temporarily unavailable. Please contact support."}]}

Then I modified the input such as CheckoutProfileID, customerPO, company name, etc., and then the second error shows error_503:

1. skipped since error_422 expected.

2. [{"errorCode":"ERR-TICOM-ORDER-API-BOM-0503","type":"Application","section":"Regulation","field":null,"reason":"We are unable to perform the regulations check at this time.","message":"Resubmit your request at a later point in time.","data":null}]}
WARNING: Unexpected HTTP status code 500.
Response from server:
{"errors":[{"type":"Unknown","code":"TI-API-00500","reason":"Service unavailable","message":"This service is temporarily unavailable. Please contact support."}]}  

  • Hi David! :) There may have been some ongoing maintenance when you attempted to make the API call. Can you please reattempt the request, now that some time has passed? Thank you!

  • It still shows Error 500 after days.

    Could you help me to check my code? I might missed something?

    Response from server:
    {"errors":[{"type":"Unknown","code":"TI-API-00500","reason":"Service unavailable","message":"This service is temporarily unavailable. Please contact support."}]}

    Thanks

    David

    from TI_API_Suite import TI_Orders, TI_Inventory
    from API_Accessor import API_Accessor
    
    # Introduction.
    print("---Example 2---")
    print("Here, we will pass our user credentials to access the Orders API and the Inventory & Pricing API.")
    print("This does not require you to manually request and pass an access token,")
    print("because the Python module is designed to abstract this process from you.")
    print("Please change lines 42 and 43 to reflect your user credentials.")
    
    # Store user credentials and server URL address.
    client_id = "PMD_ID"
    client_secret = "PMD_secret"
    server = "https://transact.ti.com"
    verify_ssl = True
    
    # Confirm to user.
    print("\nLogging into {} with ID {}.".format(server, client_id))
    api = API_Accessor(server=server, client_id=client_id, client_secret=client_secret, verify=verify_ssl)
    
    # Print output.
    print("Access token {} retrieved!".format(api.token))
    print("Expires on {}.".format(api.expiration.strftime("%m/%d/%Y at %H:%M:%S")))
    
    # Confirm to user.
    print("\nLogging into Inventory & Pricing API {} with ID {} and secret {}.".format(server, client_id, client_secret))
    catalog = TI_Inventory(server=server, client_id=client_id, client_secret=client_secret, verify=verify_ssl)
    
    # Step 1: Get inventory of the OPN below.
    opn  = "TMS320F28022DAT"
    print("\nFirst, we are using the inventory API to get how many items of OPN {} there are.".format(opn))
    response = catalog.get_product_info(opn=opn, verify=verify_ssl)
    
    # Step 2: View server response.
    print("Response: There are {} of this part available.".format(response.json()["quantity"]))
    
    # Step 3: Post an order to the TI store.
    print("\nNext, we will post a (test) order to the TI store using the Orders API.")
    print("Acquiring access to the API...")
    cart = TI_Orders(server=server, client_id=client_id, client_secret=client_secret, verify=verify_ssl)
    print("Now we can actually send a post request for a (test) order!")
    print("Because the JSON payload has mock data, it will result in a 422 error.")
    print("That means it's working as intended!")
    json = {
        "order": {
            "checkoutProfileId": "[HIDDEN FOR PRIVACY]",
            "customerPurchaseOrderNumber": "PMD123",
            "endCustomerCompanyName":"Performance Motion Devices",
            "expediteShipping":False,
            "customerOrderAttributes": [
                {
                    "message": "MY TEST ORDER"
                }
            ],
            "lineItems": [
                {
                    "customerOrderLineItemNumber": 1,
                    "tiPartNumber": "TMS320F28022DAT",
                    "customerPartNumber": "MY CUSTOM PART NUMBER",
                    "customReelIndicator": False,
                    "quantity": 1,
                    "customerItemComments": [
                        {
                            "message" : "SOME COMMENT GOES HERE"
                        }
                    ]
                },
                {
                    "customerOrderLineItemNumber": 2,
                    "tiPartNumber": "TMS320F28022DAT",
                    "quantity": 1,
                }
            ]
        }
    }
    response = cart.post_order_test(json=json, verify=verify_ssl)
    
    # Step 4: View server response.
    print("Response from server:")
    print(response.text)
    
    # Step 5: Get order details.
    print("\n The order number we will get details for is a mock one!")
    print("Please replace line 108 below with your mock order number.")
    orderNumber = "PMD123"
    response = cart.get_order_details(orderNumber=orderNumber, verify=verify_ssl)
    print("Response from server:")
    print(response.text)
    
    # Conclude.
    print("\nThat's all!")

  • I then tried on TI store test order and got a success 201 response.

    When I copy the Json and past / modified in my python. The python one got error 500.

  • It seems like you are using the customer purchase order number as the input value for getting order details. However, that API call does not work with client-side order numbers; it only works with the TI-side order number which is returned by the post order request. The error thus seems to be resulting from that GET request rather than from the POST request. (i.e., the POST request on line 76 is resulting in 422, while the GET request on line 86 is resulting in 500.)

    You can see where 'orderNumber' is returned here, in the documentation for orderCreateResponse: api-portal.ti.com/store-order-api

    Moreover, it is no longer possible at the moment to retrieve details for test orders. This means that if the GET request were formatted correctly with the order number returned by the POST request response, you would still get a 404 error because the order is a mock one that does not actually exist. I have updated the code in the repository to disable this API call since it is, for the time being, defunct (unless you replace the order number with an actual, non-mock one). I apologize for the inconvenience!

    With respect to the 422 errors, the test order POST request should not result in a 422 error if you have replaced your relevant credentials (client ID, client secret, and checkout profile ID). Would you please send more details about the API call so I can attempt to recreate the issue?

    Thank you!

  • Thank you for this! Can you confirm if it is the first or second API call, in this instance, resulting in the 500? In the previous attempts, the POST call was resulting in the 422 code, while the GET call was resulting in the 500 code. We had commented at the same time so, in case you haven't seen it, please refer to my previous response about the GET call!

  • Hi David! I believe we have found the root of the two error codes.

    Code 422 in the first API call (POST test order, line 76) is a generic error code we send to customers, but the error message is given in the server response! In your case, your error code was that the quantity of parts was so small that the subtotal did not meet the minimum required by your account. The minimum order should be US$1000. Please adjust the quantity of the part you are ordering to meet this minimum.

    And to summarize the previous messages, the 500 code in the second API call (GET order details, line 86) is due to the incorrect order number (using the customer order number instead of the TI order number), but the functionality to retrieve order details for test orders is still in-progress and would result in 404. Please disable this API call in the meantime! We regret the inconvenience, but this ability will be available in the near future.

    Let me know if you are able to get a 201 response for the POST request in Python! Thank you!

  • the full response in my python are attached. 

    Now the first one does show a line of infos and a message of "SUBMITTED" instead of error 422.
    This means the code for placing an order is completed right?

    The second API called has Error 500, which is the defunct one that you mention .

    Logging into https://transact.ti.com with ID PMD_ID_hided.
    Access token PMD_token_hided retrieved!
    Expires on 11/14/2022 at 15:28:18.
    
    Logging into Inventory & Pricing API https://transact.ti.com with ID PMD_ID_hided and secret YgM3NFuICCkuAlm8.
    
    First, we are using the inventory API to get how many items of OPN OPA1677DBVR there are.
    Response: There are 61190 of this part available.
    
    Next, we will post a (test) order to the TI store using the Orders API.
    Acquiring access to the API...
    Now we can actually send a post request for a (test) order!
    Because the JSON payload has mock data, it will result in a 422 error.
    That means it's working as intended!
    Response from server:
    {"orderInfo":{"orderNumber":"T03535234","cartID":"C339045134","checkoutProfileId":"PMD_Info_hided","currencyCode":"USD","orderDate":"2022-11-14T13:28:23Z","orderEntry":"API","customerPurchaseOrderNumber":"PMD125","orderStatus":"SUBMITTED","orderedBy":"David Kao","endCustomerCompanyName":"Performance Motion Devices",......PMD_Info_hided......,"errors":null}
    
     The order number we will get details for is a mock one!
    Please replace line 108 below with your mock order number.
    WARNING: Unexpected HTTP status code 500.
    Response from server:
    {"errors":[{"type":"Unknown","code":"TI-API-00500","reason":"Service unavailable","message":"This service is temporarily unavailable. Please contact support."}]}

  • Yes, that all looks correct! You can even try replacing the order number with the one you have received from the server response, in case you get a 404 rather than a 500. Either way, of course, the call is defunct for the time being.

**Attention** This is a public forum