# How to retreive Key and Collection after using WriteStorageObjects API

**URL:** <https://forum.heroiclabs.com/t/how-to-retreive-key-and-collection-after-using-writestorageobjects-api/4027>\
**Category:** Game Design\
**Tags:** sdk-unreal\
**Created:** [July 8, 2023, 5:39am UTC](https://forum.heroiclabs.com/t/how-to-retreive-key-and-collection-after-using-writestorageobjects-api/4027 "2023-07-08T05:39:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iroidhdr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/iroidhdr/32/1715_2.png) [@iroidhdr](https://forum.heroiclabs.com/u/iroidhdr)\
**Post date:** [July 8, 2023, 5:39am UTC](https://forum.heroiclabs.com/t/how-to-retreive-key-and-collection-after-using-writestorageobjects-api/4027/1 "2023-07-08T05:39:09Z")

</div>

So I have used both WriteStorageObjects and ReadStorageObjects in my unreal engine project and I am using Nakama Client 2.7.0. I want to assign Key and Value when I read which is working fine with the following code.

void UBackendGameinstance::OnReadStorageObjectsSuccess(const TArray& StorageObjects)  
{  
UE\_LOG(LogTemp, Log, TEXT(“Read success:”));

```
for (auto& objects : StorageObjects) {
	FString key = objects.Key;
	FString value = objects.Value;
	UE_LOG(LogTemp, Warning, TEXT("Object key:%s ,value:%s "), *key, *value);
	this->valReturn.Broadcast(key, value);
}

```

}

I want to implement the same for WriteStorageObjects but it is not working as expected it directly calls the OnError Delegate function.

void UBackendGameinstance::OnWriteStorageObjectsSuccess(const FNakamaStoreObjectAcks& acks)  
{  
UE\_LOG(LogTemp, Log, TEXT(“Success writing storage objects”));

```
for (auto& ack : acks) {
	FString key = ack.key.c_str();
	FString collection = ack.collection.c_str();
	UE_LOG(LogTemp, Warning, TEXT("%s Has been updated in collection: %s"), *key, *collection);
}

```

}

My guess is as you can see in ReadObject it is TArray they use TArray but in WritingObject it is just “const FNakamaStoreObjectAcks&” So I am not sure whether I can loop through the values.

So I want to set the Key and Collection in OnWriteStorageObjectsSuccess. If you guys have any idea how to implement it. It will be very helpful for us.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Albertcleetus](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/albertcleetus/32/603_2.png) [@Albertcleetus](https://forum.heroiclabs.com/u/Albertcleetus)\
**Post date:** [July 8, 2023, 5:51am UTC](https://forum.heroiclabs.com/t/how-to-retreive-key-and-collection-after-using-writestorageobjects-api/4027/2 "2023-07-08T05:51:15Z")

</div>

Please ensure the API request code also here,

---

<div class="post-metadata">

**Author:** ![iroidhdr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/iroidhdr/32/1715_2.png) [@iroidhdr](https://forum.heroiclabs.com/u/iroidhdr)\
**Post date:** [July 8, 2023, 5:55am UTC](https://forum.heroiclabs.com/t/how-to-retreive-key-and-collection-after-using-writestorageobjects-api/4027/3 "2023-07-08T05:55:40Z")

</div>

I have attached the API requested code here

void UBackendGameinstance::setToNakama(const FString key, const FString collection, const FString playerDataInJson)  
{  
FNakamaStoreObjectWrite WriteObject;  
NStorageObjectWrite savesObject;  
savesObject.collection = TCHAR\_TO\_UTF8(\*collection);  
savesObject.key = TCHAR\_TO\_UTF8(\*key);  
savesObject.value = TCHAR\_TO\_UTF8(\*playerDataInJson);

```
if (key.IsEmpty() || collection.IsEmpty())
{
	UE_LOG(LogTemp, Error, TEXT("Invalid collection or key value supplied. They must be set."));
	return;
}

TArray<FNakamaStoreObjectWrite> StorageObjectsData = { WriteObject };

FOnStorageObjectAcks WriteStorageObjectsSuccessDelegate;
WriteStorageObjectsSuccessDelegate.AddDynamic(this, &UBackendGameinstance::OnWriteStorageObjectsSuccess);

FOnError WriteStorageObjectsErrorDelegate;
WriteStorageObjectsErrorDelegate.AddDynamic(this, &UBackendGameinstance::OnWriteStorageObjectsError);

client->WriteStorageObjects(session, StorageObjectsData, WriteStorageObjectsSuccessDelegate, WriteStorageObjectsErrorDelegate);

```

}

---

<div class="post-metadata">

**Author:** ![Albertcleetus](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/albertcleetus/32/603_2.png) [@Albertcleetus](https://forum.heroiclabs.com/u/Albertcleetus)\
**Post date:** [July 8, 2023, 5:58am UTC](https://forum.heroiclabs.com/t/how-to-retreive-key-and-collection-after-using-writestorageobjects-api/4027/4 "2023-07-08T05:58:54Z")

</div>

lot’s of things is different in new 2.7.0 sdk version  
@tom will help, i think

---

<div class="post-metadata">

**Author:** ![iroidhdr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/iroidhdr/32/1715_2.png) [@iroidhdr](https://forum.heroiclabs.com/u/iroidhdr)\
**Post date:** [July 9, 2023, 7:51am UTC](https://forum.heroiclabs.com/t/how-to-retreive-key-and-collection-after-using-writestorageobjects-api/4027/5 "2023-07-09T07:51:39Z")

</div>

We somwhow figured it out. I have attached the solution below check it out for future references

This is changes inside the API Function for WriteStorageObjects

FNakamaStoreObjectWrite WriteObject;  
WriteObject.PermissionWrite = ENakamaStoragePermissionWrite::OWNER\_WRITE;  
WriteObject.PermissionRead = ENakamaStoragePermissionRead::OWNER\_READ;  
WriteObject.Collection = TCHAR\_TO\_UTF8(\*collection);  
WriteObject.Key = TCHAR\_TO\_UTF8(\*key);  
WriteObject.Value = TCHAR\_TO\_UTF8(\*playerDataInJson);

This is OnSuccessDelegate Changes

void UBackendGameinstance::OnWriteStorageObjectsSuccess(const FNakamaStoreObjectAcks& acks)  
{

```
for (auto& ack : acks.StorageObjects) {
	FString key = ack.Key;
	FString collection = ack.Collection;
	UE_LOG(LogTemp, Warning, TEXT("%s Has been updated in collection: %s"), *key, *collection);
}

UE_LOG(LogTemp, Log, TEXT("Success writing storage objects"));	

```

}
