Twilio's taskrouter.js is throwing a CORS policy error when I call the worker.completeTask or reservation.task.complete() - twilio

I am attempting to move the Taskrouter task from "wrapping" to "completed" programmatically when the agent is done with their post-call duties. Other method calls to worker or reservation work, but when trying to call either worker.completeTask or reservation.task.completed, I receive a CORS policy error "No 'Access-Control-Allow-Origin" header present. Since taskrouter.js is an external Twilio script and I can't change it, is there any way to get this to work?

After spending hours scouring the Twilio docs earlier today, I finally posted this question in frustration. Then, literally, 30 minutes after posting it, I was working on something else and came across the solution.
When generating my capability token, I was doing it as their tutorial suggested:
$workerCapability = new Twilio\Jwt\TaskRouter\WorkerCapability(
$accountSid, $authToken, $workspaceSid, $workerSid);
$workerCapability->allowActivityUpdates();
$workerToken = $workerCapability->generateToken();
The stumble led me to an additional capability, so the updated code is:
$workerCapability = new Twilio\Jwt\TaskRouter\WorkerCapability(
$accountSid, $authToken, $workspaceSid, $workerSid);
$workerCapability->allowActivityUpdates();
$workerCapability->allowReservationUpdates();
$workerToken = $workerCapability->generateToken();

Related

Delta filter stops working for Microsoft Graph email - Microsoft Resolution

Microsoft has resolved this.
For years we have been using the Microsoft Graph API. Over the weekend, something changed, so that when making this GET:
https://graph.microsoft.com/v1.0/me/mailfolders/Inbox/messages/delta?filter=receivedDateTime+ge+2022-09-23
the result is:
`400 Bad Request`
and the response is:
{"error":{"code":"ErrorInvalidUrlQuery","message":"The '$filter' parameter value is not supported for 'Messages' resource; only a value of 'receivedDateTime ge value' is supported."}}
I have reported the issue, and Microsoft is working on it:
'$filter=receivedDateTime+ge+{value}' stops working
User fasterforward noted that the messages/delta is not working but that messages url without the delta is working:
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$orderby=receivedDateTime desc&$filter=receivedDateTime ge 2022-09-27
This works for me.
I am unable to post comments or answers, so I hope posting this detail helps someone else especially #lazyden, #keithadams, #Joyce, #Jamie Dan, #Ram Prasad, #SBE

YouTube reporting API reports are all blank

I have created set of YouTube reporting jobs for a YouTube channel. The jobs were created and run every day as scheduled. However when I go to download the jobs they are all blank.
This is how I authenticate with the API:
def authenticate_from_credentials(API_SERVICE_NAME, API_VERSION):
youtube_client_id = os.environ['youtube_client_id']
youtube_client_secret = os.environ['youtube_client_secret']
youtube_refresh_token = os.environ['youtube_refresh_token']
credentials = client.OAuth2Credentials(
access_token=None,
client_id=youtube_client_id,
client_secret=youtube_client_secret,
refresh_token=youtube_refresh_token,
token_expiry=None,
token_uri='https://oauth2.googleapis.com/token',
user_agent=None,
revoke_uri=None
)
youtube_reporting = build(API_SERVICE_NAME, API_VERSION, credentials=credentials)
return youtube_reporting
This is the method I have been using to create the jobs:
# Call the YouTube Reporting API's jobs.create method to create a job.
def create_reporting_job(youtube_reporting, report_type_id, name):
# Provide keyword arguments that have values as request parameters.
reporting_job = youtube_reporting.jobs().create(
body=dict(
reportTypeId=report_type_id,
name=name
),
).execute()
print ('Reporting job "%s" created for reporting type "%s" at "%s"'
% (reporting_job['name'], reporting_job['reportTypeId'],
reporting_job['createTime']))
I authenticate like this:
youtube_reporting=authenticate_from_credentials('youtubereporting','v1')
And I will create a job like this:
create_reporting_job(youtube_reporting,"channel_combined_a2","Channel Combined a2")
I am not sure what the problem is here. The channel does have content and subscribers so the reports shouldn't be empty. I think there could be an issue with credentials or perhaps the wrong channel is associated with the report since the developer's Google accounts are different than the content owners. But I checked the channels associated with the Oauth credentials I am using and it was the right channel.
Why might my reports be empty and how can I fix this?
I hit the same issue, the problem is that you need to wait several hours for the report to become generated on the backend, at which point re-querying for reports will show results.
There is a subtle mention about this delay on https://developers.google.com/youtube/reporting/v1/reports under Step 3:
The API response to the jobs.create method contains a Job resource,
which specifies the ID that uniquely identifies the job. You can
start retrieving the report within 48 hours of the time that the job
is created, and the first available report will be for the day that
you scheduled the job.
This was quite confusing.

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());

KairosDB Java client checks health

I would like to use KairosDB Java client to check KairosDB health but it seems there is too few guides. Anyone knows please help me?
I have commented the question to get more details about what you want to do.
However one interesting metric is the HTTP request time in kairosDB (kairosdb.http.request_time). By polling this metric you will:
- Make sure metrics are recorded
- Make sure http requests are received, processed and answered in reasonable time (although long queries will report longer time than others)
To do so you can follow the example on https://github.com/kairosdb/kairosdb-client, e.g. by doing this kind of query every five minutes:
QueryBuilder builder = QueryBuilder.getInstance();
builder.setStart(10, TimeUnit.MINUTES)
.setEnd(0, TimeUnit.MINUTES)
.addMetric("kairosdb.http.request_time")
.addGrouper(new TagGrouper("host"));
HttpClient client = new HttpClient("http://localhost:8080");
QueryResponse response = client.query(builder);
client.shutdown();
I hope this helps.
Regards,
Loic

How to Add Tag via Asana API

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.

Resources