# API: assign opportunity owner

**URL:** <https://integration.keap.com/t/api-assign-opportunity-owner/55187>\
**Category:** API Q&A\
**Created:** [October 21, 2018, 8:36am UTC](https://integration.keap.com/t/api-assign-opportunity-owner/55187 "2018-10-21T08:36:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jared\_Goetz](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jared\_Goetz](https://integration.keap.com/u/Jared_Goetz)\
**Post date:** [October 21, 2018, 8:36am UTC](https://integration.keap.com/t/api-assign-opportunity-owner/55187/1 "2018-10-21T08:36:24Z")

</div>

Hi, there is an old unanswered topic [Not able to map user to opportunity through API](https://integration.keap.com/t/not-able-to-map-user-to-opportunity-through-api/24795)

It seems that it’s still actual. I’m trying to assign an owner to a newly-created opportunity using the latest PHP SDK to no avail.

```auto
            $opportunity = $client->opportunities()->create([
                'opportunity_title' => $data['opportunityTitle'],
                'opportunity_notes' => $data['opportunityNotes'],
                'contact' => [
                    'id' => $data['contactId'],
                    'email' => $data['email'],
                    'phone_number' => $data['phone']
                ],
                'stage' => [
                    'id' => 123
                ]
            ]);

            // so far so good

            $opportunity->user = [
                'id' => 123456
            ]; // does nothing

            $opportunity->setAttribute('user', [
                'id' => 12345
            ]); // still no luck

            $opportunity->save();

```

So the question is, do we have a way to assign opportunity owners by API? PHP SKD docs are a bit thin. Am I missing something?

---

<div class="post-metadata">

**Author:** ![TomScott](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tomscott/32/67_2.png) [@TomScott](https://integration.keap.com/u/TomScott)\
**Post date:** [October 22, 2018, 8:29pm UTC](https://integration.keap.com/t/api-assign-opportunity-owner/55187/2 "2018-10-22T20:29:01Z")

</div>

You should be able to set the user property on the model to the local userId of the intended target in the application; however, you will also need to have the Opportunity \> Can Reassign permission on the context of the user doing the reassignment.

---

<div class="post-metadata">

**Author:** ![Jared\_Goetz](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jared\_Goetz](https://integration.keap.com/u/Jared_Goetz)\
**Post date:** [October 23, 2018, 1:41pm UTC](https://integration.keap.com/t/api-assign-opportunity-owner/55187/3 "2018-10-23T13:41:47Z")

</div>

TomScott thanks for the advice. However, it turns out that the source of the issue is not a lack of permissions, but a bug in IS PHP SDK: [opportunity-\>save() results in 405 "method not allowed" error · Issue #195 · infusionsoft/infusionsoft-php · GitHub](https://github.com/infusionsoft/infusionsoft-php/issues/195)  
Unfortunately there is no reaction on the mentioned issue for almost two weeks.

---

<div class="post-metadata">

**Author:** ![Jared\_Goetz](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jared\_Goetz](https://integration.keap.com/u/Jared_Goetz)\
**Post date:** [October 28, 2018, 9:15am UTC](https://integration.keap.com/t/api-assign-opportunity-owner/55187/4 "2018-10-28T09:15:09Z")

</div>

…in the meantime, there is my workaround using a raw API call:

```auto
            $opportunity = $isoft->opportunities()->create([
                'opportunity_title' => $data['opportunityTitle'],
                'opportunity_notes' => $data['opportunityNotes'],
                'contact' => [
                    'id' => $data['contactId'],
                    'email' => $data['email'],
                    'phone_number' => $data['phone']
                ],
                'stage' => [
                    'id' => 123
                ]
            ]);

            // $http here refers to GuzzlePHP, but any http client will work
            $http->request(
                'PATCH',
                "https://api.infusionsoft.com/crm/rest/v1/opportunities/{$opportunity->id}",
                [
                    'headers' => [
                        'Authorization' => "Bearer {$isoftToken}"
                    ],
                    'json' => ['user' => [
                        'id' => $opportunityOwnerId
                    ]]
                ]
            );

```
