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}