# Argument 1 passed to KeyValuePair must be of the type string, int given

**URL:** <https://forum.shopware.com/t/argument-1-passed-to-keyvaluepair-must-be-of-the-type-string-int-given/95554>\
**Category:** Shopware 6 (English)\
**Created:** [30. Juli 2022 um 06:48 UTC](https://forum.shopware.com/t/argument-1-passed-to-keyvaluepair-must-be-of-the-type-string-int-given/95554 "2022-07-30T06:48:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![krjanssen](https://avatars.discourse-cdn.com/v4/letter/k/a88e57/32.png) [@krjanssen](https://forum.shopware.com/u/krjanssen)\
**Post date:** [30. Juli 2022 um 06:48 UTC](https://forum.shopware.com/t/argument-1-passed-to-keyvaluepair-must-be-of-the-type-string-int-given/95554/1 "2022-07-30T06:48:08Z")

</div>

When trying to handle media via the admin api I came across the next exception:  
[Argument 1 passed to Shopware\Core\Framework\DataAbstractionLayer\Write\DataStack\KeyValuePair::\_\_construct() must be of the type string, int given]

If I take a look at the file where the KeyValuePair class is called i see the next code:

```auto
foreach ($originalData as $key => $value) {
    $this->data[$key] = new KeyValuePair($key, $value, true);
}

```

In addition to the fact that the class is deprecated it asks for a `string` $key in the constructor:

```auto
class KeyValuePair
{
    /**
     * @var string
     */
    private $key;

    private $value;

    /**
     * @var bool
     */
    private $isRaw;

    public function __construct(string $key, $value, bool $isRaw)
    {
        $this->key = $key;
        $this->value = $value;
        $this->isRaw = $isRaw;
    }

    public function getKey(): string
    {
        return $this->key;
    }

    public function getValue()
    {
        return $this->value;
    }

    public function isRaw(): bool
    {
        return $this->isRaw;
    }

    public function setValue($value): void
    {
        $this->isRaw = false;
        $this->value = $value;
    }
}

```

Does someone knows how to fix this or how to make sure this deprecated class is not used anymore?

---

<div class="post-metadata">

**Author:** ![abdullah](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@abdullah](https://forum.shopware.com/u/abdullah)\
**Post date:** [30. Juli 2022 um 22:50 UTC](https://forum.shopware.com/t/argument-1-passed-to-keyvaluepair-must-be-of-the-type-string-int-given/95554/2 "2022-07-30T22:50:53Z")

</div>

Have you checked what your IDs look like? Are your IDs all numbers? Then that could be the problem.

I had that problem too. but the error occurred via the storefront.  
The problem for me was that the IDs only consisted of numbers and this was converted to an int in between. And in the end the error you described occurred.

---

<div class="post-metadata">

**Author:** ![krjanssen](https://avatars.discourse-cdn.com/v4/letter/k/a88e57/32.png) [@krjanssen](https://forum.shopware.com/u/krjanssen)\
**Post date:** [30. Juli 2022 um 23:02 UTC](https://forum.shopware.com/t/argument-1-passed-to-keyvaluepair-must-be-of-the-type-string-int-given/95554/3 "2022-07-30T23:02:37Z")

</div>

> [@abdullah](#):
>
> e problem for me was that the IDs only consisted of numbers and this was converted to an int in between. And in the end the error you described occurr

I had this fixed this afternoon, but now I stumble across the same issue but this time from the shopware migration assistent. This struck me as odd, because I did not touched that code at all. I don’t even decide what data is been send.

{"errors":[{"code":"0","status":"500","title":"Internal Server Error","detail":"SwagMigrationAssistant\\Migration\\Premapping\\PremappingChoiceStruct::\_\_construct(): Argument #1 ($uuid) must be of type string, int given

---

<div class="post-metadata">

**Author:** ![p.potharlanka](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@p.potharlanka](https://forum.shopware.com/u/p.potharlanka)\
**Post date:** [13. Oktober 2022 um 11:42 UTC](https://forum.shopware.com/t/argument-1-passed-to-keyvaluepair-must-be-of-the-type-string-int-given/95554/4 "2022-10-13T11:42:29Z")

</div>

Have you found the solution to Argument #1 ($uuid) must be of type string, int given? Having same problem.

Thanks

---

<div class="post-metadata">

**Author:** ![abdullah](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@abdullah](https://forum.shopware.com/u/abdullah)\
**Post date:** [13. Oktober 2022 um 16:22 UTC](https://forum.shopware.com/t/argument-1-passed-to-keyvaluepair-must-be-of-the-type-string-int-given/95554/5 "2022-10-13T16:22:10Z")

</div>

@p.potharlanka , are you getting the error through the storefront? Say you have a numeric ID and want to do something with it?

Are you accessing the ID with `DomAccess.getDataAttribute`? Then probably here’s the problem. Because `getDataAttribute` parses the ID to an int.  
Attempt to access the attribute differently.

---

<div class="post-metadata">

**Author:** ![p.potharlanka](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@p.potharlanka](https://forum.shopware.com/u/p.potharlanka)\
**Post date:** [14. Oktober 2022 um 12:53 UTC](https://forum.shopware.com/t/argument-1-passed-to-keyvaluepair-must-be-of-the-type-string-int-given/95554/6 "2022-10-14T12:53:05Z")

</div>

> [@abdullah](#):
>
> `DomAccess.getDataAttribute`

Hey thanks for the reply. The error was due to the PHP version which i was using after downgrading to V 8.0, it has resolved.
