How to Add Tag via Asana API - asana

I am trying to do a simple Salesforce-Asana integration. I have many functions working, but I am having trouble with adding a tag to a workspace. Since I can't find documentation on the addTag method, I'm sort of guessing at what is required.
If I post the following JSON to https://app.asana.com/api/1.0/workspaces/WORKSPACEID/tasks:
{"data":{"name":"MyTagName","notes":"Test Notes"}}
The tag gets created in Asana, but with blank notes and name fields. If I try to get a bit more fancy and post:
{"data":{"name":"MyTagName","notes":"Test Notes","followers":[{"id":"MY_USER_ID"}]}}
I receive:
{"errors":[{"message":"Invalid field: {\"data\":{\"name\":\"MyTagName\",\"notes\":\"Test Notes\",\"followers\":[{\"id\":\"MY_USER_ID\"}]}}"}]}
I'm thinking the backslashes may mean that my request is being modified by the post, though debug output shows a properly formatted json string before the post.
Sample Code:
JSONGenerator jsongen = JSON.createGenerator(false);
jsongen.writeStartObject();
jsongen.writeFieldName('data');
jsongen.writeStartObject();
jsongen.writeStringField('name', 'MyTagName');
jsongen.writeStringField('notes', 'Test Notes');
jsongen.writeFieldName('followers');
jsongen.writeStartArray();
jsongen.writeStartObject();
jsongen.writeStringField('id', 'MY_USER_ID');
jsongen.writeEndObject();
jsongen.writeEndArray();
jsongen.writeEndObject();
jsongen.writeEndObject();
String requestbody = jsongen.getAsString();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://app.asana.com/api/1.0/workspaces/WORKSPACEID/tags');
req.setMethod('POST');
//===Auth header created here - working fine===
req.setBody(requestbody);
Http http = new Http();
HTTPResponse res = http.send(req);
return res.getBody();
Any help appreciated. I am inexperienced using JSON as well as the Asana API.

The problem was that I was posting to the wrong endpoint. Instead of workspaces/workspaceid/tags, I should have been using /tags and including workspaceid in the body of the request.

Aha, so you can add tags and even set followers despite the API not mentioning that you can or claiming that followers are read-only.
So to sum up for anyone else interested: POSTing to the endpoint https://app.asana.com/api/1.0/tags you can create a tag like this:
{ "data" : { "workspace": 1234567, "name" : "newtagname", "followers": [45678, 6789] } }
where 1234567 is your workspace ID and 45678 and 6789 are your new followers.

Since you posted this question, Asana's API and developer has introduced Tags. You documentation lays out the answer to your question pretty clearly:
https://asana.com/developers/api-reference/tags

I'm a bit confused by your question. Your ask "how to add a tag" but the first half of your question talks about adding a task. The problem with what you describe there is that you are trying to set a task's followers but the followers field is currently read-only according to Asana's API documentation. That is why you are getting an error. You can not set followers with the API right now.
The second part of your question - with the sample code - does look like you are trying to add a tag. However, right now the Asana API does not support this (at least according to the API documentation). You can update an existing tag but you can't add one.
So, to sum up: at this time the API does not allow you to add followers to a task or to create new tags.

Related

Is it possible to filter email using EntryID (PR_ENTRYID) with Outlook REST API?

We are currently using EWS Managed APIs in our application and looking to migrate to use Outlook REST API approach. I am new to Outlook REST API world and looking for some inputs.
I am trying to fetch email from exchange using PR_ENTRYID with REST API and retrieve its properties, however always facing error like below:
Response status code does not indicate success: 400 (Bad Request).
Endpoint used :
https://outlook.office365.com/api/v2.0/me/messages?
Code:
Above endpoint is appended with below filter:
"$filter=SingleValueExtendedProperties/any(ep: ep/PropertyId eq 'Binary 0x0fff' and cast (ep/Value, Edm.Binary) eq '" + entryId + "')";
where entryId is
"00000000224A6557586868FH8N6765SZ6F78768686C9786R7658E8686860886D8768676C8B6CV75V7C57S6F5S8FSF7S9F7D86GD7G57D6G86D84000000"
also tried entryId of below form with no luck:
"AAAAACJKsh5bmbBdknCdkkjAAdjhV76ssn876fBDJg76jdkBfnnnkbslnKns76229873qHGHGnPPSHSFH+gdgf8BmF8aJdgaAAA=="
Please note that I am able to expand properties as mentioned here, however unable to filter/fetch email with that property. I have followed official documentation at official documentation
Any help is highly appreciated.
Thanks.

Accessing public Instagram content via Instagram API without expiring accesstoken

i want to show public contents from instagram related to a specific hashtag (everything works fine with that) but i can't to renew the access_token everytime it expires.
("do not assume your access_token is valid forever." -
https://www.instagram.com/developer/authentication/)
To renew it manually is not an option i have to make sure there is a valid access_token at ANY time without re-authenticating.
Any ideas or questions? :)
I have one idea, but without API (and access_token). You can make requests to the web-version of Instagram with ?__a=1 parameter. I do not know how long it will work but now there is workflow:
You want to show public content with hashtag space, for example.
Add it to url and add GET-parameter ?__a=1: https://www.instagram.com/explore/tags/space/?__a=1
Make the GET-request. It returns json with nodes in top_posts (8) and media (18). Each node has owner, caption, number of comments and likes. But the most important part is in thumbnail_src and display_src.
There is page_info in media object which helps to paginate results. You need end_cursor (for example, J0HWE9rjAAAAF0HWE9qvgAAAFiYA)
Add the value from end_cursor to the url: https://www.instagram.com/explore/tags/space/?__a=1&max_id=J0HWE9rjAAAAF0HWE9qvgAAAFiYA
Repeat 3-6 to get newest posts with specific hashtag.
Update to the ?__a=1 url param. This appears to have stopped working with users '/account/?__a=1' endpoints.:( Still works on tags apparently.
Instagram shut down their public API. Here's a quick and dirty workaround in PHP:
<?php
function getPublicInfo($username) {
$url = sprintf("https://www.instagram.com/$username");
$content = file_get_contents($url);
$content = explode("window._sharedData = ", $content)[1];
$content = explode(";</script>", $content)[0];
$data = json_decode($content, true);
return $data['entry_data']['ProfilePage'][0];
}
Not sure for how long it's gonna work. Here's one for Javascript.

How to set Vendor Tax ID and 1099 Eligibility in API?

I'm currently using Consolibyte's PHP QB classes to interface with the QB api.
I've been successfully creating and updating Vendor's in QB for a while. However, we have a new requirement to use the API to store vendor's tax information.
I've tried to lookup the correct syntax to set these, but have been unsuccessful thus far.
My most recent attempt was:
$Vendor->setVendorTaxIdent($provider->taxId);
$Vendor->setIsVendorEligibleFor1099(true);
The rest of the information set gets updated properly, and the return from
$result = $VendorService->update($this->context, $this->realm, $provider->vendorId, $Vendor);
seems to indicate success.
Please let me know if you need anymore context. Thanks!
Have you referred to the documentation?
https://developer.intuit.com/docs/api/accounting/Vendor
The documentation indicates:
TaxIdentifier: String, max 20 characters
Vendor1099: Boolean
The geters and seters exactly mirror the documented fields. So unsurprisingly, you'll have these methods:
$Vendor->setTaxIdentifier($string);
$string = $Vendor->getTaxIdentifier();
And:
$Vendor->setVendor1099($boolean);
$boolean = $Vendor->getVendor1099();
If you continue to have trouble, make sure you post the XML request you're sending to QuickBooks. You can get this by doing:
print($VendorService->lastRequest());
print($VendorService->lastResponse());

"Exception Occurred" with addSiteAccount1

After having gotten a site's login form from getSiteLoginForm, I'm attempting to add a site, but I'm receiving
{ :errorOccurred=>"true", :exceptionType=>"Exception Occurred", :referenceCode=>"_fa9ede97-1792-45ca-b147-005ec4002d33" }
The URL I'm POSTing to (in Rails) is:
https://consolidatedsdk.yodlee.com/yodsoap/srest/private-fairshare/v1.0/jsonsdk/SiteAccountManagement/addSiteAccount1
and this is the POST data:
cobSessionToken=REDACTED
userSessionToken=REDACTED
siteId=11671
credentialFields.enclosedType=com.yodlee.common.FieldInfoSingle
credentialFields[0][displayName]=User Name
credentialFields[0][fieldType.typeName]=TEXT
credentialFields[0][isEditable]=true
credentialFields[0][name]=LOGIN
credentialFields[0][value]=testuser
credentialFields[0][valueIdentifier]=LOGIN
credentialFields[0][valueMask]=LOGIN_FIELD
credentialFields[1][displayName]=Password
credentialFields[1][fieldType.typeName]=IF_PASSWORD
credentialFields[1][isEditable]=true
credentialFields[1][name]=PASSWORD
credentialFields[1][value]=testpass
credentialFields[1][valueIdentifier]=PASSWORD
credentialFields[1][valueMask]=LOGIN_FIELD
I've triple checked the parameters, and they seem to match up with the documentation.
Is there something I'm missing?
Looking at the documentation it looks like there's a mismatch in the format of your parameters.
For example, you have the field credentialFields[0][displayName], but in the documentation it's referred to as credentialFields[0].displayName. Is is possible that the API expects fields in this format?
If the API does expect fields in the credentialFields[0][displayName] then it would make sense for the credentialFields.enclosedType field to follow the same format. In that case it should be credentialFields[enclosedType].

Can't get views by insightTrafficSourceType — YouTube Analytics API

So I'm using the 'google-api-client' gem with Rails, and I'm attempting to call the URL below in order to get video views by day and insightTrafficSourceType. This is a call that appears to be allowable from the Available Reports documentation page.
Additionally, I found that I was able to make this call by using the API Explorer tool provided by Google.
URL:
https://www.googleapis.com/youtube/analytics/v1beta1/reports?metrics=views&ids=channel==CHANNEL_ID&dimensions=day,insightTrafficSourceType&filter=video==VIDEO_ID&start-date=2013-01-15&end-date=2013-01-16&start-time=1970-01-01
Result:
{
:error=>
{
"errors"=>[
{
"domain"=>"global",
"reason"=>"invalid",
"message"=>"Unknown identifier (insightTrafficSourceType) given in field parameters.dimensions."
}
],
"code"=>400,
"message"=>"Unknown identifier (insightTrafficSourceType) given in field parameters.dimensions."
}
}
I'm not sure what extra data I can provide in the initial description of this bug, but as stated before I am making the call to the API with the Google::APIClient Ruby library. The actual code itself looks like this:
client.execute(
:api_method => api.reports.query,
:parameters => options
)
You are still referencing the old beta API, i.e., in your URL, you have 'v1beta' and you should have 'v1' there. Try replacing that and running it again. Also, you can look at the api explorer to see the exact URL that should be generated in live examples with your acct (once you enable OAuth) here:
https://developers.google.com/youtube/analytics/v1/
(Look at the bottom of the page.)
Finally, start-time isn't a parameter listed on the production version of the API, so you will want to remove that as well.

Resources