Content Management and Capture

 View Only
Expand all | Collapse all

Datacap 9.1.9 - Use of WsSetResultItem action with JSON Response

  • 1.  Datacap 9.1.9 - Use of WsSetResultItem action with JSON Response

    Posted Fri August 18, 2023 05:02 AM

    Hi,

    I am building a POC which consumes a ChatGPT web service via an API. The response from the API is returned in JSON as opposed to XML. I'm trying to use the WsSetResultItem action from the WebService.Actions library to assign the value from the response that I'm interested in to a field in the DCO, but I'm not having any success.

    Here is an example of the response:

    {
        "id": "cmpl-7opXGx3YaS5ev7cZeYJa5A98ijgzA",
        "object": "text_completion",
        "created": 1692348858,
        "model": "davinci",
        "choices": [
            {
                "text": " -0.8\nThis is a negative tweet, with a negative sentiment score of -0.",
                "index": 0,
                "logprobs": null,
                "finish_reason": "length"
            }
        ],
        "usage": {
            "prompt_tokens": 83,
            "completion_tokens": 20,
            "total_tokens": 103
        }
    }

    What I'd like to do is to capture this value into a field in the DCO:

                "text": " -0.8\nThis is a negative tweet, with a negative sentiment score of -0.",
    

    I have tried various JSON paths in the action, but none of them result in the value being captured into the DCO field, for example:

    WsSetResultItem("$.choices[0],text","@P\Result")

    I'm wondering WsSetResultItem works with JSON responses, or is it just targeted to XML responses? Alternatively, am I doing something wrong with the way I have constructed the Path?

    Many thanks,

    Shaun



    ------------------------------
    Shaun McDowall
    ------------------------------


  • 2.  RE: Datacap 9.1.9 - Use of WsSetResultItem action with JSON Response

    Posted Thu August 31, 2023 07:39 AM

    Hi Shaun,

    WsSetResultItem will not work for JSON response. 

    write a custom action, get the response and push the result to DCO object.

    Regards

    AK



    ------------------------------
    Iva Nakan
    ------------------------------



  • 3.  RE: Datacap 9.1.9 - Use of WsSetResultItem action with JSON Response

    Posted Wed September 06, 2023 12:37 PM

    Hi Iva,

    Many thanks for this. I was able to work around it by putting the contents of the response into a field and then using out of the box actions SplitFieldValuePreserveStart() and SplitFieldValuePreserveEnd() to achieve the desired result. But I agree that a Custom Action would be preferable for Production use.

    Regards,

    Shaun



    ------------------------------
    Shaun McDowall
    ------------------------------