How to Request Direct Sponsored Content Poster Role in Linkedin API?

Viewed 170

I am getting a 404 Error when I try to make the GET request to make a member a Direct Sponsored Content Poster Role on an Organization.

So following the sample here, I am using the organization ID and I am using the person that I want to add ID to the URL request. So my code looks like this:

    sendRequest(GET, "https://api.linkedin.com/v2/organizationAcls/" + URLEncoder.encode("(organization:urn:li:organization:" + organization + ",role:DIRECT_SPONSORED_CONTENT_POSTER,roleAssignee:urn:li:person:" + roleAssignee +")" , StandardCharsets.UTF_8.toString()), null);

With the sendRequest method:

    public String sendRequest(String method, String url, String parameters) throws ExternalApiException, IOException{
    URL obj = new URL(url);
    HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

    // add request header
    con.setRequestMethod(method);
    
    con.setRequestProperty("Authorization", "Bearer " + token);
    if (method == POST) 
        //Removed POST logic as its irrelevant
    int responseCode = con.getResponseCode();

    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();

    return response.toString();
}

Lastly, an example of the URL post-encodement is as follows, with organization = 1234567 AND roleAssignee = abcDEfg:

https://api.linkedin.com/v2/organizationAcls/%28organization%3Aurn%3Ali%3Aorganization%3A1234567%2Crole%3ADIRECT_SPONSORED_CONTENT_POSTER%2CroleAssignee%3Aurn%3Ali%3Aperson%3AabcDEfg%29

Update 1 (11/10/2020): Wanted to add the response body that was returned as well. As mentioned the error code is 404 and the response body returned was:

{"serviceErrorCode":0,"message":"Resource organizationAcls does not exist","status":404}
1 Answers

So I spoke with a Linkedin Technical Support member and it appears there is an error in their documentation.

The correct call requires a PUT request.

Additionally, the URL for the request is: https://api.linkedin.com/v2/organizationAcls/(organization:urn%3Ali%3Aorganization%3AXXXXXXX,role:DIRECT_SPONSORED_CONTENT_POSTER,roleAssignee:urn%3Ali%3Aperson%3AXXXXXXX). Where the 'XXXXXXX' needs to be the associated organization id and the associated person id.

Lastly, as part of the request, a request body needs to be passed in. The request body is a JsonObject that contains the following properties.

  1. state
  2. role
  3. roleAssignee
  4. organization

For state, the only possible value is REQUESTED. For role, the only possible value is DIRECT_SPONSORED_CONTENT_POSTER. For role assignee, it is "urn:li:person:" + roleAssignee, the id of the user you wish to use add to the below organization. Lastly, for the organization, it is "urn:li:organization:" + organization, the id of organization you wish to add the above user to.

Related