Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create resource returns empty item id #81

Open
Ash-raf10 opened this issue Mar 13, 2023 · 3 comments
Open

create resource returns empty item id #81

Ash-raf10 opened this issue Mar 13, 2023 · 3 comments
Labels
needs info Needs more information.

Comments

@Ash-raf10
Copy link

Whenever I create a new resource/entity I am supposed to get the created resource/entity id in the response but instead I am getting empty({}) response. The response is showing 200 status. Also I checked, the record is indeed getting created in the autotask.

This is the code I am using

public function createContact()
{
    $contact = new ContactEntity(
        [
            'id' => 0, // Autotask requires that new entities have an ID of 0
            'companyID' => 0,
            'firstName' => 'New',
            'lastName' => 'User',
            'isActive' => 1,
        ]
    );
    try {
        $response = $this->autoTaskClient->contacts()->create($contact);
        return response()->json($response);
    } catch (\Exception $exception) {
        return $exception->getMessage();
    }
}

It returned {} only.

@aidan-casey
Copy link
Member

@Ash-raf10 - What is the response on this same request using something like Postman?

@aidan-casey aidan-casey added the needs info Needs more information. label May 24, 2023
@miltechnz
Copy link

Did you figure this out as I too am having the same issue. I am creating a ticket and then need to go and add time entries to the ticket but dont have a created entity ID.

@miltechnz
Copy link

PS. I figured this out. The "response" returned from the initial query is just the Guzzle stream. You need to call getBody() on the Guzzle response stream to get the actual server response in JSON.

(Credit to - https://stackoverflow.com/questions/30549226/guzzlehttp-how-get-the-body-of-a-response-from-guzzle-6)

So i.e.
...
$response = $client->tickets()->create( $ticket );
$contents = (string) $response->getBody();
echo $contents;
...

$contents will contain a string of the raw json response (like {"itemId":10018}). Obviously not very helpful as a string but this was just for testing. Do with it as you please.

I believe this should be the same for any entity :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info Needs more information.
Projects
None yet
Development

No branches or pull requests

3 participants