500 error when trying to create page using REST API - confluence

I'm currently using Confluence server and I'm currently getting a 500 error when I try to create a new page using the REST API. I am currently using an HTML macro that makes GET & POST requests using the Fetch API. I currently have no issues when making GET requests, only issues with POST requests.
I tried researching the error and saw someone mention that they fixed it by turning off collaborative editing in the space, but in my case that is not an option. Anyone have an idea of what is causing this error?
function createPage() {
let url = "http://exampledomain:8090/confluence/rest/api/content/"
fetch(url, {
method: 'POST',
headers: {
'Authorization': 'Basic USER:PASS',
'Content-Type': 'application/json',
},
data: {
'type': 'page',
'title': "New Page",
'ancestors': [{ 'id': 97059352 }], // parent page id
'space': { 'key': "EXAMPLE_SPACE" },
'body': {
'storage': {
'value': "<h1>New Page!</h1>",
'representation': 'storage',
}
},
}
})
.then(response => console.log(response))
.catch(err => console.log(err.message))
}

I see invalid data structure:
'representation': 'storage', <== extra comma
}
}, <== another extra comma
}
Also double check with your programming language that you can use single quotes (') and that they are correctly transformed into double quotes ("). JSON (Jira REST API) accepts only double quotes for keys and string values.

Related

SharePoint Rest API - Set Lookup field when [Lookup Name]Id value is already in use

I have a SharePoint list with a number field that has an internal name of [ProjectId]. I later created a lookup column with an internal name of [Project]. I need to use a REST API to update the lookup column value. However, when I use
"ProjectId": 403
It sets the number field. I know SharePoint will append a 0 to a duplicate internal name. However, in this case it was created by the system. I can expand the Lookup column using "Project/Id" in a GET call. I just can't set it.
Does anyone know how to reference the lookup id in this case?
Here is the full code:
// basic patch items
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/lists/GetByTitle('My List')/items(1)",
headers: {
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"IF-MATCH": "*",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
},
data: JSON.stringify({
"__metadata": {
"type": "SP.Data.MyListListItem"
},
"ProjectId": 403
}),
method: 'PATCH',
success: function (data) {
console.log("success");
console.log(data);
},
error: function (data) {
console.log("error");
console.log(data);
}
});
I've tried these as well:
"Project0Id": 403
"ProjectId0": 403
It just returns an error saying the column doesn't exist.

Trying to Add tags to Bitly API Query String

I am creating a spreadsheet to help me quickly shorten UTM parameters for ad campaigns. I want to be able to dynamically add tags to the query string so that they are easier to organize once they are created in Bitly. Here is what I have tried in Google Sheets.
=importData(concatenate("https://api-ssl.bitly.com/v3/shorten?tags[]=test&tags[]=new&longUrl=",ENCODEURL(J10),"&access_token=",$C$5,"&format=txt"))
It kicks back a URL and works perfectly, except it does not add the tags. Just not sure what I am missing.
Link to copy, just add bitly API key:
https://docs.google.com/spreadsheets/d/1OB4CaA-P-dXpRsDXjdTzLkNKHWGPjkzWOxo3n-Iv6ao/edit?usp=sharing
To further explain my end result... you will notice my "tags" parameter in the URL. I want that to be pushed into the Bitly API and create/add those tags to the newly created URL. This will give me the ability to better filter them for use.
Even though the docs says you can, it seems like it is not possible to create the link with tags. Even the Bitly UI does not support it.
It is possible to do an update and add the tags.
I created the bitlink and then right after I did another request to updated it with the tags.
Update API: PATCH:https://api-ssl.bitly.com/v4/bitlinks/{bitlink.id}
This is what I did:
fetch("https://api-ssl.bitly.com/v4/shorten", {
method: "POST",
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ***'
},
body: JSON.stringify(data)
}).then(response => response.json())
.then(data => {
let updateData = {
"tags": [
"tag1",
"tag2"
]
};
fetch("https://api-ssl.bitly.com/v4/bitlinks/" + encodeURIComponent(data.id), {
method: "PATCH",
headers: {
'Content-Type': 'application/json',
'Authorization': '***'
},
body: JSON.stringify(updateData)
})
});
}
try this:
=IMPORTDATA("https://api-ssl.bitly.com/v3/shorten?tags[]=test&tags[]=new&longUrl="&ENCODEURL(J10)&"&access_token="&$C$5&"&format=txt")

get token from spotify API using axios, error 404

I`m trying to get the token from the spotify API, I use axios. I use the example given by the API as a guide, but give me the error 404
export const getToken = code => async dispatch => {
const responseToken = await axios.post({
url: "https://accounts.spotify.com/api/token",
form: {
grant_type: "authorization_code",
code,
redirect_uri
},
headers: {
'Authorization': 'Basic ' + (new Buffer(client_id + ':' + client_secret).toString('base64'))
},
json: true
})
console.log(responseToken);
The first line is because I`m using redux,I just wanted you to see that it was a asinc method.
I have being all day trying to fix this, I don`t have more ideas of how to solve this
Try changing
form: {
grant_type: "authorization_code",
code,
redirect_uri
}
to
data: JSON.stringify({
grant_type: "authorization_code",
code,
redirect_uri
})
You want to send it in the request body, hence "data", that's how you define it in axios.
Also, I don't think you need json: true
EDIT:
Pretty sure you have to add 'content-type': 'application/x-www-form-urlencoded;charset=utf-8' to the headers as well.

Escape " in axios

I am making an api call to WuFoo forms
to do a dateCreated filter it needs to look like this (note double quote):
Filter1=DateCreated+Is_greater_than+"2019-11-13 12:00:00"
However, Axios urlencodes it to look like this:
Filter1=DateCreated%2BIs_greater_than%2B%222019-11-13+12:00:00%22'
and WuFoo unfortunately returns incorrect response to that.
I have tried escaping the encoding by using paramSerializer:
const instance = axios.create({
baseURL: 'https://subdomain.wufoo.com/api/v3',
timeout: 1000,
headers: { 'Authorization': 'Basic fjdkalfjkdafldklaskflsdkl' },
paramsSerializer: function(params) { return params }
});
....
instance.get('/forms/form/entries.json',{
params:{
Filter1: qDateFilter
}
})
qDateFilter = DateCreated+Is_greater_than+"2019-11-13 12:00:00"
However I now have the following error:
TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters
at new ClientRequest (_http_client.js:139:13)
at Object.request (https.js:309:10)
at RedirectableRequest._performRequest (/home/node/app/node_modules/follow-redirects/index.js:169:24)
at new RedirectableRequest (/home/node/app/node_modules/follow-redirects/index.js:66:8)
at Object.wrappedProtocol.request (/home/node/app/node_modules/follow-redirects/index.js:307:14)
at dispatchHttpRequest (/home/node/app/node_modules/axios/lib/adapters/http.js:180:25)
at new Promise (<anonymous>)
at httpAdapter (/home/node/app/node_modules/axios/lib/adapters/http.js:20:10)
at dispatchRequest (/home/node/app/node_modules/axios/lib/core/dispatchRequest.js:59:10)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
code: 'ERR_UNESCAPED_CHARACTERS'
}
Attempts to just use a straight full string as a URL don't work either, it still encodes it.
Using straight " in postman works fine, same with curl.
Any other options?
WuFoo got back to me. It wasn't the " it was actually the encoding of the + sign. I replaced with spaces and it worked.

SharePoint REST Service Create List Item Error The required version of WcfDataServices is missing.

I am trying to insert an item to a list (just a basic custom list with the title column) using the SharePoint Web Services. This is the code I am using
function GetItemTypeForListName(name) {
return "SP.Data." + name.charAt(0).toUpperCase() + name.slice(1) + "ListItem";
}
var itemType = GetItemTypeForListName(lisNameTitle);
var item = {
'__metadata': { 'type': itemType },
'Title': 'another item check if works'
};
var jsonItem = JSON.stringify(item);
alert(jsonItem);
$http({
method: "POST",
url: reportDownloadSubmitDataUrl,
contentType: "application/json;odata=verbose",
data: jsonItem,
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
}
})
when I execute this code, on the SharePoint side logs I get the following errors
"The required version of WcfDataServices is missing. Please refer to http://go.microsoft.com/fwlink/?LinkId=321931 for more information." String
WcfDataServices 5.6 is missing.
I have SharePoint 2013 Service Pack 1 installed on my server.
I found the problem was due to the $http( method in Angularjs. When I used directly jquery to post the result ($.ajax) it worked fine.