Creating new task through WebHook with Asana API - webhooks

I am working with a form system very similar to WUFOO that allows me to send data to an external website using WebHooks.
I have been able to connect my form to my ASANA system through Zapier but I cannot seem to get the API system to operate correctly. Can someone please advise or assist me on what I am doing incorrectly here?
In the screenshot note the following:
- Web URL functions for any web URL (https or http)
- HTTP method has POST, PUT, or GET options
- Data format allows me to input virtually anything so I can match up form fields with any necessary names for ASANA.
I simply cannot get the system to connect to ASANA. Please help me.
Screen shot of WebHook Options

I don't have access to your exact form builder but assuming it does what it says it is doing you can try the following. I'll use creating a task as an example.
Create a personal access token in Asana. To do this log in to Asana, click the icon in the top right corner and open "My profile settings". Go to the apps tab and create a personal access token. You will only ever see this token once so create a new one if you lose it. Also retrieve your workspace id, you can get it by opening app.asana.com/api/1.0/workspaces while logged in.
Now back to your form. For the website url place the specific endpoint you want to hit at Asana. For example, lets create a new task:
https://app.asana.com/api/1.0/tasks
Under the HTTP Method you want to select POST
Under the HTTP Headers you want to specify something like (replace 0/1234abcd with your access token):
{
"Authorization": "Bearer 0/1234abcd",
"Content-Type": "application/json"
}
You can use Send Raw Data and specify something like the following in the raw data section (replace 1234 with your workspace id):
{
"data": {
"workspace": 1234,
"name": "The name of the task"
}
}
You can of course add other fields- please see the API reference for more information:
https://asana.com/developers/api-reference/tasks
Let me know if that works for you.

Related

Azure Build Pipeline - Pause and Enable DefinitionQueueStatus change REST API

We have many dozens of build pipelines and we want to pause and resume (re-enable) build pipelines from a simple webapp interface as we are making config changes frequently. Here is the MS doc explaining this API:
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/update%20build?view=azure-devops-rest-5.0#definitionqueuestatus
From this documentation, it appears I need to hit the REST API and change/toggle the DefinitionQueueStatus -- however, this documentation only shows a sample for a build specific operation, whereas I want to pause then re-enable the entire build pipeline. What is the proper way to make this call?
I'm using fetch - and I've tried many dozen formats in the call - the 'ourorg' and 'ourproject' are correct (we use this call structure for many other calls), but all fails for this call below. I grabbed the 'definitionID' from the URL I can visibly see when in the Azure devops portal on the specific build pipeline page, and I'm using it for the {buildID} as I don't know what else to put there. Any guidance to help here is appreciated - I don't need to use fetch btw - any working sample will help here:
fetch(https://dev.azure.com/our_org/our_projectname/_apis/build/builds/definitionId=1593?retry=true&api-version=5.0 {
method: 'PATCH ',
credentials: 'same-origin',
body: 'DefinitionQueueStatus: "Enabled"'
}).then(function(response) {
console.log(response);
})
It seems that the body is incorrect in your post. Here is sample about how to use POSTMAN to access Azure DevOps Services REST APIs.
Generate the PAT, and then record the token, it is important to use to authorization, please see this document.
Create a new request in POSTMAN, it is recommended to put the request in a collection for Azure DevOps Services REST API;
Select the authorization as Basic Auth, you can input the username as any value, and the password as the token which is generated in step1.
Basic Auth
Set the REST API which you want to use,and select the request method type(GET,POST,FETCH ....), here you use https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}?api-version=5.0.
In the Body tab, you can set the request body as raw in json format, and input the value as following:
{
"buildNumber":"#20190607.2",
"buildNumberRevision":1,
"definition":
{
"id":1,
"createdDate":null,
"queueStatus":"paused"
}
}
Everthing is ready now, you can send the request, if sccuess, you will get the response from the REST API.
In your post, the body content is incorrect, the Request Body should meet the format in the REST API document. The DefinitionQueueStatus is a type in definitions. In addition, if you send the request with parameter retry, you will get the message The request body must be empty when the retry parameter is specified..

Spotify API Token Scope Issue

I have been at this for sometime now and wanted to see if anyone had and idea of what I could be doing wrong. What I am trying to do is add a song to a playlist using the provided Spotify Web APIs. According to the documentation on this https://developer.spotify.com/documentation/web-api/reference/playlists/add-tracks-to-playlist/ I need to establish the scope of the user.
"adding tracks to the current user’s private playlist (including collaborative playlists) requires the playlist-modify-private scope" I have created the playlist as collaborative and I am using the login credentials of my personal account to reach this playlist I created. all this is under the same login.
What I am finding is that my scope is not getting added to my token on my call for my token causes a 403 error when I try to add the song.
Here is what that call looks like
https://accounts.spotify.com/authorize/?client_id=mynumber&response_type=code&scope=playlist-modify-private&redirect_uri=http:%2F%2Flocalhost:55141/Home/GetToken/
here are the docs on using authorization to get the correct token.
https://accounts.spotify.com/authorize/?client_id=894400c20b884591a05a8f2432cca4f0&response_type=code&scope=playlist-modify-private&redirect_uri=http:%2F%2Flocalhost:55141/Home/GetToken/
further more if I go into the dev support here
https://developer.spotify.com/documentation/web-api/reference/playlists/add-tracks-to-playlist/
and click the green try button and then request a new token it works.
Bottom line some how my request is not taking my scope request. Any Ideas?
Thanks
To get the token with a specific scope you need to go to the authorize endpoint and get the code. The code is what you want to get to be able http post to the endpoint https://accounts.spotify.com/api/token and get a token with your desired scopes. You can simply get the code by pasting a url like this in your browser...
https://accounts.spotify.com/authorize?client_id=<client_id>&response_type=code&scope=streaming%20user-read-email%20user-read-private&redirect_uri=<redirect_uri>
Only add %20 in between scopes if you have multiple ones
You will then be sent to spotify's website and they'll verify you want to do this. Once you verify it your browser will redirect you to what you set the redirect_uri to be in the url above. At the end of the url that you are sent to, you should be able to see the parameter name code with the code value assigned to it. You then get that code and put it in your http post body params to the https://accounts.spotify.com/api/token endpoint. Make sure you accurately follow the query params requirements in your post method.
An example of the post in python using the requests library:
authorization = requests.post(
"https://accounts.spotify.com/api/token",
auth=(client_id, client_secret),
data={
"grant_type": "authorization_code",
"code": <code>,
"redirect_uri": <redirect_uri>
},
)
authorization_JSON = authorization.json()
return authorization_JSON["access_token"]
In the end you should get a json that shows the scopes you set a long with a refresh the token later on to make more requests.
I know this answer is quite late but I was experiencing the same issue as well which is how I came across this question. I hope this helps anyone that sees this at a later date.
Source: https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow

How can I get a token for the Drive API?

I want to implement the Google Drive API to my web application using NodeJS and I'm struggling when I try to get a token via OAuth.
I've copied the code from this guide and run the script using Node and it returns an error in this line:
var redirectUrl = credentials.installed.redirect_uris[0];
Googling around I found that I can set that variable as http://localhost:8080 and set the same value in the Authorized redirect URIs configuration in the Google Developers Console and that error goes away, fine, it works. Now it asks for a code that I should get by using an URL.
https://accounts.google.com/o/oauth2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.metadata.readonly&response_type=code&client_id=CLIENT_ID&redirect_uri=http%3A%2F%2Flocalhost%3A8080
Then I've added the client id and enter to that URL with Chrome and then returns a connection refused error. No clue what to do in here, I searched about my problem and I can't found an answer. By looking at the direction bar in Chrome I see that there's a parameter called code and after it, there's random numbers and letters. Like this:
http://localhost:8080/?code=#/r6ntY87F8DAfhsdfadf78F7D765lJu_Vk-5qhc#
If I add any of these values it returns this error...
Error while trying to retrieve access token { [Error: invalid_request] code: 400 }
Any ideas on what should I do? Thanks.
Did you follow all the directions on the page you indicated, including all of those in Step 1 where you create the credentials in the console and download the JSON for it? There are a few things to note about creating those credentials and the JSON that you get from it:
The steps they give are a little different from what I went through. They're essentially correct, but the "Go to credentials" didn't put me on the page that has the "OAuth Consent Screen" and "Credentials" tabs on the top. I had to click on the "Credentials" left navigation for the project first.
Similarly, on the "Credentials" page, my button was labeled "Create Credentials", not "Add Credentials". But it was a blue button on the top of the page either way.
It is very important that you select "OAuth Client ID" and then Application Type of "Other". This will let you create an OAuth token that runs through an application and not through a server.
Take a look at the client_secret.json file it tells you to download. In there, you should see an entry that looks something like "redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"] which is the JSON entry that the line you reported having problems with was looking for.
That "urn:ietf:wg:oauth:2.0:oob" is a magic string that says that you're not going to redirect anywhere as part of the auth stage in your browser, but instead you're going to get back a code on the page that you will enter into the application.
I suspect that the "connection refused" error you're talking about is that you used "http://localhost:8080/" for that value, so it was trying to redirect your browser to an application running on localhost... and I suspect you didn't have anything running there.
The application will prompt you to enter the code, will convert the code into the tokens it needs, and then save the tokens for future use. See the getNewToken() function in the sample code for where and how it does all this.
You need to use this code to exchange for a token. I'm not sure with nodejs how to go about this but in PHP I would post the details to the token exchange url. In javascript you post array would look similar to this ....
var query = {'code': 'the code sent',
'client_id': 'your client id',
'client_secret': 'your client secret',
'redirect_uri': 'your redirect',
'grant_type': 'code' };
Hope this helps
Change redirect uri from http://localhost:8080 to https://localhost:8080.
For this add SSL certificates to your server.

Instagram how to get my user id from username?

I'm in the process of embedding my image feed in my website using JSON, the URL needs my user id so I can retrieve this feed.
So, where can I find/get my user id?
Update in Jun-5-2022, Instagram API no longer use Bearer Token for authentication. But I find another useful API. All you need is added extra header X-IG-App-ID with "magic value".
https://i.instagram.com/api/v1/users/web_profile_info/?username=therock
Use can use my docker container Insta-Proxy-Server to bypass the authentication.
https://hub.docker.com/repository/docker/dockerer123456/insta-proxy-server
Demo video (I just run directly from source code): https://www.youtube.com/watch?v=frHC1jOfK1k
Update in Mar-19-2022, the API is require login now. Sorry for the bad news.
But we can solve this problem in two ways.
Using my C# lib, login using your account (without any Instagram app token stuff and graph api.)
In case the lib failed (I'm no longer maintain it long time ago), create a proxy server with logged in instagram account.
[Your app] --> [Proxy server] --> [Instagram] --> [Proxy server] -(forward)-> [Your app]
For Proxy server, you can use Nodejs app which install Chromium headless module (Puppeteer for example), logged in with an instagram account.
Proof of concept:
https://www.youtube.com/watch?v=ZlnNBpCXQM8
https://www.youtube.com/watch?v=eMb9us2hH3w
Update in June-20-2019, the API is public now. No authentication required.
Update in December-11-2018, I needed to confirm that this endpoint still work.
You need to login before sending request to this site because it's not public endpoint anymore.
Update in Apr-17-2018, it's look like this endpoint still working (but its not public endpoint anymore), you must send a request with extra information to that endpoint. (Press F12 to open developer toolbar, then click to Network Tab and trace the request.)
Update in Apr-12-2018, cameronjonesweb said that this endpoint doesn't work anymore. When he/she trying to access this endpoint, 403 status code return.
You can get user info when a request is made with the url below:
https://www.instagram.com/{username}/?__a=1
E.g:
This url will get all information about a user whose username is therock
https://www.instagram.com/therock/?__a=1
Enter this url in your browser with the users name you want to find and your access token
https://api.instagram.com/v1/users/search?q=[USERNAME]&access_token=[ACCESS TOKEN]
Working solution without access token as of October-14-2018:
Search for the username:
https://www.instagram.com/web/search/topsearch/?query=<username>
Example:
https://www.instagram.com/web/search/topsearch/?query=therock
This is a search query. Find the exact matched entry in the reply and get user ID from the entry.
Easily Get USER ID and User Details
https://api.instagram.com/v1/users/search?q=[ USER NAME ]&client_id=[ YOU APP Client ID ]
For Example:
https://api.instagram.com/v1/users/search?q=zeeshanakhter2009&client_id=enter_your_id
Result:
{"meta":{"code":200},"data":[{"username":"zeeshanakhter2009","bio":"http://about.me/zeeshanakhter","website":"http://zeeshanakhter.com","profile_picture":"http://images.ak.instagram.com/profiles/profile_202090411_75sq_1377878261.jpg","full_name":"Zeeshan
Akhter","id":"202090411"}]}
Most of the methods are obsolete since June, 1/2016 api changes
Below worked for me,
access instagram on your browser say chrome, safari or firefox.
Launch developer tools, go to console option.
on command prompt enter below command and hit enter:
window._sharedData.entry_data.ProfilePage[0].user.id
If you are lucky, you will get at first attempt, if not, be patient, refresh the page and try again. keep doing until you see user-id. Good luck!!
Instead of using the API, one can examine the Instagram userpage to get the id. Example code in PHP:
$html = file_get_contents("http://instagram.com/<username>");
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$js = $xpath->query('//body/script[#type="text/javascript"]')->item(1)->nodeValue;
$start = strpos($js, '{');
$end = strrpos($js, ';');
$json = substr($js, $start, $end - $start);
$data = json_decode($json, true);
$data = $data["entry_data"]["UserProfile"][0];
# The "userMedia" entry of $data now has the same structure as the "data" field
# in Instagram API responses to user endpoints queries
echo $data["user"]["id"];
Of course, this code has to be adapted if Instagram changes its page format.
Currently there is no direct Instagram API to get user id from user name. You need to call the GET /users/search API and then iterate the results and check if the username field value is equal to your username or not, then you grab the id.
I wrote this tool for retrieving Instagram IDs by username: Instagram User ID Lookup.
It utilizes the python-instagram library to access the API and includes a link to the source code (written on Django), which illustrates various implementations of the Instagram API.
Update: Added source code for port to Ruby on Rails.
I tried all the aforementioned solutions and none works. I guess Instagram has accelerated their changes. I tried, however, the browser console method and played around a bit and found this command that gave me the user ID.
window._sharedData.entry_data.ProfilePage[0].graphql.user.id
You just visit a profile's page and enter this command in the console. You might need to refresh the page for this to work though. (I had to post this as an answer, because of my low reputation)
You need to use Instagrams API to convert your username to id.
If I remember correctly you use users/search to find the username and get the id from there
Most of these answers are invalid after the 6/1/2016 Instagram API changes. The best solution now is here. Go to your feed on instagram.com, copy the link address for any of your pictures, and paste it into the textbox on that page. Worked like a charm.
to get your id, make an authenticated request to the Instagram API users/self/feed endpoint. the response will contain, among other data, the username as well as the id of the user.
Go to the api console & copy link https://api.instagram.com/v1/users/self in text field and authenticate using your instagram id & password, you will get your id in response
This can be done through apigee.com Instagram API access here on Instagram's developer site. After loging in, click on the "/users/search" API call. From there you can search any username and retrieve its id.
{
"data": [{
"username": "jack",
"first_name": "Jack",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_66_75sq.jpg",
"id": "66",
"last_name": "Dorsey"
},
{
"username": "sammyjack",
"first_name": "Sammy",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_29648_75sq_1294520029.jpg",
"id": "29648",
"last_name": "Jack"
},
{
"username": "jacktiddy",
"first_name": "Jack",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_13096_75sq_1286441317.jpg",
"id": "13096",
"last_name": "Tiddy"
}]}
If you already have an access code, it can also be done like this:
https://api.instagram.com/v1/users/search?q=USERNAME&access_token=ACCESS_TOKEN
Well you can just call this link
http://jelled.com/ajax/instagram?do=username&username=[USER_NAME_GOES_HERE]&format=json
Although it's not listed on the API doc page anymore, I found a thread that mentions that you can use self in place of user-id for the users/{user-id} endpoint and it'll return the currently authenticated user's info.
So, users/self is the same as an explicit call to users/{some-user-id} and contains the user's id as part of the payload. Once you're authenticated, just make a call to users/self and the result will include the currently authenticated user's id, like so:
{
"data": {
"id": "1574083",
"username": "snoopdogg",
"full_name": "Snoop Dogg",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
"bio": "This is my bio",
"website": "http://snoopdogg.com",
"counts": {
"media": 1320,
"follows": 420,
"followed_by": 3410
}
}
If you are using implicit Authentication must have the problem of not being able to find the user_id
I found a way for example:
Access Token = 1506417331.18b98f6.8a00c0d293624ded801d5c723a25d3ec
the User id is 1506417331
would you do a split single seperated by . obtenies to acces token and the first element
I think the best, simplest and securest method is to open your instagram profile in a browser, view source code and look for user variable (ctrl+f "user":{") inside main javascript code. The id number inside user variable should be your id.
This is the code how it looked in the moment of writing this answer (it can, and probably will be changed in future):
"user":{"username":"...","profile_picture":"...","id":"..........","full_name":"..."}},
Here is how you can retrieve your user id from a username:
$url = "https://api.instagram.com/v1/users/search?q=[username]&access_token=[your_token]";
$obj = json_decode(#file_get_contents($url));
echo $obj->data[0]->id;
You can do this by using Instagram API ( User Endpoints: /users/search )
how-to in php :
function Request($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function GetUserID($username, $access_token) {
$url = "https://api.instagram.com/v1/users/search?q=" . $username . "&access_token=" . $access_token;
if($result = json_decode(Request($url), true)) {
return $result['data'][0]['id'];
}
}
// example:
echo GetUserID('rathienth', $access_token);
Here is a really easy website that works well for me:
http://www.instaid.co.uk/
Or you can do the following replacing 'username' with your Instagram username
https://www.instagram.com/username/?__a=1
Or you can login to your Instagram account and use google dev tools and look at the cookies that have been stored. 'ds_user_id' is your user ID
Working Solution December 14, 2020
For simple usage like 3rd party tools that require an Instagram user ID (like embedding an image feed) I tend to use:
https://www.thekeygram.com/find-instagram-user-id/
because it makes it really easy to copy and paste the Instagram user ID that I am looking for. Unlike most tools I get the results fast, it's free and there are no ads. I recommend you watch the youtube video before using it so you can see how simple it is and get an idea of how it's used:
https://www.youtube.com/watch?v=9HvOroY-YBw
For more advanced usage I recommend:
https://www.instagram.com/{username}/?__a=1
(replace username with the requested username)
For example to find the user ID of the username "instagram" you would use:
https://www.instagram.com/instagram/?__a=1
This is the most advanced way which returns a JSON response and it's great if you are building an app that requires the raw data. You can save it in a database or build some type of front end UI to display it. Example: for a dashboard or on a website. Also, using the url is great because you can get additional attributes about users such as their total follower count and profile bio.
Since adding ?__a=1 to a profile URL is not working anymore to get a user ID from a username, we can do it with cURL and jq (the new API endpoint can be found in the network requests of Instagram web version, for example with Firefox Developer Tools):
curl -s 'https://i.instagram.com/api/v1/users/web_profile_info/?username=alanarblanchard' -H 'X-IG-App-ID: 936619743392459' | jq -r .data.user.id
If you are using Instagram in a web browser, you don't need to use the command above and can check the response of the HTTP request directly.
You may also be interested in finding the username from a user ID, in case someone changes frequently the username. I added an answer here: Instagram get username from userId
https://api.instagram.com/v1/users/search?q="[USERNAME]"&access_token=[ACCESS TOKEN]
Please notice the quotation marks.
This does not always return a valid result but more often than non-quoted one:
https://api.instagram.com/v1/users/search?q="self"&count=1&access_token=[ACCESS TOKEN]
returns user "self" (id: 311176867)
https://api.instagram.com/v1/users/search?q=self&count=1&access_token=[ACCESS TOKEN]
returns user "super_selfie" (id: 1422944651)
Working solution ~2018
I've found that, providing you have an access token, you can perform the following request in your browser:
https://api.instagram.com/v1/users/self?access_token=[VALUE]
In fact, access token contain the User ID (the first segment of the token):
<user-id>.1677aaa.aaa042540a2345d29d11110545e2499
You can get an access token by using this tool provided by Pixel Union.
Python solution with Instaloader external library (install it first with pip)
import instaloader
YOUR_USERNAME = "Your username here"
USERNAME_OF_INTEREST = "Username of interest here"
L = instaloader.Instaloader()
L.interactive_login(YOUR_USERNAME)
profile = instaloader.Profile.from_username(L.context, USERNAME_OF_INTEREST)
print(profile.userid)
With this kind of questions about constantly changing private APIs, I recommend to rely on actively developing libraries, not on the services or answers.
First Create an Application on Instagram and get Client Id for your application
http://instagram.com/developer/
Now just copy paste following Url into browser window by replacing your Username and your Client Id
https://api.instagram.com/v1/users/search?q=[Your-username]&client_id=[Your-Client-Id]
you will get a Json Result containing General Information about your account along with your Numeric user Id
UPDATED 2021
Just go to Facebook Apps choose your app connected with Instagram and you will see your Instagram ID: ********
Note https://www.instagram.com/{username}/?__a=1 was NOT working for me, so this is not a solution in 2021 if you want to use the Instagram Graph API
As of june 2022, you can to run or intercept a special HTTP request in order to successfully get the user data (and user ID). If you use Puppeteer, you can intercept the request that Instagram makes in the browser, and read its response. Example code:
const username = 'user.account';
const page = await browser.newPage();
const [foundResponse] = await Promise.all([
page.waitForResponse((response) => {
const request = response.request();
return request.method() === 'GET' && new RegExp(`https:\\/\\/i\\.instagram\\.com\\/api\\/v1\\/users\\/web_profile_info\\/\\?username=${encodeURIComponent(username.toLowerCase())}`).test(request.url());
}),
page.goto(`https://instagram.com/${encodeURIComponent(username)}`),
]);
const json = JSON.parse(await foundResponse.text());
console.log(json.data.user);
See discussion here: https://github.com/mifi/SimpleInstaBot/issues/125#issuecomment-1145354294
See also working code here: https://github.com/mifi/instauto/blob/2de64d9a30dad16c89a8c45f792e10f137a8e6cb/src/index.js#L250

How to provide information in the html link for Facebook open graph api call of "property name" when posting trying to post an action

I am trying to create an html object dynamically with the necessary header information depending on the query string in the link I provide to Facebook. I am hoping that Facebook open graph will call this html link as I provided. However it seems that query string info are not getting passed to my server. Do anyone know how to make this work or what is the more appropriate way to do this. BTW, I am writing my code in Node.js.
To get more info about Facebook open graph api, look here, https://developers.facebook.com/docs/beta/opengraph/actions/.
For example, the link I am trying to pass to Facebook is, "http://xxx-url.com/getFacebookObject?objectId=&description=first dynamic post", so I sent a request with the link as, "https://graph.facebook.com/me/app-name:action-name?object=http://xxx-url.com/getFacebookObject?objectId=&description=first dynamic post". However, when I check the log on the server, I don't see anything in the query string.
Instead of using the query string, you can embed the data in the URL:
http://some-domain.com/getFacebookObject/id/description
Then, depending on what node.js packages you're using, extract the data from the request:
// expess.js style
app.get("/getFacebookObject/:id/:description", function(req, res) {
var id = req.params.id,
desc = req.params.description;
// your code...
});
(See http://expressjs.com/guide.html.)
Sorry, Facebook will strip off all query string information from the URL when they launch your site in the iframe. If it was a page tab app, then you could add it to the app_data query string parameters which in turn gets passed to your iframe's page tab app via the app_data part of the signed_request parameter.

Resources