Linked In API article thumbnails - linkedin

I'm trying to migrate existing code that fetches organization posts from ugcPosts API to new versioned call of the Posts API(version 202210) and I'm facing issues with getting thumbnails for articles. Response that I get from Posts API doesn't contain thumbnail URL but instead it contains thumbnail URN(old ugcPost API returned thumbnail URL as a part of the post). Here is an example of an article post that I get from API
{
"isReshareDisabledByAuthor": false,
"createdAt": 1666603988797,
"lifecycleState": "PUBLISHED",
"lastModifiedAt": 1666603988797,
"visibility": "PUBLIC",
"publishedAt": 1666603988797,
"author": "urn:li:organization:1111",
"id": "urn:li:share:2222",
"distribution": {
"feedDistribution": "MAIN_FEED",
"thirdPartyDistributionChannels": []
},
"content": {
"article": {
"description": "some description",
"thumbnail": "urn:li:image:3333",
"source": "https://example.com",
"title": "some title"
}
},
"commentary": "some comment",
"lifecycleStateInfo": {
"isEditedByAuthor": false
}
}
I tried to use Images API to fetch thumbnail URL using a call
GET https://api.linkedin.com/rest/images/urn:li:image:3333
Unfortunately Linked In API responds with code 400 and message Invalid asset owner urn type provided: urn:li:article:4444
I don't get why it happens. Token that I'm using has enough permissions to fetch organization posts(token's scope contains permissions w_member_social, r_liteprofile, r_1st_connections_size, w_organization_social, r_member_social, r_organization_social, rw_organization_admin). Article id that presents in error message isn't anyhow connected to post id. It's also not clear why that asset is referenced as urn:li:article while the post itself is described as urn:li:share. To me it looks like Linked In API bug or am I doing something wrong?

Turns out there was a bug in Linked In API which was confirmed by their support. At this moment same calls work fine with version 202210

Related

Can't create category via WP REST API

I am attempting to create categories via the WordPress REST API but getting the following error:
{
"code": "rest_cannot_create",
"message": "Sorry, you are not allowed to create terms in this taxonomy.",
"data": {
"status": 401
}
}
The REST API user I'm using is an administrator. I've confirmed that I'm authenticating correctly because I can create pages via the REST API.
Here is the JSON I'm submitting to https://hostname.net/wp-json/wp/v2/categories
{
"description":"",
"name": "Test",
"slug": "test",
"parent": 51,
"meta": []
}
I've confirmed that the category with id 51 exists (created that via the UI). The content-type header is set to application/json.
What is the correct syntax to create a new category via the WP REST API?

Getting a 400 Error when doing a simple text post

Trying to migrate our calls away from the v2/ugcPosts endpoint to the new /rest/posts endpoint. I started off trying to create a text-only post as per the Text-Only Post Creation Sample Request
I copied and pasted the request body, changed the organization ID to my own, and included Authorization: Bearer {My Authorization Token}, X-Restli-Protocol-Version: 2.0.0, Content-Type: application/json, LinkedIn-Version:202207 as headers.
POST https://api.linkedin.com/rest/posts
{
"author": "urn:li:organization:***",
"commentary": "Sample text Post",
"visibility": "PUBLIC",
"distribution": {
"feedDistribution": "NONE",
"targetEntities": [],
"thirdPartyDistributionChannels": []
},
"lifecycleState": "PUBLISHED",
"isReshareDisabledByAuthor": false
}
However, when trying to post, I keep getting this 400 error.
{
"errorDetailType": "com.linkedin.common.error.BadRequest",
"code": "MISSING_REQUIRED_FIELD_FOR_DSC",
"message": "Field /adContext/dscAdAccount is required when the post is a Direct Sponsored Content, but missing in the request",
"errorDetails": {
"inputErrors": [
{
"description": "Field /adContext/dscAdAccount is required when the post is a Direct Sponsored Content, but missing in the request",
"input": {
"inputPath": {
"fieldPath": "/adContext/dscAdAccount"
}
},
"code": "MISSING_REQUIRED_FIELD_FOR_DSC"
}
]
},
"status": 400
}
I see that lifecycleState, distribution, visibility, commentary, author are all required, but adContext should be an optional field. I'm not sure what part of my request is indicating I'm trying to make a Direct Sponsored Content post - can someone take a look?
I've already tried
Removing the targetEntities and thirdPartyDistributionChannels parameters.
Removing isReshareDisabledByAuthor and the above.
Changing the feedDistribution to MAIN_FEED and NONE
Creating the post via the /v2/ugcPosts endpoint - meaning the authorization token and organization urn are correct

Posting through linkedin v2 api shows corrupt characters

I am trying to create a post with Linkedin V2 api.
POST https://api.linkedin.com/v2/posts
The post is posting fine. The issue is when characters from different languages are used. It shows corrupted (Attached in Pic)
The text that I am trying to post is: "Læs mere og støt på"
This is how I am creating an object to post.
const options = {
"author": urn,
"commentary": text,
"visibility": "PUBLIC",
"distribution": {
"feedDistribution": "MAIN_FEED",
"targetEntities": [],
"thirdPartyDistributionChannels": []
},
"content":{
"media":{
"title": "Test title",
"id": assetsUrn
}
},
"lifecycleState": "PUBLISHED",
"isReshareDisabledByAuthor": false
}
Is there any way to fix this issue? Tried some encoding stuff as well but all in vain. Any help would be highly appreciated.
I've contacted the linkedin developer team and it seems to be and issue at their end which is fixed now.

Fetch company posts from linkedin API

I am trying to fetch the posts of the company from the api, I have already applied to the marketing development platform and it was approved. I already got the token with the scope: r_organization_social and I'm calling the /shares api:
https://api.linkedin.com/v2/shares?q=owners&owners=urn:li:organization:{company_ID}&sharesPerOwner=100&count=25&sharesPerOwner=10
But I'm getting the following response:
{
"paging": {
"start": 0,
"count": 25,
"links": [
{
"type": "application/json",
"rel": "next",
"href": "/v2/shares?count=25&owners=urn%3Ali%3Aorganization%3A{company_ID}&q=owners&sharesPerOwner=10&sharesPerOwner=100&start=0"
}
],
"total": 242
},
"elements": []
}
I tried to change the query params and it's still the same
This end-point worked for me:
https://api.linkedin.com/v2/ugcPosts?q=authors&authors=List(urn%3Ali%3Aorganization%3A<ID_ORGANIZATION>)
See documentation: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/ugc-post-api?tabs=http#sample-request-6
Disclaimer: I've no access to the linkedin API and couldn't test. But these are some things I noticed:
Your url contains two times the paramater sharesPerOwner, try removing one.
In the docs it's recommended to set the sharesPerOwner to 1000 and the count to 50. I'd also include the start paramater, just to make sure:
Maybe try something like this:
GET https://api.linkedin.com/v2/shares?q=owners&owners=urn:li:organization:{id}&sharesPerOwner=1000&count=50&start=0
From the api-docs(https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/share-api?tabs=http#find-shares-by-owner): "Note that the pagination excludes UGC and Direct Sponsored Content (DSC) posts". Make sure that the owner you are testing contains posts.
If this doesn't work. Could you provide some information on how you are sending the request? Have you tried accessing other parts of the api?

What should the "author" field for a LinkedIn UGC post be for Showcase/Brand pages?

I am trying to specify an author for a UGC post to a showcase page. I am expecting that the author of the showcase post is the showcase page itself, which is what happens when I manually create a post, but this doesn't seem to work with the API.
Let's say I have a showcase urn:li:organizationBrand:123456. If I specify the showcase as the author ("author": "urn:li:organizationBrand:123456) I get an error about an invalid "author" field. But if I wrap the brand URN ID with "organization" instead of "organizationBrand" ("author": "urn:li:organization:123456") it works but I have not found this interchangeability documented anywhere.
This same workaround works for retrieving post stats (/organizationalEntityShareStatistics).
Can anyone explain what the right approach is supposed to be?
Are organization brand URNs meant to effectively be an alias of organization URNs?
You can use the organizationalEntityAcls API to find your URN. organization URNs are not necessarily interchangeable with organizationBrand URNs.
For example:
GET https://api.linkedin.com/v2/organizationalEntityAcls?q=roleAssignee
"paging": {
"count": 10,
"start": 0
},
"elements": [
{
"state": "APPROVED",
"role": "ADMINISTRATOR",
"roleAssignee": "urn:li:person:R8302pZx",
"organizationalTarget": "urn:li:organization:1000"
}
]
}
source: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/organizations/organization-access-control#find-access-control-information

Resources