Linked Posts API (new) sample code is not working - linkedin

I'm trying to use the new LinkedIn Posts API to make a post. I started by trying to duplicate the curl sample code at
https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/posts-api?view=li-lms-2022-06&tabs=curl#text-only-post-creation-sample-request
curl -X POST 'https://api.linkedin.com/rest/posts \
-H 'Authorization: Bearer {INSERT_TOKEN}' \
-H 'X-Restli-Protocol-Version: 2.0.0' \
-H 'LinkedIn-Version: {version number in the format YYYYMM}' \
-H 'Content-Type: application/json' \
--data '{
"author": "urn:li:organization:5515715",
"commentary": "Sample text Post",
"visibility": "PUBLIC",
"distribution": {
"feedDistribution": "NONE",
"targetEntities": [],
"thirdPartyDistributionChannels": []
},
"lifecycleState": "PUBLISHED",
"isReshareDisabledByAuthor": false
}'
I replaced the bearer token with my own, and changed the author to urn:li:person:{my id}
I get the following error suggesting that I a have asked for a specific adContext:
{"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}
In the hope that that was the default, I added an adContext "adContext": {"isDsc": False}
and that gave me {"errorDetailType":"com.linkedin.common.error.BadRequest","code":"UNPROCESSABLE_ENTITY","message":"ReadOnly field present in a create request","errorDetails":{"inputErrors":[{"description":"ReadOnly field present in a create request","input":{"inputPath":{"fieldPath":"/adContext/isDsc"}},"code":"UNPROCESSABLE_ENTITY"}]},"status":400}
I also tried a blank adContext.
Has anyone had any luck using this API, or can anyone tell me what I'm doing wrong?

Related

Change project key with bitbucket rest api

I am trying to write a script to move repos in a project to another project but I am getting a 400 error whenever I try.
My python requests line looks like:
url = 'https://bitbucketserver.com/rest/api/1.0/projects/example1/repos/repo1'
token = 'TokenString'
response = requests.put(url, headers={'Content-Type': 'application/json', 'Authorization': 'Bearer' + token}, data={'project': {'key': 'NEW_PROJECT'}}, verify=False)
I get a response 400 that says 'Unexpected character ('p' (code112)): expected a valid value (number, string, array, object, true, false, or null) at [Source: com.atlassian.stash.internal.web.util.web.CountingServletInputStream#7ccd7631; line 1, column 2]
I'm not sure where my syntax is wrong
Not python, but work for me via curl:
curl -u 'USER:PASSWORD' --request PUT \
--url 'https://stash.vsegda.da/rest/api/1.0/projects/OLD_PROJECT/repos/REPO_TO_MOVE' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"project": {"key":"NEW_PROJECT"}
}'
Maybe can someone help.

Trying to use browserless ... getting "message: 'elements' is not allowed"

I'm trying to scrape an Amazon page with browserless:
curl -X POST \
"https://chrome.browserless.io/content?token=<token>" \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d ' {
"url": "https://www.amazon.com/gp/your-account/order-details/?orderID=114-5444651-3149007",
"elements": [{
"selector": "a",
}],
"cookies": [
<many cookies>
],
}'
but I keep getting:
[{"message":"\"elements\" is not allowed","path":["elements"],"type":"object.unknown","context":{"child":"elements","label":"elements","value":[{"selector":"a","timeout":10000}],"key":"elements"}}]%
If I exclude the elements object, it works fine but returns the entire 6,000 lines of <html>.
(What I actually want is document.getElementsByClassName('shipment')[0].innerText)
When I try the examples (from the docs) they work fine.
Its because elements only available for /scrape API
You are using /content

How to obtain time-entries for a project?

An api exists for obtaining all time-entries for a workspace, /workspaces/{workspaceId}/time-entries, and the ability to obtain time-entries for a user, /workspaces/{workspaceId}/user/{userId}/time-entries.
Can filtering be added to /workspaces/{workspaceId}/time-entries? Start Date would be nice.
Would be possible to add obtain time-entries for a project?
/workspaces/{workspaceId}/projects/{projectId}/time-entries, with filtering of course
For the new clockify report API, which is documented here (https://clockify.me/developers-api#tag-Reports), you can use following requests.
Filtering time entries by user and date:
curl --request POST \
--url https://reports.api.clockify.me/v1/workspaces/<YOUR WORKSPACE ID>/reports/summary \
--header 'content-type: application/json' \
--header 'x-api-key: <YOUR API KEY>' \
--data '{
"dateRangeStart": "2020-08-13T00:00:00.000Z",
"dateRangeEnd": "2020-08-13T23:59:59.000Z",
"summaryFilter": {"groups": ["USER", "TIMEENTRY"]},
"exportType": "JSON",
"users": {
"ids": ["<USER ID>"],
"contains": "CONTAINS",
"status": "ALL"
}
}'
All time entries for a certain project:
curl --request POST \
--url https://reports.api.clockify.me/v1/workspaces/<YOUR WORKSPACE ID/reports/summary \
--header 'content-type: application/json' \
--header 'x-api-key: <YOUR API KEY>' \
--data '{
"dateRangeStart": "2020-08-13T00:00:00.000Z",
"dateRangeEnd": "2020-08-13T23:59:59.000Z",
"summaryFilter": {"groups": ["PROJECT", "TIMEENTRY"]},
"exportType": "JSON",
"projects": {"ids" : ["<PROJECT ID>"]}
}'
If you remove the group TIMEENTRY you will just get the sums as result, not all the separate time entries.
Of course you can fetch all time entries for a project grouped by a user like this (filtering by project and grouping by USER:
"summaryFilter": {"groups": ["PROJECT", "USER", "TIMEENTRY"]},

Is this possible to pass multiple values at once for fetching process instances by passing variables?

I am fetching process instances by passing the variables. I am using historic process instance query api.
Reference link is as follows:
http://localhost:8082/activiti-app/api-explorer.html#!/process-instances/getHistoricProcessInstancesUsingPOST
Curl command for this API is as follows:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic YWRtaW5AYXBwLmFjdGl2aXRpLmNvbTphZG1pbg==' -d '{ \
"variables": [
{
"name": "location",
"operation": "equals",
"value": "banglore"
}
]
}' 'http://localhost:8082/activiti-app/api/enterprise/historic-process-instances/query'
The above example worked for me. But I want to pass multiple values at once for the value. For example, I need to pass India, Banglore, Puna, Delhi etc... as values for the value at once. Is this possible to pass multiple values to the value at once. Can any one provide solution in this?
Thanks & Regards
Shilpa Kulkarni

Amazon - Can't request performance report using Advertising API

I'm getting an error using amazon advertising API. I'm currently trying to request performance report using https://advertising-api.amazon.com/v1/campaigns/report.
But the server reply Cannot consume content type
here is my request header and body.
End point : https://advertising-api.amazon.com/v1/campaigns/report
Method Type: POST
Header :
{
Authorization: 'Bearer xxxxxx',
Amazon-Advertising-API-Scope: '11111111111',
Content-Type: 'application/json'
}
Body :
{
campaignType:'sponsoredProducts',
reportDate:'20180320',
metrics:'impressions,clicks'
}
I think I did everything correctly as API document but it says
{
"code": "415",
"details": "Cannot consume content type"
}
Please help me.
Try this way
curl -X POST \
https://advertising-api.amazon.com/v1/campaigns/report \
-H 'Amazon-Advertising-API-Scope: REPLACE_YOUR_PROFILE_ID' \
-H 'Authorization: REPLACE_YOUR_ACCESS_TOKEN' \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-H 'Host: advertising-api.amazon.com' \
-H 'cache-control: no-cache' \
-d '{
"campaignType": "sponsoredProducts",
"metrics": "impressions,clicks",
"reportDate": "20181101"
}
And you will get a response like
{
"reportId": "amzn1.clicksAPI.v1.p1.......",
"recordType": "campaign",
"status": "IN_PROGRESS",
"statusDetails": "Report is being generated."
}
You can put this curl command in Postman also.
I think your Body may be missing a parameter. When I successfully make a similar POST I need my body to have at least what you have written as well as the segment type. Try adding this to your body:
{
campaignType:'sponsoredProducts',
reportDate:'20180320',
metrics:'impressions,clicks'
segment:'query'
}
Just copy the body from the documentation and paste it in the raw area (of postman) and choose JSON format. For me it works fine.

Resources