Trying to Add tags to Bitly API Query String - rest

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")

Related

500 error when trying to create page using REST API

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.

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.

Github API doesn't retrieve all the users when requested

I have a project where I need to retrieve all the issues from a repo. I've been practicing with the atom repository and I am using the GitHub API.
I use axios get function and the request I'm making is the following.
axios.get('https://api.github.com/repos/atom/atom/issues',
{
headers: { 'Accept': 'application/vnd.github.VERSION.raw+json' },
params: {'state': 'all'}
})
.then((response) => {
console.log(response);
})
.catch((error) =>{
console.log(error);
});
But there are 772 issues and it is only retrieving 30 issues.
How can I retrive them all? am I missing something in the header or the params.
Ive also tried without params and the header. And also adding filter: all to the params and I still get 30 issues.
Thanks in advance.

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.

Promise response works with GET, but not with POST in XHR

I am trying to call a URL through XHR.post on the DOJO 1.8. I need catch the STATUS property and getHeader() from promise response, but the problem is, when I call my URL with POST I don't have any promise, and when I call with GET I have all properties that I need, but I only can send the request as POST.
The most strange is that I have another code in AngularJS which works well, this code does the same thing. I am testing DOJO and AngularJS.
I need catch the STATUS information to check if it is 201(created), if true I need catch getHeader('location') and call the URL that I picked up from getHeader('location').
Look at my method in Dojo 1.8:
checkCreation: function(typeFile, id){
var promise = xhr('/rest/list/one', {
handleAs: 'json',
method: 'post',
accepts: 'application/json',
headers: {
Accept: 'application/json',
id: id,
type: typeFile
}
});
promise.response.then(function(response) {
console.log("status", response.status);
console.log("options", response.options);
console.log("url", response.url);
console.log("timestamp", response.options.timestamp);
console.log(response);
});
},
I discovered the problem, I commented the lines followings and now works fine.
//handleAs: 'json',
//accepts: 'application/json',
The handleAs you need to use only when you have a JSON response. About "accepts" I haven't found what difference between "accept" and "Accept"(inside headers) yet.
Now I can take my informations:
console.log('location: ', response.getHeader('location'));
console.log("status: ", response.status);