I am making a call to the linkedin images API to initialize an upload. I am using insomnia to make the call, I have the access token that is not expired (created 4 days ago) with all the following perms/scope (r_1st_connections_size,r_ads,r_ads_reporting,r_basicprofile,r_organization_admin,r_organization_social,rw_ads,rw_organization_admin,w_member_social,w_organization_social). Here is the code for the call exported in python. I have all the correct perms, and the linkedin account is the campaign manager, but everytime i keep getting the 403 forbidden error included below.
INPUT/CALL:
import requests
url = “https://api.linkedin.com/rest/images”
querystring = {“action”:”initializeUpload”}
payload = {“initializeUploadRequest”: {
“owner”: “urn:li:organization:219257106”,
“mediaLibraryMetadata”: {
“associatedAccount”: “urn:li:sponsoredAccount:513356194”,
“assetName”: “My media library asset”
}
}}
headers = {
“cookie”: “lidc=%22b%3DTB09%3As%3DT%3Ar%3DT%3Aa%3DT%3Ap%3DT%3Ag%3D4706%3Au%3D9%3Ax%3D1%3Ai%3D1721511524%3At%3D1721531628%3Av%3D2%3Asig%3DAQEhRosuJdmI8XOks_ogULcqJ4z6ElBm%22; lang=v%3D2%26lang%3Den-us; bcookie=%22v%3D2%26e770df25-8e43-4671-8db7-93d77b371de4%22; lidc=%22b%3DOB24%3As%3DO%3Ar%3DO%3Aa%3DO%3Ap%3DO%3Ag%3D4952%3Au%3D1%3Ax%3D1%3Ai%3D1721511020%3At%3D1721597420%3Av%3D2%3Asig%3DAQEU3F9_YkGbWbcYIHaAzem7-iWdhPs3%22”,
“Content-Type”: “application/json”,
“User-Agent”: “insomnia/9.3.2”,
“LinkedIn-Version”: “202401”,
“X-RestLi-Protocol-Version”: “2.0.0”,
“Authorization”: “Bearer Access key is here”
}
response = requests.request(“POST”, url, json=payload, headers=headers, params=querystring)
print(response.text)
OUTPUT/RESPONSE:
{“message”:”Accessing this image resource is forbidden. Please check your permissions for this resource”,”status”:403}
Content-Type: application/json
x-restli-error-response: true
x-restli-protocol-version: 2.0.0
Date: Sat, 20 Jul 2024 21:37:14 GMT
X-Li-Fabric: prod-ltx1
Report-To: {“group”:”network-errors”,”max_age”:2592000,”endpoints”:[{“url”:”https://www.linkedin.com/li/rep”}],”include_subdomains”:true}
NEL: {“report_to”:”network-errors”,”max_age”:1296000,”success_fraction”:0.00066,”failure_fraction”:1,”include_subdomains”:true}
Transfer-Encoding: chunked
Connection: keep-alive
X-Li-Source-Fabric: prod-lor1
X-Li-Pop: prod-lor1-x
X-LI-Proto: http/1.1
X-LI-UUID: AAYdtJ2D23vSK/bl+U5hKQ==
Set-Cookie: lidc=”b=TB09:s=T:r=T:a=T:p=T:g=4706:u=9:x=1:i=1721511434:t=1721531628:v=2:sig=AQHyDuL8gOEgjhxrLJrv0Tmw4FnAgczf”
X-LI-Route-Key: “b=TB09:s=T:r=T:a=T:p=T:g=4706:u=9:x=1:i=1721511434:t=1721531628:v=2:sig=AQHyDuL8gOEgjhxrLJrv0Tmw4FnAgczf”
I have tried making a new access token, using MediaLibraryMetadata, and ive tried to use video api ang get same issue. Im expecting a 200 OK status code with the uploadUrl to upload the image, and something like the following response example.
{
“value”: {
“uploadUrlExpiresAt”: 1650567510704,
“uploadUrl”: “https://www.linkedin.com/dms-uploads/C4E10AQFoyyAjHPMQuQ/uploaded-image/0?ca=vector_ads&cn=uploads&sync=0&v=beta&ut=08zHQjMjAOLqc1”,
“image”: “urn:li:image:C4E10AQFoyyAjHPMQuQ”
}
}
Vyom Sawhney is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.