Closed miyamotoh closed 11 months ago
Your XPath is valid, but you should use a colon instead of $xpath.host
{{$xpath:hosts //atom:entry[1]/atom:id}}
You should see an error in the Output Channel. Maybe I should check if variable exists and give a hint for invalid values.
Working example
###
# @name hosts
GET https://rss.golem.de/rss.php?ms=open-source&feed=ATOM1.0
Accept: application/atom+xml
###
# @ref hosts
# @name xpath_test
@xpath_ns atom=http://www.w3.org/2005/Atom
@host = {{$xpath:hosts //atom:entry[1]/atom:id}}
{{
console.info(host)
}}
Ah, great to know that little {{ console.info(host) }}
trick to debug. Thanks, @AnWeber! Perhaps these little debug tricks can be added to the Support > Troubleshooting section of your doc?
Deviating from the topic a bit, now that I'm further into the interaction with my API server, I notice that some return, for example, Content-Type: application/foo.bar.wee.json
, instead of straight application/json
, and the ensuring editor window doesn't give me the "Format Document" menu action (for apparent JSON data). Is there a way you can suggest to fight this?
Oh, never mind. I found @extension
in the doc 🎉 , and that's all I needed for the weird Content-Type
problem!
###
# @name emondata
# @ref login
# @ref energymon
# @extension json
@xpath_ns atom=http://www.w3.org/2005/Atom
GET {{$xpath:energymon //atom:entry[5]/atom:link/@href}}
Accept: application/json
X-API-Session: {{token}}
With this, the response editor window can "format document" as JSON. All set!
Ah, great to know that little {{ console.info(host) }} trick to debug
I fear to spoil a generation of frontend devs, if I say you could debug with console.info
:-). But yeah, I will mention it in my docs.
Did already mention it: https://httpyac.github.io/guide/scripting.html#console
Hi, I admit I'm not very familiar with XPath, but googling around, I came to suspect the below
.http
code might work and get me the first host ID of many that're returned from thehosts
call prior at<feed><entry><id>
in the response XML.However, this
{{host}}
in the GET request remains empty, despite many variants that I've tried (again, I'm no expert). I hope I'm missing something obvious that an expert can point me to. Thanks!!