helpscout / helpscout-api-php

PHP Wrapper for the Help Scout API
MIT License
98 stars 62 forks source link

Get link to conversion, getPrimaryCustomer only working on threads? #234

Closed JonLaliberte closed 4 years ago

JonLaliberte commented 4 years ago

I was in the middle of getting something done last week and it would have been helpful to be able to echo the conversation URLs, but I couldn't figure out how to access them. I unfortunately didn't save any of my attempts since I found a work around (just build the URLs myself since it was only needed during testing), but basically I was trying to do something like the following (note, v2 right now)

` $request = (new ConversationRequest) ->withMailbox() ->withThreads() ->withPrimaryCustomer() ->withWeb();

$filters = (new ConversationFilters())
    ->withMailbox(123)
    ->withFolder(123)
    ->withStatus('open');   
$conversations = $client->conversations()->list($filters, $request);

foreach($conversations as $aConvo){ .... } `

But I kept hitting a wall on how to actually get the web URL, or maybe I misunderstood what "withWeb" would do. I believe I tried getWeb. getUrl, and a few others, but nothing was working.

I was also confused about one other thing... Am I correct that you can't get the customer/primary customer from a conversation, but only from a thread? Using the same code as above, I tried this in the foreach: $aConvo->getPrimaryCustomer(); and $aConvo->getCustomer(); and they always returned null (or an error, I forget now).

bkuhl commented 4 years ago

Hey Jon,

But I kept hitting a wall on how to actually get the web URL

The API provides the URL in metadata, but it's not exposed via the SDK at the moment. The easiest path forward would probably be to build the URL manually.

Using the same code as above, I tried this in the foreach: $aConvo->getPrimaryCustomer(); and $aConvo->getCustomer(); and they always returned null (or an error, I forget now).

Using the same code to fetch a conversation, I tried $conversation->getCustomer()->getId(), $conversation->getCreatedByCustomer()->getId() and the same customer was provided to me on both of these methods with their objects populated with data. I'm not sure why it wouldn't be returning for you. If you can provide me the convoId we can look into that for you.

JonLaliberte commented 4 years ago

Hey Ben,

The API provides the URL in metadata, but it's not exposed via the SDK at the moment. The easiest path forward would probably be to build the URL manually.

Ah hah, I noticed the withWeb on the ConversationRequest somewhere and was just assuming it'd be returned. I was trying to not build the URL myself because in the docs it recommends against it. I shouldn't have been concerned with it though since it was just for testing, but I couldn't help myself.

Using the same code to fetch a conversation, I tried $conversation->getCustomer()->getId(), $conversation->getCreatedByCustomer()->getId() and the same customer was provided to me on both of these methods with their objects populated with data. I'm not sure why it wouldn't be returning for you. If you can provide me the convoId we can look into that for you.

I really wish I knew what I was trying last week that was failing. Tried this just now and it worked perfectly, thanks and sorry for the bother! I know I was having issues getting it from the conversation, but when I tried the thread it was working.

I did leave one thing in my test code that wasn't working. I tested this again just now and it still isn't working. Unless I'm misunderstanding what it should do.

$client = app(\HelpScout\Api\ApiClient::class);
$client->conversations()->publishDraft(1152518271); // This is a real conversation ID for testing
bkuhl commented 4 years ago

I did leave one thing in my test code that wasn't working. I tested this again just now and it still isn't working. Unless I'm misunderstanding what it should do.

publishDraft() is to be used when the entire conversation is in the draft status. In this case, the conversation Closed, but a thread within that conversation is in the draft status. I'm not seeing a way to publish a draft thread via the API, but I'm double checking with the team internally to verify.

JonLaliberte commented 4 years ago

Got it, that makes sense given what I had seen in the docs too. I was confused about there being no publishDraft on threads, so I assumed when done against a convo it just found (the only) draft thread and published it.

This isn't a vital thing I need, so I don't want you having to waste any time on it, it was something I was testing out and which confused me at the time. It may be good to have in the future, but for now I'm not worried about it.

Thanks again for responding, it's appreciated.

bkuhl commented 4 years ago

I double checked with the team, and there's not a way to publish a draft thread via the API at this time.