Linkedin versioning Marketing API - isDSC returns True by default - api

I'm trying to use Linkedin versioning (the new approach) Marketing API to publish posts on the company page.
I'm following the official docs and trying to use provided example:
https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/posts-api
Here is my request:
content = "x"
headers = {
"Authorization": f"Bearer {self.access_token}",
"X-Restli-Protocol-Version": "2.0.0",
"LinkedIn-Version": "202207",
"Content-Type": "application/json",
}
author = f"urn:li:organization:{self.page_id}"
data = {
"author": author,
"commentary": content,
"visibility": "PUBLIC",
"distribution": {
"feedDistribution": "NONE",
"targetEntities": [],
"thirdPartyDistributionChannels": []
},
"lifecycleState": "PUBLISHED",
"isReshareDisabledByAuthor": False,
}
response = requests.post("https://api.linkedin.com/rest/posts", headers=headers, json=data)
return response
But I get the 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 don't want to use DSC at all. But cannot disable it since isDsc field is read-only.

Related

Add value to select list in Jira cloud using python and API

I'm trying to add new values to a multiple select custom field.
I'm getting 401 response.
The code taken from Atlassian documentation .
Anyone knows why? maybe it is something with the authentication method?
import requests
from requests.auth import HTTPBasicAuth
import json
customers_id = "10163"
contextId = "int64"
url = "https://MY_DOMAIN.atlassian.net/rest/api/3/field/{customers_id}/context/{contextId}/option"
auth = HTTPBasicAuth("MY_EMAIL", "MY_API_TOKEN")
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
payload = json.dumps( {
"options": [
{
"disabled": "false",
"value": "Manhattan"
},
{
"disabled": "false",
"value": "The Electric City"
}
]
} )
response = requests.request(
"POST",
url,
data=payload,
headers=headers,
auth=auth
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",",": ")))
You have "int64" which is a string, it should be 12345 or whatever your contextID is.
There might be something else going on here also:
401 is Returned if the authentication credentials are incorrect or missing.
Is this your own Jira Cloud instance or one managed by someone else as you need the following permissions - Permissions required: Administer Jira global permission. So you may not have sufficient rights to make this call?

Jira REST API for configuring dashboard gadget

My goal is to create dashboard gadgets automatically and programatically.
I tried to create dashboard gadget, Filter Results, using jira rest api (https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-dashboards/#api-rest-api-3-dashboard-dashboardid-gadget-post). However, there isn't any parameters to set 'Saved filter', 'Number of results' or 'Columns to display' for Filter Results gadget in the api. The only thing I can do with the api is create an empty gadget.
How can I configure gadgets using api?
ScriptRunner has some support for this
https://scriptrunner.adaptavist.com/latest/jira/recipes/dashboard-gadgets.html
Not an official one, but 100% work.
End point: /rest/dashboards/1.0/{dashboardId}/gadget/{gadgetId}/prefs
Method: PUT
Example payload:
{
"up_isConfigured": true,
"up_num": "20",
"up_refresh": "false",
"up_columnNames": "issuetype|issuekey|summary|priority|assignee",
"up_filterId": "10001"
}
I use jira api, set dashboard item properties, to configure gadgets (dashboard item).
payload = json.dumps({
"filterId": "10711",
"num": "50",
"columnNames": "issuetype|summary|issuekey",
"refresh": "true",
"isConfigured": "true"
})
res = requests.request(
"PUT",
f"{HOST}/rest/api/3/dashboard/{dashboard_id}/items/{item_id}/properties/config",
headers={
"Accept": "application/json",
"Content-Type": "application/json"
},
data=payload,
auth=HTTPBasicAuth(EMAIL, TOKEN)
)
Thanks for the answer from Atlassian Community.

Change custromer-request-type in Jira ServiceDesk via REST API

I can receive the values of an created ticket using the SD API like:
GET /servicedeskapi/request/SD-4532
and within that i find something like:
{
"issueId": "71928",
"issueKey": "SD-4532",
"requestTypeId": "121",
"serviceDeskId": "5",
...
}
whereas "requestTypeId" related to the type created by the user (e.g. has a label "Common question").
Now i want to change the request type to, let's say "Hardware issue" which have the requestTypeId of "89".
When i try to change by POST /servicedeskapi/request/SD-4532
and giving a payload of
{
"requestTypeId": "89",
}
I get a "405 - Method not allowed". Also the Jira ServiceDesk REST-API doc does not state anything about a POST method for this.
So i tried the common Jira REST-API
PUT /api/2/issue/SD-4532
and give payload
{
"fields": {
"customfield_10001": {
"requestType": {
"id": "89"
}
}
}
}
but that give me an "Field 'customfield_10001' cannot be set. It is not on the appropriate screen, or unknown." error.
The reason why the Jira ServiceDesk REST API docs do not state anything about a POST method for this because.... there is no POST method for this. You cannot change a request (issue) type simply by altering the value of the field that contains the ID (metadata) of that request type.
Do a Google search on "jira rest api change issue type" to see the many other times this question has been discussed in the past in many places. In a nutshell, changing types is not possible via the REST API, only the web UI.
Use Jira Rest API to update Jira issue information. https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-put
// This code sample uses the 'node-fetch' library:
// https://www.npmjs.com/package/node-fetch
const fetch = require('node-fetch');
const bodyData = `{
"fields": {
"customfield_10010": "ABC-09",
"customfield_10000": {
"air": "",
"type": "doc",
"name": "Sample Process",
"avatarUrl": null
}
}
}`;
fetch('https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}', {
method: 'PUT',
headers: {
'Authorization': `Basic ${Buffer.from(
'email#example.com:<api_token>'
).toString('base64')}`,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: bodyData
})
.then(response => {
console.log(
`Response: ${response.status} ${response.statusText}`
);
return response.text();
})
.then(text => console.log(text))
.catch(err => console.error(err));
email#example.com --> Your Jira emailid
<api_token> --> This is from your account token generated
Note:- Before using any API check if it's not experimental as this may cause issues in future due to sudden change in req/resp from Jira.
Try to inspect Jira dashboard network tab to understand more.

People api of People.get doesn't get names, photos for other user

Dear Google People API developers,
I am using https://developers.google.com/people/api/rest/v1/people/get api, but it couldn't get other user information of names, photos and etc., using resourceName="people/account_id".
But I could get my profile information of names, photos and etc when I use resourceName="people/me"
I have also tried both web and flutter, it is the same result.
{
"resourceName": "people/110971898718679553920",
"etag": "%EgYBAgMuNz0aBAECBQc=",
"photos": [
{
"metadata": {
"primary": true,
"source": {
"type": "PROFILE",
"id": "110971898718679553920"
}
},
"url": "https://lh3.googleusercontent.com/a-/AOh14GgB8WckrOhYHm-R_Y6hugAEu7XxQ-ktNsmzYUQW=s100",
"default": true
}
]
}
How can I get that information?
My code sample as below
Calling people API by library
Future<Person> getPersonDetails(String peopleId) async {
final GoogleAuthClient googleAuthClient =
await GoogleProvider.provideGoogleAuthClient();
final PeopleServiceApi peopleServiceApi =
peopleDataProvider.getPeopleApi(googleAuthClient);
Person person = await peopleServiceApi.people
.get(peopleId, personFields: '(names,photos,urls,emailAddresses)');
return person;
}
Calling People API by HttpClient
Future<http.Response> getByPeopleAPI(String accountId) async {
GoogleSignInAccount googleSignInAccount =
await GoogleProvider.provideGoogleSignInAccount();
GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
http.Client _client = http.Client();
_client.get(
Uri.parse(
"https://people.googleapis.com/v1/$accountId?personFields=names,photos"),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ${googleSignInAuthentication.accessToken}',
},
).then((value) {
print(value?.body.toString());
});
}
Note: I got people/account_id from google activity API's of actor attribute.
I am looking forward to your support and reply.
Thank you very much in advance!
I've noticed this too in a few parts of the newer People API. The people.listDirecory endpoint seems broken. The older deprecated olderContacts.list works better but is deprecated.
Oddly enough people.searchDirectoryPeople works as expected and shows every field in readMask but you need to provide a search (no wildcard option apparently). Calling people.listDirectoryPeople with exactly the same readMask omits most fields. I'm not sure if there's a different scope required for people.listDirectoryPeople or what but it seems there's definitely something wrong with this api as documented - unless someone can point out another doc we're missing somewhere?

How to load search params to Leankit Post request from Google Apps Script

I have set up a working api call using Postman that returns the information that I want to return. I need to set up the same API call using google apps script but for some reason the search params are not loading. The api response gives the same result as the Postman response was without any search params being loaded.
My code so far is shown below. I've tried removing and adding back different settings in various orders but haven't found anything that finds the card related to the search term that I used.
function cardSearch(part) {
var settings = {
"method": "POST",
"contentType": "application/json",
"headers": {
"async": true,
"crossDomain": true,
"Authorization": "Basic *********",
"User-Agent": "PostmanRuntime/7.15.0",
"Accept": "*/*",
"Cache-Control": "no-cache",
"Postman-Token": "************",
"accept-encoding": "gzip, deflate",
"contentLength": "60",
"Connection": "keep-alive",
"cache-control": "no-cache"
},
"payload": JSON.stringify({"searchOptions": { "SearchTerm": part, "Page": 1 } })
// part is loaded into this function as a variable
}
var url = "https://**********.leankit.com/kanban/api/board/********/searchcards";
var response = UrlFetchApp.fetch(url,settings);
Logger.log(response);
var result = JSON.parse(response.getContentText());
var results = result.ReplyData[0].Results;
Logger.log(results);
}
Expected Result:
JSON describing 1 or more cards titled or header'd with the search term of my choosing if one exists.
Actual Result:
JSON describing the first 20 cards that were uploaded to the leankit board I'm referencing.
{TypeName=Test, ClassOfServiceId=0, Size=1, BlockReason=null, IsOlderThanXDays=true, SystemType=Card, Index=139, ActualStartDate=9/12/2018 4:11:09 PM, DrillThroughStatistics=null, CreateDate=9/10/2018, PriorityText=High, StartDate=9/12/2018, CurrentTaskBoardId=*****, ExternalCardIdPrefix=null, LastComment=null, AssignedUserIds=[******], CardTypeIconColor=212121, Version=84, LaneTitle=Finished As Planned, DrillThroughBoardId=null, Tags=Testing, SmallGravatarLink=********, ClassOfServiceCustomIconName=null, TypeId=*******, ClassOfServiceIconPath=null, DrillThroughProgressSizeComplete=null, ParentBoardId=0, Priority=2, Color=#0084FF, CurrentContext=Tasks, ExternalCardID=Material Testing, AssignedUsers=[{AssignedUserId=*********, AssignedUserName=*********, FullName=******** *****, Id=********, EmailAddress=******#*****.com, GravatarLink=*********, SmallGravatarLink=**********}], GravatarLink=********, DrillThroughProgressComplete=null, HasDrillThroughBoard=false, Active=false, ExternalSystemName=null, ExternalSystemUrl=null, Icon=, Id=********, DrillThroughCompletionPercent=null, CountOfOldCards=0, Description=<p>***********</p>, AssignedUserId=*******, ClassOfServiceTitle=null, LastAttachment=null, BoardId=**********, TypeColorHex=#0084FF, ActualFinishDate=9/15/2018 8:28:55 PM, HasMultipleDrillThroughBoards=false, CardDrillThroughBoardIds=[], TypeIconPath=null, ClassOfServiceColorHex=null, BoardTitle=********, TaskBoardTotalCards=3, DueDate=09/19/2018, DrillThroughProgressSizeTotal=null, IsBlocked=false, ParentCardId=null, ParentCardIds=[], AssignedUserName=******, TaskBoardCompletedCardSize=11, Title=Test Card, ClassOfServiceCustomIconColor=null, ParentBoardIds=[], CardTypeIconName=blank_icon, LastActivity=09/18/2018 03:28:55 PM, AttachmentsCount=0, DrillThroughProgressTotal=null, TaskBoardCompletionPercent=100, TaskBoardTotalSize=11, Type={Id=********}, CommentsCount=0, DateArchived=01/15/2018, LaneId=********, ParentTaskboardId=null, LastMove=09/16/2018 04:18:34 PM, TaskBoardCompletedCardCount=3, BlockStateChangeDate=null}
You need to put both the keys and values of the JSON request in quotes, as specified in the documentation E.g. 'method':'post'
Everything that is not a valid parameter for options for UrlFetchApp.fetch() goes into headers or payload - depending on the required syntax of the API you are calling. In particular: async and crossDomain belongs into headers, while everything inside data should be assigned to payload
The documentation for the request you are using specifies that the page number should not be in quotes
Those questions might be helpful for you:
https://stackoverflow.com/a/35155175/11599789
Unable to send Post Request on Google Apps Script