I am trying to post a text on LinkedIn using UGC through Postman.
Here is my request body:
{
"author": "urn:li:person:{uid of my account}",
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"text": "Hello World! This is my first Share on LinkedIn!"
},
"shareMediaCategory": "NONE"
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
Note: uid of my account is fetched through - https://api.linkedin.com/v2/me
The response I am getting is:
{
"message": "ERROR :: /author :: \"urn:li:person:oQRNppEnm\" does not match urn:li:company:\\d+|urn:li:member:\\d+\n",
"status": 422
}
Can anyone please help out here?
I had such a mistake. I used wrong value from https://api.linkedin.com/v2/me request answer. You need to add id in your request query if you haven't already,
for example
https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName)
also you need to use value from id field of JSON answer:
{"id\":\"XyyyyXXXXX\"}
It will be some kind of value with numbers and letters, not just numbers.
Related
I have an android app that uses laravel as backend. I validate user inputs in laravel using Validator facades.
$validator = Validator::make($inputs, $rules);
if ($validator->fails()) {
return response(['errors' => $validator->errors()], 401);
}
The response is an json object that could have different elements.
{
"errors": {
"username": [
"The username has already been taken.",
"The username format is invalid."
],
"email": [
"The email has already been taken."
]
}
}
or
{
"errors": {
"password": [
"The password must have at least 8 characters."
]
}
}
I get the JSONObject in the android app using java.
JSONObject errors = jsonObject.getJSONObject("errors");
My question is that how can I iterate over the errors object to show the errors?
After long hours session of finding any documentation, I am forced to ask the community.
Currently the query I am making from Java code(also tried the same with Postman) to query GraphQL:
Request:
{"query":"{findPublisherByLicenseNumber(licenseNumber : \"UAE_DXB_CMH-971\") {name licenseNumber}}"}
Response:
{
"data": {
"findPublisherByLicenseNumber": {
"name": "Cantaloupe Media House",
"licenseNumber": "UAE_DXB_CMH-971"
}
}
}
This is the query which I have made in my backend to query endpoint: http://mg-api.com/mg-graphQL
As of now I have mentioned two fields only but actual Schema has many.
type Publisher {
ID: ID!
name: String!
licenseNumber: String!
address: String
contactNumber: String
mobileNumber: String
areaCode: Int!
...
... #few more fields
books: [Book]
}
extend type Query {
findAllPublishers: [Publisher]!
findPublisherByLicenseNumber(licenseNumber: String!) : Publisher!
}
The fragment that I want to add in Query:
fragment publisherInfo on Publisher {
ID
name
licenseNumber
address
contactNumber
areaCode
}
Tried like this
{"query":"{findPublisherByLicenseNumber(licenseNumber : \"UAE_DXB_CMH-971\") {...publisherInfo}}", "fragment" : "fragment publisherInfo on Publisher {ID name licenseNumber address contactNumber areaCode }"}
but got ValidationError with message : Undefined fragment publisherInfo.
{
"data": null,
"errors": [
{
"message": "Validation error of type UndefinedFragment: Undefined fragment pubInfo # 'findPublisherByLicenseNumber'",
"locations": [
{
"line": 1,
"column": 67,
"sourceName": null
}
],
"description": "Undefined fragment pubInfo",
"validationErrorType": "UndefinedFragment",
"queryPath": [
"findPublisherByLicenseNumber"
],
"errorType": "ValidationError",
"path": null,
"extensions": null
}
]
}
When I try to achieve the same with GraphiQL UI then it works.
I have not started to look to call this from UI Frameworks where I need to use graphql.js in Vanilla JS/Angular/React/Vue etc.
As of now I am looking to utilize this from my backend code logic as there is a middleware between UI and my graphql service.
The only thing I found was left unanswered and if answered then totally in vague manner : S.O Question
Any help is appreciated.
SOLVED
Need to pass fragment before method;
{"query":"fragment pubInfo on Publisher {name licenseNumber contactNumber} {findPublisherByLicenseNumber(licenseNumber :\"UAE_DXB_CMH-971\") {...pubInfo}}"}
SOLVED
Need to pass fragment before/after method call body {} in the same Query;
{"query":"fragment pubInfo on Publisher {name licenseNumber contactNumber} {findPublisherByLicenseNumber(licenseNumber :\"UAE_DXB_CMH-971\") {...pubInfo}}"}
First, sorry for my poor english, but let me try to explain my problem.
I'm working in an application using elasticsearch java api for managed my documents.
Everything works fine, i'm able to search in DB and save on my index, i can count my documents aggregate by field and a lot of cool things, but i stucked on a weird problem.
When i trying to search my document by field called name, some documents doesn't return on search.
Let me give an example:
My documents is look like this(just for example):
id: 1
name: book
type: pdf
id: 2
name: Test of my search service
type: zip
When i trying to search, if i search by name, send as parameter the value "book", it works fine, but when i trying to search, send my parameter value "service", the result is empty.
Here my search code:
SearchRequestBuilder src1 = client.prepareSearch().setQuery(QueryBuilders.queryStringQuery(parameter).field("name"));
Anyone knows, why this search doesn't find my parameter value "service" on name field of document with id 2?
Thanks!
Additional information:
My general index information:
{
"template": "*",
"settings": {
"index.refresh_interval": "5s"
},
"mappings": {
"_default_": {
"_all": {
"enabled": true
},
"dynamic_templates": [
{
"string_fields": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"index": "not_analyzed",
"omit_norms": true,
"type": "string"
}
}
}
],
"properties": {
"#version": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
Well, after searching for hours and hours, i solved my problem.
To solve this issue, i used the wildcards query from elasticsearch java api and now i'm able to search a string parameter in my fields.
Here's the code:
SearchRequestBuilder srch1 = client.prepareSearch()
.setIndices("index_name")
.setTypes("type_name")
.setSearchType(SearchType.DFS_QUERY_AND_FETCH)
.setQuery(QueryBuilders.wildcardQuery("field_name", "*"+string_parameter+"*"));
After construction of your SearchRequestBuilder just add it into your MultipleSearchResponse or SearchResponse:
MultiSearchResponse sr = client.prepareMultiSearch()
.add(srch1)
.add(srch2)
.add(srch3)
.execute().actionGet();
In my case, i have 3 distinct queries, so i used MultipleSearchResponse.
Below is the JSON data which contains rich text/wiki text. I want to pass this data to to one of the issues in Jira through REST API. Here Java is the technology, I am using.
{"update":{"summary": [{"set": "CRF-397 – For Virgin Mobile, alert must be sent via email when Tier Mismatch exception is encountered."}]},"fields":{"description":{"set":"*Clients Impacted** Virgin Mobile *Background Information*<br>All UK schemes are experiencing at different levels some issues of:* Customers being billed on the wrong premium* Excess Fees paid at point of claim do not correspond to what has been communicated to the customer at the point of sale.* Welcome packs not being issued due to a mismatch *CRF Scope*<br>The scope of this project consists of identifying whenever a new device is communicated to Asurion by a client system and ensuring the data in each of those instances is validated to confirm that the device premium and excess fees are correctly aligned.*User Story Scope*<br>While doing enrollment if any record goes into exception due to Tier is match we have to send consolidated list of such records via email so that Asurion Team can communicate with Virgin Mobile to resolve the Tier Mismatch issues.*Requirement** An email alert must be sent when Tier Mismatch exception is encountered.* Flag based development must be done for triggering an email.* Email must be sent to Client Service, SCM and BI teams* Recipient email IDs must be configurable.* Exception list must contain below records:- * The list of devices for which there was an exception * The Feature Code sent by Virgin Mobile * The feature code configured in Client Convention for the given device*"}}}
Above JSON I am storing in jiraUpdateFromBuilder.
I am calling PUT method to update description in Jira, as below.
String _jiraUrl = applicationProperties.get(Constants.JIRAURL)
+ "/rest/api/2/issue/" + reference;
String _jiraUser = applicationProperties.get(Constants.JIRAUSER);
String _jiraPwd = applicationProperties.get(Constants.JIRAPWD);
String auth = new String(Base64.encode(_jiraUser + ":" + _jiraPwd));
int statusCode = invokePutMethod(auth, _jiraUrl.trim(),
jiraUpdateFromBuilder.toString().trim());
public static int invokePutMethod(String auth, String url, String data) {
int statusCode = 0;
try {
Client client = Client.create();
WebResource webResource = client.resource(url);
ClientResponse response = webResource
.header("Authorization", "Basic " + auth)
.type("application/json").accept("application/json")
.put(ClientResponse.class, data);
statusCode = response.getStatus();
return statusCode;
} catch (Exception e) {
Constants.ERROR.info(Level.INFO, e);
}
return statusCode;
}
Doing so, I am unable to update description of issue in Jira, through any REST API, because here getting status other than 201. And the same problem is with all the field of an Issue in JIRA which contains rich text. Kindly let me know if JRJC can help else if I need to change in JSON or any other approach.
Your json looks like this:
{
"update": {
"summary": [
{
"set": "CRF-397 ..."
}
]
},
"fields": {
"description": {
"set": "..."
}
}
}
But the "fields" part does not require to use the 'set' keyword, so it should be something like this:
{
"update": {
"summary": [
{
"set": "CRF-397 ..."
}
]
},
"fields": {
"description": "..."
}
}
If you check the documentation for the PUT /issue REST resource, you'll see that it mentions this:
Specifying a "field_id": field_value in the "fields" is a shorthand for a "set" operation in the "update" section.
Field should appear either in "fields" or "update", not in both.
Also, you've mentioned that your response status code was 400, which means it's a bad request. The response body will probably contain more detail about what is wrong, so it's best to log that as well.
Regarding this error:
Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: org.apache.catalina.connector.CoyoteInputStream#20e841d2; line: 1, column: 187]
Your description value contains newlines, but it's not allowed to use those in a json string directly. You'll have to escape those. See this post for an example.
The Jira documentations and these answers seem to be outdated. With API version 3 of Jira. (API docs to edit issue)
Updating the description of an Issue in Jira:
HTTP Method: PUT
HTTP URL: https://cognitedata.atlassian.net/rest/api/3/issue/{issueIdOrKey}
Request Body:
{
"fields": {
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "add your description here"
}
]
}
]
}
}
}
If you use a different request body, you will get the following error:
{
"errorMessages": [],
"errors": {
"description": "Operation value must be an Atlassian Document (see the Atlassian Document Format)"
}
}
I'm having trouble passing a complex json object in angularjs with $http.post. I'm keep getting a 400 bad request error sent back from the server saying the request was syntactically incorrect. I believe it has something to do with the array since it passes fine when i don't include it.
json i'm passing.
{
customer: {
firstName: "John",
lastName: "Doe",
street: "1234 South Dr",
city: "Detroit",
state: "MI",
zip: "12345",
phone: "123-321-1234",
email: "EMAIL#GMAIL.COM"
},
order: {
orderDate: "06-16-2015",
registerNum: "1",
transactionNum: "7820",
deliveryStatusID: 1,
notes: "Hold order until July",
items: [
{skuID: "1234568",
skuDescription: "Order item 1",
qty: "4",
itemStatusID: 1,
itemStatusDescription: "Backorder"
},
{skuID: "7387491",
skuDescription: "Order item 2",
qty: "1",
itemStatusID: 1,
itemStatusDescription: "Flagged"
}
]
}
}
angular service function
this.addOrder = function(new_order) {
return $http.post(base + "/add", new_order);
};
Spring MVC controller method
#RequestMapping(value="/add", method=RequestMethod.POST)
public void addOrder(#RequestBody CustomerOrder customerOrder) {
System.out.println("----CUSTOMER-INFO----");
System.out.println(customerOrder.getCustomer().getFirstName());
System.out.println(customerOrder.getCustomer().getLastName());
System.out.println("");
System.out.println("----ORDER-INFO----");
System.out.println(customerOrder.getOrder().getOrderID());
System.out.println(customerOrder.getOrder().getOrderDate());
}
The problem only seems to occur when I pass the items array in the json. I've passed the same json object without the items array and it works fine. The format of the json is being sent in the same format that gets returned whenever I GET an order with my angularjs service method so I'm really not sure as to where I'm going wrong with this.
If I need to provide more code please let me know. I appreciate any effort in helping me out.
Thank you.
Jason
Well after struggling to find my error in this problem, I finally found a solution. I thought I'd share how I debugged and fix this problem in case someone else is in a similar situation as I was.
After trying every possible way of sending my data in angular to the server and continually getting the same HTTP 400 error, I decided to send the json as a string and accept the json as a string in my spring mvc controller like this.
angular service method:
this.addOrder = function(new_order) {
return $http.post(base + "/add", angular.toJson(new_order));
};
spring controller
#RequestMapping(value="/add", method=RequestMethod.POST, consumes="application/json")
public void addOrder(#RequestBody String json) {
}
From here I simply took the json passed in and used the Jackson ObjectMapper to convert the json string to my POJO like this.
mapping json string to pojo
#RequestMapping(value="/add", method=RequestMethod.POST, consumes="application/json")
public void addOrder(#RequestBody String json) {
ObjectMapper mapper = new ObjectMapper();
try {
CustomerOrder order = mapper.readValue(json, CustomerOrder.class);
System.out.println(order.getCustomer().getFirstName() + " " + order.getCustomer().getLastName());
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
After doing this and running my code, I would get an UnrecognizedPropertyException on a field in my Items class when trying to bind the items json to the List in my Order class. It was just a simple mispelling on the json side and I completely missed it. After correcting this, jackson mapped everything correctly and I no longer get this HTTP 400 Error The request was syntactically incorrect.
Another thing to note is that if you pass your object as a string in angular using the JSON.stringify you may encounter this same exception on hashKey field in the JSON object. The hashKeys are used by angular to monitor changes. I believe you can use a jackson annotation to ignore unknown fields or you can simply use angular.toJson instead which will remove all the hasKey/values for you which is what I did.
Just formatted the Json in a better way. Try this if it helps. Also, post the java classes if possible:
{
"customer": {
"firstName": "John",
"lastName": "Doe",
"street": "1234 South Dr",
"city": "Detroit",
"state": "MI",
"zip": "12345",
"phone": "123-321-1234",
"email": "EMAIL#GMAIL.COM"
},
"order": {
"orderDate": "06-16-2015",
"registerNum": "1",
"transactionNum": "7820",
"deliveryStatusID": 1,
"notes": "Hold order until July",
"items": [
{
"skuID": "1234568",
"skuDescription": "Order item 1",
"qty": "4",
"itemStatusID": 1,
"itemStatusDescription": "Backorder"
},
{
"skuID": "7387491",
"skuDescription": "Order item 2",
"qty": "1",
"itemStatusID": 1,
"itemStatusDescription": "Flagged"
}
]
}
}