Big problem with 2 successive call to api

Hi,

I am currently having a big issue.

I am making this call :

    $dataRepository = Slim::getInstance()->getContainer()["cms.store_location.repository"];
    $this->locations_localization = $dataRepository->getStoresCoordinates();

getStoresCoordinates() creates a query and call the api. All returned data is as expected.

But, juste after in the same events sequence, i make an other call to the api like so:

    $dataRepository = Slim::getInstance()->getContainer()["cms.store_location.repository"];
    $storeBanner = $dataRepository->getStoreVisitBanner($params['name']);

getStoreVisitBanner() creates and other query and make a other call to the api. This call is supposed to returned new data about different fields, but instead return the same data as the first query i made.

I can not figure out why. I displayed the query made in the function getStoreVisitBanner($id) and the query is good, but the returned content is not good.

Every time i try to make 2 successive call to the api, the second call is not returning the expected content.

Please need help!

Thanks

Hi @olivier.castro-perri,

Could you tell us how exactly the response retrieved is not what you’d expect? Also, what is the structure of your queries? (without any credentials, of course)

Hi @gabriel,

I am making a call to retrieve the coordinates of all my stores. So i call this function that makes a call and return all coordinates about all my stores.

public function getStoresCoordinates()
{
$data = [];
$query = $this->getQuery()
->select([“fields.uri”, “fields.coordinates”]);
$stores = $this->getEntries($query);

    if (!empty($stores)) {
        foreach ($stores as $index => $store) {
            $coordinates = $this->getAsset($store, "coordinates");

            $data[$index]["name"] = $store->get("uri");
            $data[$index]["latitude"] = $coordinates["latitude"];
            $data[$index]["longitude"] = $coordinates["longitude"];
        }
    }

    return $data;

}

All data return is perfect and as expected.
Immediately after, i call this function to make an other call to the api:

public function getStoreVisitBanner($id)
{
    $a = [];
    $b = $this->getQuery()
        ->select(["fields.visit_banner"])
        ->where("fields.uri", $id);
    $t = $this->getEntries($b)[0];

    dump($b);
    dump($t);

    if ($t != null) {
        $data = $this->getAsset($t, "visit_banner");
    }

    return $data;
}

the problem is there, making this second call to the api return the same data as the first call i made, even if the query is a new one, querying the field visit_banner of the store content-type.

Query {#894
-include: null
-locale: “en-US”
-limit: null
-skip: null
-contentType: “location”
-mimeTypeGroup: null
-orderConditions: []
-whereConditions: array:1 [:arrow_forward:]
-select: “sys,fields.visit_banner”
-linksToEntry: null
-linksToAsset: null
}

I expect to get field.visit_banner data, but the content is the same as the first call i made…
Entry {#841
#fields: array:2 [▼
“uri” => array:1 [:arrow_forward:]
“coordinates” => array:1 [▼
“en-US” => Location {#836 :arrow_forward:}
]
]
-localeCode: “en-US”
#localeCodes: array:3 [:arrow_forward:]
#client: Client {#21 :arrow_forward:}
#sys: SystemProperties {#833 :arrow_forward:}
}

I made a test and each time i make 2 successives calls to the api, the content of the second call is the same as the first call even if i query on other fields.

Hey @olivier.castro-perri,

would you mind sharing the code of your getEntries and getAsset methods, so we can better understand what’s going on? Before trying to figure out if there’s anything wrong with the SDK, I’d like to have a full picture of your code, thank you!

Davide

Hi,
yesterday we found the problem.

In fact, if we create one instance of the client and we try to make 2 successives calls to the api, the second call returns exactly the same content as the first call no mather the query you give…

But, if each time we want to call the api we create a new instance of the client, then it works…

Is that normal??

Thanks

Hey,

no, it’s definitely not normal. Could I ask you to open a support ticket here, please:

https://www.contentful.com/support/

Mentioning this conversation and asking to be redirected to the PHP SDK developer (myself)? I’d like to rule out possible issues in the SDK. Thank you!

Davide

I opened a ticket ! thanks you for your answer!!