Skip to content

PUT method; raw JSON values; 201 status responses #5

@RandomEtc

Description

@RandomEtc

Hopefully I can follow up with a patch soon but I wanted to let you know about the errors I'm seeing...

In the LinkedIn developer documentation for JSON API usage at https://developer.linkedin.com/documents/api-requests-json there are some examples of translating XML to JSON for API request payloads.

The API request I'm using is a PUT to /people/~/network/updates/key={ID}/is-liked - this requires adapting linkedin_client.js to allow a PUT or a POST where it currently only allows POST, and to choose the correct method on the OAuth client instance.

To PUT a new is-liked value to LinkedIn you are required to send just true as the body of the HTTP request. This means that sending the params object, even with other parameters deleted, is not sufficient. I ended up detecting this case specifically and setting isLiked on my parameters object, but it seems like splitting the token parameters from the API payload would be a smarter approach. I'll look at this next.

Anyway, here's what I ended up with in linkedin_client.js:

    } else if (method.toUpperCase() === 'POST' || method.toUpperCase() == 'PUT') {
      return CLIENT.oauth[method.toLowerCase()](
        _rest_base + path
      , token.oauth_token
      , token.oauth_token_secret
      , JSON.stringify(params.isLiked ? true : params)
      //, 'application/json; charset=UTF-8'
      , 'application/json'
      , requestCallback(callback)
      );
    }

I'm not 100% certain that specifying the charset was causing problems - I'll confirm before submitting a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions