newrelic-cli icon indicating copy to clipboard operation
newrelic-cli copied to clipboard

[Feature] Generating one.nr short-links for one.newrelic.com URLs

Open ctrombley opened this issue 4 years ago • 3 comments

Copied from newrelic/newrelic-client-go#632 and originally entered by @skyzyx.

Feature Description

Building on #634 : The New Relic One UI has a feature where you can generate a short-link. I would love to see support in this client library for generating the short URL that I can give to my users, which will link them into the New Relic One UI.

I've reverse-engineered the implementation to this:

curl -XPOST \
    https://urly.service.newrelic.com/ \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H "Origin: https://one.newrelic.com" \
    -H "Cookie: login_service_login_newrelic_com_tokens={encoded-json}"
    -d '{"url":"https://one.newrelic.com/xxxxxxx"}' \

Skipping any of these will result in either a 401 (expected) or 500 (unexpected) error. The only way I have been able to figure out how to authenticate is by using the login cookie from my browser (i.e., {encoded-json}) which contains a token that I can't generate from my end.

If there's another way to authenticate that doesn't involve a web browser, that would greatly simplify the implementation.

Describe Alternatives

I can pass the links to a third-party link shortener.

ctrombley avatar Jan 21 '21 16:01 ctrombley

@skyzyx, it looks as if API key authentication is already enabled for this API. You should be able to use your User API key to make a request that looks like this:

curl -XPOST \
    https://urly.service.newrelic.com/ \
    -H "Content-Type: application/json" \
    -H "Api-Key: <USER_API_KEY>" \
    -d '{"url":"https://one.newrelic.com/xxxxxxx"}' \

ctrombley avatar Jan 21 '21 16:01 ctrombley

We are usually hesitant to build around individual APIs, since stitching them into Nerdgraph is the common path for building integrations. Please let us know if the advice above helps you along for now, and we will put this on the backlog for when the stitching happens.

ctrombley avatar Jan 21 '21 16:01 ctrombley

Awesome. Thank you!

Happy to update in the future once integration in Nerdgraph is ready.

skyzyx avatar Jan 21 '21 17:01 skyzyx