fetchURL json results to variables

Hi All,

I have a endpoint/url I’m posting to and results returned using $(fetchURLResultBody) are as below, I did note $(fetchURLResultCode) returns ( * 0: 200 OK response (i.e., a successful HTTP request response))
I want to store the fields inside the json file into separate variables, any pointers?
{
“AccountNumber”:“12345”,
“CrmId”:“855302c1-12bf”,
“HomeNumber”:“0115821155”,
“Message”:null,
“MobileNumber”:“0723625580”,
“Name”:“Test user”,
“Successful”:true,
“WorkNumber”:“0123456789”
}

I have followed this guide , but would make more sense if it came with examples
https://help.brightpattern.com/5.8:Scenario-builder-reference-guide/ScenarioBlocks/FetchURL

Thanks,
Meli

Hi Meli,

If you set the “Scenario variable prefix for JSON data” to store the response body in, you can then access the attributes using standard “.” or “” notation.

Using your example, we can save all of your customer data in a variable named “customer” using the Scenario variable prefix for JSON data option on our fetchURL action.

In a subsequent set variable block you can set AccountNumber equal to “customer.AccountNumber”, set Name equal to “customer.Name” etc.

Hope that helps.

  • Andy

Hi Andy,

Thanks for the reply, i have already tried you recommendation without success, thats normally how i retrieve the data from a json endpoint, if my data stored in variable ‘customer’, just reference this with the fields in the api as you stated customer.name and this would contain the json files information for ‘name’, however this is not working on this api

Only thing thats different on this implementation compared to others done before is that i have to use POST on my FETCHURL instead of doing GET, this is how the developer did it, if i use GET i get function not supported/ no results

Working Scenario:

  • I do a POST to the endpoint and pass the clients cellphone number
  • I get the results back in json e.g store them in customer
  • If i use customer.[api field] , field are blank but the is information if i look in the $(fetchURLResultCode)

Thanks

Interesting. The GET vs POST method doesn’t have any impact here. It’s just the format of the response that we’re concerned with. The only other thing worth checking is whether the response is actually an array of objects. E.g. if it could return multiple customers, then it could be wrapped in an object with square brackets.
If this is the case then you may need to access the first customer record by using [0]. E.g Customer[0].Name.
If you still can’t get it working, I’d recommend raising a support case with the Bright Pattern team.
Good luck!
Andy.

Thanks Andy, response comes back as stated above.

I will try this as this is the logic i was not sure how to reference if multiple accounts/records received, to reference specific one e.g Customer[0].Name.

Tried and the Customer[0].Name did not work, i logged a ticket with BP, will hear what they say,

Thanks again

BP Konstantin was able to assist me with this, turned out to be variables which i used different case naming on, a slip on my side, thanks for the help Andy