API: assign opportunity owner

Hi, there is an old unanswered topic Not able to map user to opportunity through API

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.

            $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?

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.

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: https://github.com/infusionsoft/infusionsoft-php/issues/195
Unfortunately there is no reaction on the mentioned issue for almost two weeks.

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

            $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
                    ]]
                ]
            );