Repeat values in PAW, POST request - http

I wanted to ask if it is possible to repeat elements in a POST request in PAW and how to do so?
Basically, given the POST request BODY:
[
{ "zip":"DYNAMIC_VALUE" }
]
Can I then repeat this entry multiple times? Let's say I want to repeat this entry in the array 10 times, I would get for example:
[
{ "zip":"1234" },
{ "zip":"2543" },
{ "zip":"6543" },
{ "zip":"7645" },
{ "zip":"2654" },
{ "zip":"7568" },
{ "zip":"5364" },
{ "zip":"1313" },
{ "zip":"5432" },
{ "zip":"5634" }
]
And maybe I want to send an array with 1000 or more objects with a dynamic zip.
How do I do that?
Thank you :)

Related

Here geocode api gives double results

Some API geocode queries return double results when this is not warranted by the real data.
It will return 2 results with slightly different latitude and longitude and different LocationId's.
This makes it difficult if not impossible to decern which one is the correct result.
Example:
https://geocoder.ls.hereapi.com/6.2/geocode.json?apiKey=8888&city=Zutphen&country=NL
Returns:
{
"Response":{..
},
"View":[
{
"Result":[
{
"Relevance":1.0,
"MatchLevel":"city",
"MatchQuality":{
"City":1.0
},
"Location":{
**"LocationId":"here:cm:namedplace:23055957",**
"LocationType":"point",
**"DisplayPosition":{
"Latitude":52.1402,
"Longitude":6.19152**
},
...
},
"Address":{
"Label":"Zutphen, Gelderland, Nederland",
"Country":"NLD",
"State":"Gelderland",
"County":"Zutphen",
"City":"Zutphen",
"PostalCode":"7201",
"AdditionalData":[
{
"value":"Nederland",
"key":"CountryName"
},
{
"value":"Gelderland",
"key":"StateName"
},
{
"value":"Zutphen",
"key":"CountyName"
}
]
}
}
},
{
"Relevance":1.0,
"MatchLevel":"city",
"MatchQuality":{
"City":1.0
},
"Location":{
**"LocationId":"here:cm:namedplace:20201443",**
"LocationType":"point",
**"DisplayPosition":{
"Latitude":52.13764,
"Longitude":6.20777**
},
...
],
"ViewId":0
}
]
}
}

Using Gatsby `createResolvers` to set default image if GraphQL returns null?

I'm working on a gatsby site using gatsby-source-wordpress to source posts for the blog. However, if any of the WordPress posts do not include a featured image this causes the build to fail. I understand that this is expected behavior.
Here is the build error I am seeing:
29 | {posts.map(({ node: post }, index) => (
30 | <li key={post.id} {...post}>
> 31 | <Img fixed={post.featured_media.localFile.childImageSharp.fixed} />
| ^
32 | <p>
33 | <Link to={`/insights/${post.slug}`}>
34 | {post.title}
WebpackError: TypeError: Cannot read property 'localFile' of null
This is caused by the resulting query, which is returning a null result in the second node because there is no featured image on the post:
{
"data": {
"allWordpressPost": {
"edges": [
{
"node": {
"id": "28ec9054-5b05-5f94-adcb-dcbfc14659b1",
"featured_media": {
"id": "f12d613b-e544-560b-a86f-cd0a7f87801e",
"localFile": {
"id": "7fca2893-ff80-5270-9765-d17d3dc21ac2",
"url": "https://www.mycustomdomain.com/wp-content/uploads/2020/01/some-featured-image.jpg"
}
}
}
},
{
"node": {
"id": "91a236ed-39d5-5efc-8bed-290d8344b660",
"featured_media": null
}
}
]
}
}
}
How I would like to fix:
As an ideal solution, I would like to use schema customization to set a default image if there is no featured image in WordPress. But I am at a total loss how to correctly do so. I am working from this documentation to guide me, but I'm just not getting my head wrapped around it properly.
A similar working example:
Tag data is similar to featured images in that the query returns null if the post has no tags. However I am able to set a default undefined tag using createResolvers like so:
exports.createResolvers = ({ createResolvers }) => {
const resolvers = {
wordpress__POST: {
tags: {
resolve(source, args, context, info) {
const { tags } = source
if (tags === null || (Array.isArray(tags) && !tags.length)) {
return [
{
id: 'undefined',
name: 'undefined',
slug: 'undefined',
}
]
} else {
return info.originalResolver(source, args, context, info)
}
},
},
},
}
createResolvers(resolvers)
}
And this works as shown in the following query results:
{
"data": {
"allWordpressPost": {
"edges": [
{
"node": {
"id": "28ec9054-5b05-5f94-adcb-dcbfc14659b1",
"tags": [
{
"id": "undefined"
}
]
}
},
{
"node": {
"id": "91a236ed-39d5-5efc-8bed-290d8344b660",
"tags": [
{
"id": "50449e18-bef7-566a-a3eb-9f7990084afb"
},
{
"id": "8635ff58-2997-510a-9eea-fe2b88f30781"
},
{
"id": "97029bee-4dec-5198-95af-8464393f71e3"
}
]
}
}
]
}
}
}
What I tried for images (isn't working...)
When it comes to nested nodes and image files I'm at a total loss. I am heading in the following direction based on this article and this code example, but so far it isn't working:
exports.createResolvers = ({
actions,
cache,
createNodeId,
createResolvers,
store,
reporter,
}) => {
const { createNode } = actions
const resolvers = {
wordpress__POST: {
featured_media: {
type: `File`,
resolve(source, args, context, info) {
return createRemoteFileNode({
url: 'https://www.mycustomdomain.com/wp-content/uploads/2017/05/placeholder.png',
store,
cache,
createNode,
createNodeId,
reporter,
})
},
},
},
}
createResolvers(resolvers)
}
I realize the above code does not have an if else statement, so the expectation is that all featured images would be replaced by the placeholder image. However the resulting GraphQL query is unaffected (as shown at top).
Can anyone point me in the right direction here? I can't seem to wrap my head around what information I can find out there.
WebpackError: TypeError: Cannot read property 'localFile' of null
'localFile' of null means that nulled is a parent of localfile - featured_media ... you can see that in results:
"featured_media": null
... so you're trying to fix localfile while you should work on featured_media level
why?
You can easily render conditionally [in react] what you need (placeholde, component) on nulled nodes ... why at all you're trying to fix graphql response?

Transfer data from FocusableIframe to block

I want to make a selection in an iframe at the editor and transferring the selection to the element where it will be displayed at the saved page. How do I get the data from the iFrame back to the registered block ?
How do I store these data ?
My current not working code:
blocks.registerBlockType('XXX/XX-block', {
stringToUpdate: {
type: 'string',
},
edit: function(props) {
return (el(components.FocusableIframe, {
src: "https:///....my-iframe.php"
},
}
}),
save: function(props) {
return (el('div', {
className: 'stringToUpdate'
}, 'stringToUpdate'))
}

Google Analytics: Filter by custom dimension

I'm using the enhanced ecommerce tracking from Google Analytics to send data like this in JS to GA:
ga("ec:addImpression", {
brand: null,
dimension2: "shop123",
id: 1,
list: "Search",
name: "Product 123",
position: 1
});
ga("send", "pageview");
Then, I use the Reporting API to generate some charts. Here, I want to filter by my custom dimension dimension2. The request looks like this:
{
"reportRequests":[
{
"dateRanges":[
{
"startDate":"2016-10-17",
"endDate":"2016-11-16"
}
],
"viewId":"132093148",
"metrics":[
{
"expression":"ga:productListViews"
}
],
"dimensions":[
{
"name":"ga:date"
},
{
"name":"ga:dimension2"
}
],
"dimensionFilterClauses":[
{
"filters":[
{
"dimension_name":"ga:dimension2",
"operator":"EXACT",
"expressions":[
"shop123"
]
}
]
}
]
}
]
}
However, this returns no results:
{
"reports":[
{
"columnHeader":{
"dimensions":[
"ga:date",
"ga:dimension2"
],
"metricHeader":{
"metricHeaderEntries":[
{
"name":"ga:productListViews",
"type":"INTEGER"
}
]
}
},
"data":{
"totals":[
{
"values":[
"0"
]
}
]
}
}
]
}
But when I remove the dimensionFilterClauses I get all the results, of course not filtered by dimension2.
Did I anything wrong when filtering for that dimension?
Change your string dimension_name for dimensionName and try.
As you can see in the examples: https://developers.google.com/analytics/devguides/reporting/core/v4/samples
"dimensionFilter":
{
"dimensionName":"ga:browser",
"operator":"EXACT",
"expressions":["Safari"]
}

Elasticsearch - Count distinct

I have a basic index with logs
Some logs are visit of user1 to user2
I managed to count the total of visits a user has received, but I don't know how count the total of distinct users a user has received
This is giving me all the logs for a user
{
"post_filter":{
"bool":{
"must":[
{
"term":{
"message":"visit"
}
},
{
"term":{
"ctxt_user2":"733264"
}
}
]
}
},
"query":{
"match_all":{}
}
}
Actually, I'm using FoSElasticaBundle for Symfony2
$filter->addMust((new Term())->setTerm('message', 'visit'));
$filter->addMust((new Term())->setTerm('ctxt_user2', $this->search->getVisit()));
I read some pages in the ES doc with aggregator, but I never managed to get what I want
Convert to SQL, I just need
SELECT COUNT(DISCTING ctxt_user1)
FROM logs
WHERE ctxt_user2 = 733264
EDIT:
Cardinality seams to be what I need.
Now just need to find how use it with FosElasticaBundle
"aggs": {
"yourdistinctcount": {
"cardinality": {
"field": "ctxt_user1"
}
}
}
Try this query ( not tested...):
{
"query" : {
"bool":{
"must":[
{
"term":{
"message":"visit"
}
},
{
"term":{
"ctxt_user2":"733264"
}
}
]
}
},
"aggs": {
"yourdistinctcount": {
"terms": {
"field": "ctxt_user1"
}
}
}
}
The post_filter query cannot be used in your case. As it write on Elastic.co website: The post_filter is applied to the search hits at the very end of a search request, after aggregations have already been calculated.`
HtH,

Resources