Jump to content

Need help making correct string representation of raw value in a json file into my autoit code.


 Share

Go to solution Solved by mistersquirrle,

Recommended Posts

Hi Everyone / Json Masters,

 

May I seek your assistance to help me with my code. My code is able to login and get bearer token but I am unable to make a working string representation of the Json raw data to my script.

My script doesn't give any errors but blank response.

The second snippet is the Json raw data where I am trying to convert to a string to be called as a request to be able to get a proper response / output.

 

_GetToken()

;~ MsgBox(0,"",$sU_Token)

$sBaseurl2 = $url

$oHttp = Objcreate("winhttp.winhttprequest.5.1")
$oHttp.open("POST", $sBaseurl2, False)

$oHttp.SetRequestHeader("Content-Type","application/json")

$oHttp.SetRequestHeader("Authorization", "Bearer " & $sU_Token)

$oHttp.SetRequestHeader("Accept","application/json")

$req = '{busObId: 6dd53665c0c24cab86870a21cf6434ae,&Fields: [6ae282c55e8e4266ae66ffc070c17fa3],&filters: [{fieldId: 9365a6098398ff2551e1c14dd398c466d5a201a9c7,&operator: equals,&value: Incident}]}]}'

;~ $oHttp.Option(4) = 0x3300
$oHttp.Send($req)

$oReceived = $oHttp.ResponseText
$oStatus = $oHttp.Status

$sCanisterVal = $oReceived
Consolewrite ($oReceived)
{
    "busObId": "6dd53665c0c24cab86870a21cf6434ae", //Incident Business Object ID
    //Fields Return
    "Fields": [
        "6ae282c55e8e4266ae66ffc070c17fa3" //Ticket ID
    ],
    "filters": [
        {
            "fieldId": "9365a6098398ff2551e1c14dd398c466d5a201a9c7", //Incident Type
            "operator": "equals",
            "value": "Incident"
        },
        {
            "fieldId": "83c36313e97b4e6b9028aff3b401b71c", //Priority
            "operator": "equals",
            "value": "1"
        },
        //Status
        {
            "fieldId": "5eb3234ae1344c64a19819eda437f18d", //Status
            "operator": "equals",
            "value": "New"
        },
        {
            "fieldId": "5eb3234ae1344c64a19819eda437f18d", //Status
            "operator": "equals",
            "value": "Assigned"
        },
        {
            "fieldId": "5eb3234ae1344c64a19819eda437f18d", //Status
            "operator": "equals",
            "value": "In Progress"
        },
        {
            "fieldId": "5eb3234ae1344c64a19819eda437f18d", //Status
            "operator": "equals",
            "value": "Pending"
        },
        {
            "fieldId": "5eb3234ae1344c64a19819eda437f18d", //Status
            "operator": "equals",
            "value": "Reopened"
        }
    ]
}

 

Link to comment
Share on other sites

  • Solution
22 hours ago, Danp2 said:

I'm having trouble understanding your post.

He's trying to get the JSON in the second snippet into his AutoIt code (first snippet) to send as a request: 

On 2/3/2023 at 9:48 AM, TheOne23 said:

Json raw data where I am trying to convert to a string to be called as a request

At least that's my take on the request.

 

First of all, your JSON is not valid, JSON does NOT support comments, like //Incident Business Object ID. You need to remove all of those. As for then putting the multiline JSON into your script, I recommend that you run the JSON through a minifier, like: https://codebeautify.org/jsonminifier

With the 'comments' removed, it outputs this:

{"busObId":"6dd53665c0c24cab86870a21cf6434ae","Fields":["6ae282c55e8e4266ae66ffc070c17fa3"],"filters":[{"fieldId":"9365a6098398ff2551e1c14dd398c466d5a201a9c7","operator":"equals","value":"Incident"},{"fieldId":"83c36313e97b4e6b9028aff3b401b71c","operator":"equals","value":"1"},{"fieldId":"5eb3234ae1344c64a19819eda437f18d","operator":"equals","value":"New"},{"fieldId":"5eb3234ae1344c64a19819eda437f18d","operator":"equals","value":"Assigned"},{"fieldId":"5eb3234ae1344c64a19819eda437f18d","operator":"equals","value":"In Progress"},{"fieldId":"5eb3234ae1344c64a19819eda437f18d","operator":"equals","value":"Pending"},{"fieldId":"5eb3234ae1344c64a19819eda437f18d","operator":"equals","value":"Reopened"}]}

That should have no issues inserting into AutoIt as long as it's enclosed with a single quote: '

 

Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

Do you meant this:

$req='{"busObId": "6dd53665c0c24cab86870a21cf6434ae","Fields": ["6ae282c55e8e4266ae66ffc070c17fa3"],"filters": [{"fieldId": "9365a6098398ff2551e1c14dd398c466d5a201a9c7","operator": "equals","value": "Incident"}]}'

Saludos

Link to comment
Share on other sites

  • 2 weeks later...

Hi @Danp2,

I am trying to convert the 2nd snippet for the 1st snippet $req variable where the request variable will contain the 2nd snippet to I can get the output coming out of the 2nd snippet. The 2nd snippet it the body of the request where I have hard time how to incorporate it in AutoIT code in my 1st snippet.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...