nvcnvn
nvcnvn

Reputation: 5175

LinkedIn API call with url encoded

For example, if I make a call to:

https://api.linkedin.com/v1/people/~:(id,first-name,last-name)

It should work fine, but if the URL encoded (and it should be) like this:

https://api.linkedin.com/v1/people/~:%28id,first-name,last-name%29

I get this error message:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
    <status>404</status>
    <timestamp>1423577265744</timestamp>
    <request-id>6B2UQSA25W</request-id>
    <error-code>0</error-code>
    <message>[invalid.property.name]. Couldn&#39;t find property with name {:%28id,first-name,last-name%29} in resource of type {Person}</message>
</error>

How can you deal with that?
Currently I cannot change the code because my language (Golang btw) do very properly encode this with standar package. Here is my code:

r, _ := http.NewRequest("GET", "https://api.linkedin.com/v1/people/~:(id,first-name,last-name)", nil)
r.Header.Set("Authorization", "Bearer "+respBody.AccessToken)
resp, err = http.DefaultClient.Do(r)

Do you have solution for this issue except rewrite std lib code?

Some what face with the same issue since 2013 here https://developer.linkedin.com/forum/edit-i-dont-way-uris-look

Upvotes: 3

Views: 1158

Answers (1)

Thundercat
Thundercat

Reputation: 120941

Set the URL Opaque field to the path after creating the request:

r, err := http.NewRequest("GET", "https://api.linkedin.com", nil)
if err != nil {
  // handle error
}
r.URL.Opaque = "/v1/people/~:(id,first-name,last-name)"
r.Header.Set("Authorization", "Bearer "+respBody.AccessToken)
resp, err = http.DefaultClient.Do(r)

The URL type documentation describes how to do this.

Upvotes: 1

Related Questions