xero-php icon indicating copy to clipboard operation
xero-php copied to clipboard

Setting a customer user-agent

Open leereichardt opened this issue 4 years ago • 7 comments

Previously we were able to do the following

'curl'  => [
    CURLOPT_USERAGENT => $xeroUserAgent,
],

We used this so we can detect which isntance calls were coming from. Is this possible to do with with the updated library?

leereichardt avatar Jun 24 '20 02:06 leereichardt

It's no longer required, but it IS possible. You have to set it on the transport object I think?

But also in the API history, when you click on an entry, it tells you the organisation it came from.

Healyhatman avatar Jun 24 '20 02:06 Healyhatman

Yeah, I did see the possibility of setting the transport object, just checking that was the way to do it. Cheers. I'll finish off the development and get it connected and see where I go from there.

leereichardt avatar Jun 24 '20 03:06 leereichardt

Hmm. Reopening this as I think it would be beneficial to have an option we can send through to set the user agent. We have multiple servers with different customers pointing the same App, so if there were errors coming through, having that quick user agent to tell us where the errors are occurring can sometimes be quite helpful. The attached screenshot is a bit much I think? Screenshot 2020-07-15 10 07 25

leereichardt avatar Jul 14 '20 22:07 leereichardt

You can already do this.

// Reset the Transport to have the correct User-Agent for certification purposes $xero->setTransport($transport = new Client([ 'headers' => [ 'User-Agent' => 'blah blah blah here', // OAuth 2 Client ID 'Authorization' => sprintf('Bearer %s', $access_token), 'Xero-tenant-id' => $tenantID, ] ]));

Healyhatman avatar Jul 15 '20 00:07 Healyhatman

Yeah, I realise that, but that's not exactly the best method here. As soon as any of that changes inside the library, it'll require constant updates

leereichardt avatar Jul 15 '20 00:07 leereichardt

How about we make an update! As long as it ultimately confirms to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent, I think it's a great idea.

P.S. when I first made this library, I was automatically getting the package version and putting it in there, but decided to roll it back because it seemed like an unnecessary overhead. Maybe it's time to make it part of the release pipeline.

calcinai avatar Jul 16 '20 20:07 calcinai

Awesome! Would you rather I try do a PR for this one @calcinai ?

leereichardt avatar Jul 16 '20 20:07 leereichardt