Skip to content

Unable to get Webhook's response in message #119

Description

@akanshaaa19

Summary

Problem Statement

Unable to retrieve and display data from a webhook's JSON response in messages.

User Expectations

The user expected to access specific values from the JSON response, such as village and state names, and display them in a message.

What Actually Happened

Instead of retrieving the specific values, the messages returned the variable names as plain text, not resolving to the intended data.

Reproduction Steps

  1. Use the provided API that returns the following JSON response:
    {"text":[{"type":"Village","name":"Jabalpur (M Corp. + OG) (Part)"},{"type":"State","name":"Madhya Pradesh"}]}
  2. Set the result name in the webhook node as api_location.
  3. Attempt to access values in a message using:
    Village: @results.api_location.text[0].name
    State: @results.api_location.text[3].name
    
  4. Observe the message showing unresolved variable names instead of actual values.

Error Messages

No specific error messages were mentioned, but the output showed unresolved variables and plain text instead of expected data.

Additional Notes

The user's JSON response from the webhook returns data organized under a "text" array, which may require restructuring in the API to allow proper indexing as per the platform's requirements.

Source

Original message

Hi,
I've been working on a flow that uses an api to get the location info using the user's location.
In the webhook logs, I can see the response json:

{"text":[{"type":"Village","old_lid":"NA","name":"Jabalpur (M Corp. + OG) (Part)","lgd":"","id":"IO00883742"},{"type":"Sub district","old_lid":"NA","name":"Jabalpur","lgd":null,"id":"IO00000886"},{"type":"District","old_lid":"NA","name":"Jabalpur","lgd":null,"id":"IO00000497"},{"type":"State","old_lid":"NA","name":"Madhya Pradesh","lgd":null,"id":"IO00000004"},{"type":"Block","old_lid":"NA","name":"Jabalpur","lgd":null,"id":"IO00008481"},{"type":"Panchayat","old_lid":"NA","name":"Jabalpur (M Corp. + Og) (Part)","lgd":null,"id":"IO00236475"}],"responseType":"1"}

But I am unable to get this into the messages.
The result name for this webhook node is api_location. I've tried using multiple variables, like:

  • @results.api_location
  • @results.api_location.text
  • @results.api_location.message

Instead of getting the response from the json, they are being sent as plain text, not the variable responses.

Plus, another issue is with the "Update Contacts" node.
I'm trying to save this response into the "Api Location" field of contacts as @results.api_location, but it is being stored as plain text, rather than using the response from the webhook's response json.

Full thread transcript

tanishqt7: Hi,
I've been working on a flow that uses an api to get the location info using the user's location.
In the webhook logs, I can see the response json:

{"text":[{"type":"Village","old_lid":"NA","name":"Jabalpur (M Corp. + OG) (Part)","lgd":"","id":"IO00883742"},{"type":"Sub district","old_lid":"NA","name":"Jabalpur","lgd":null,"id":"IO00000886"},{"type":"District","old_lid":"NA","name":"Jabalpur","lgd":null,"id":"IO00000497"},{"type":"State","old_lid":"NA","name":"Madhya Pradesh","lgd":null,"id":"IO00000004"},{"type":"Block","old_lid":"NA","name":"Jabalpur","lgd":null,"id":"IO00008481"},{"type":"Panchayat","old_lid":"NA","name":"Jabalpur (M Corp. + Og) (Part)","lgd":null,"id":"IO00236475"}],"responseType":"1"}

But I am unable to get this into the messages.
The result name for this webhook node is api_location. I've tried using multiple variables, like:

  • @results.api_location
  • @results.api_location.text
  • @results.api_location.message

Instead of getting the response from the json, they are being sent as plain text, not the variable responses.

Plus, another issue is with the "Update Contacts" node.
I'm trying to save this response into the "Api Location" field of contacts as @results.api_location, but it is being stored as plain text, rather than using the response from the webhook's response json.

Glific AI doc bot (bot): Hey! Could you please share the name of the flow you’re working on?

A quick check: Glific expects webhook results to be used as @results.<result_name>., and the webhook must return a JSON object keyed by the values you want to reference (not a bare array) . Since your API returns an array under text, Glific can’t index into that array in message variables; the usual approach is to flatten the response in your API (e.g., return state, district, city as top-level keys), then use @results.api_location.state, @results.api_location.district, etc., similar to the geolocation example where keys like state/city are directly accessible as @results.loc.state/@results.loc.city . Also confirm the webhook node type: if you used Function for a custom API, Glific stores the response as a string (not parsed JSON), so @results.api_location.text won’t resolve—switch the webhook to POST/GET so keys map into @results, or have your function return structured keys as documented . For Update Contacts, point to a specific key (e.g., Api Location = @results.api_location.state) rather than @results.api_location, otherwise it will save as plain text/object string . Finally, make sure the Send Message/Update Contact nodes come after the webhook node and the result name matches exactly; unresolved variables will print literally (see notes on flow vs contact variables and naming) .

Helpful references:

Glific AI doc bot (bot): Was this helpful in resolving your query? Or do you need further support?

sangeetamishra._91310: <@1118236242119761941> Could you please help us with your Organisation Name ? And also please check the above response shared by the BOT ans try implementing it and let us know if you get stuck anywhere.

tanishqt7: Hi <@1132952719586492478>
My organization's name is INREM Foundations.
I tried implementing the suggestions by the bot, but they still don't seem to work for me.

I'll try a couple of other modifications and let you know if the issue persists.

Thanks

sangeetamishra._91310: I would suggest you to check the documentation link shared as that would be more beneficial to see the steps and follow.

sangeetamishra._91310: <@1118236242119761941> -Were you able to try the steps checking the documentation ?

tanishqt7: Hi,
Sorry I couldn't try them yesterday. I will be working on them today, and let you know..
Thanks.

sangeetamishra._91310: Sure, please do let us know.

tanishqt7: Hi, i've tried using other variables but none seem to work.

So, we are using an api from indiaobservatory.org.in, and their api returns values like this:

{"text":[{"type":"Village","old_lid":"NA","name":"Jabalpur (M Corp. + OG) (Part)","lgd":"","id":"IO00883742"},{"type":"Sub district","old_lid":"NA","name":"Jabalpur","lgd":null,"id":"IO00000886"},{"type":"District","old_lid":"NA","name":"Jabalpur","lgd":null,"id":"IO00000497"},{"type":"State","old_lid":"NA","name":"Madhya Pradesh","lgd":null,"id":"IO00000004"},{"type":"Block","old_lid":"NA","name":"Jabalpur","lgd":null,"id":"IO00008481"},{"type":"Panchayat","old_lid":"NA","name":"Jabalpur (M Corp. + Og) (Part)","lgd":null,"id":"IO00236475"}],"responseType":"1"}

Now, in the call webhook node, i've set the result name as api_location, which also shows By naming the result, you can reference it later using @results.api_location.

But I've tried so many variable names, but none seem to work. They are just being returned as plain text.

I am also trying to update the contact too, where I've created a contact variable api_location.
In the update contact node, I've selected Api Location under 'Select what to update', and then entered @results.api_location for the value.

This is was I had in the Send message node:

Your location has been registered.
@contact.fields.api_location
@results.api_location.Village
@api_location

Village: @results.api_location.village
State: @results.api_location.state

@results.location.latitude

And this is what it is returning in the message:

Your location has been registered.
@results.api_location
@results.api_location.Village
@api_location

Village: @results.api_location.village
State: @results.api_location.state

23.1219438

sangeetamishra._91310: <@1118236242119761941> The API response contains a text array, not fields like village or state.
That's why @results.api_location.village and @results.api_location.state aare being returned as plain text.

Try accessing the values from the array instead:
@results.api_location.text[0].name // Village
@results.api_location.text[3].name // State

If that doesn't work, please check the webhook result in the flow logs once.

tanishqt7: Okay, thank you.
Will try this as well and let you know.

tanishqt7: Hi,
I've tried accessing the array values too, but it is still returning them as plain text.

In webhook logs, we are getting the response as before:

{"text":[{"type":"Village","old_lid":"NA","name":"Jabalpur (M Corp. + OG) (Part)","lgd":"","id":"IO00883742"},{"type":"Sub district","old_lid":"NA","name":"Jabalpur","lgd":null,"id":"IO00000886"},{"type":"District","old_lid":"NA","name":"Jabalpur","lgd":null,"id":"IO00000497"},{"type":"State","old_lid":"NA","name":"Madhya Pradesh","lgd":null,"id":"IO00000004"},{"type":"Block","old_lid":"NA","name":"Jabalpur","lgd":null,"id":"IO00008481"},{"type":"Panchayat","old_lid":"NA","name":"Jabalpur (M Corp. + Og) (Part)","lgd":null,"id":"IO00236475"}],"responseType":"1"}

Text we're using in our Send message node:

Your location has been registered.
@contact.fields.api_location
@results.api_location.text

@api_location

Village: @results.api_location.text[0].name
State: @results.api_location.text[3].name

@results.api_location.text[1].name
@results.api_location.text[2].name

@results.location.latitude

And the message it's sending back:

Your location has been registered.
@results.api_location
@results.api_location.text

@api_location

Village: @results.api_location.text[0].name
State: @results.api_location.text[3].name

@results.api_location.text[1].name
@results.api_location.text[2].name

23.1219449

sangeetamishra._91310: <@1118236242119761941> Can you share the flow link will check and get back by tomorrow.

tanishqt7: Thanks.
Here's the link: https://inrem.glific.com/flow/configure/0287b9d1-c25d-4539-8c56-26698e107ed1

sangeetamishra._91310: <@929190799151865956> As discussed in the morning could you please check this
Flow : https://inrem.glific.com/flow/configure/0287b9d1-c25d-4539-8c56-26698e107ed1
node id - 398b

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions