APICreating Posts
Image post
Upload one image and publish it to LinkedIn. Three-step flow with cURL, JavaScript, and Python examples.
An image post is three steps: init the upload, PUT the bytes to LinkedIn, then create the post.
When to use
You're posting a single photo. For 2 or more images, see Image carousel.
Steps
POST /posts/upload/init→ returns anassetUrnand a one-timeuploadUrl.PUTthe file bytes touploadUrl(this goes straight to LinkedIn, not to our API).POST /posts/createreferencing theassetUrn.
Image post (full flow)
# 1. init -> returns assetUrn, uploadUrl, uploadHeaderscurl -X POST https://api.connectsafely.ai/linkedin/posts/upload/init -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{ "mediaType": "image", "fileSize": 184230, "filename": "photo.jpg" }'
# 2. upload the bytes to the returned uploadUrlcurl -X PUT "PASTE_uploadUrl" -H "Content-Type: image/jpeg" --data-binary @photo.jpg
# 3. create the postcurl -X POST https://api.connectsafely.ai/linkedin/posts/create -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{ "mediaType": "image", "assetUrn": "PASTE_assetUrn", "altText": "Our team at the offsite", "text": "Great week with the team!" }'Common mistakes
- Posting before uploading. Create only works after the
PUTin step 2 succeeds. - Wrong
Content-Typeon the PUT. Match the file (image/jpeg,image/png, …). - Dropping
uploadHeaders. Include whatever step 1 returned on the PUT.
