Deluge function to get a Postcode and put the street name and city into the Address field on Zoho CRM - google-maps

I'm trying to write a code that'll automatically run when a contact is created. It'll take the postcode and use that with my Google Geocoding API to pull the street and city, and put that in the Address field.
leadDetails = zoho.crm.getRecordById("ARCH_Concept_Ltd",input.leadId);
// Make API call to Google Maps Geocoding API
api_key = "API_Number";
postcode = ifnull(leadDetails.get("Postcode"),"");
api_url = "https://maps.googleapis.com/maps/api/geocode/json?address="+postcode+"&key="+api_key;
response = http.get(api_url.toURL());
// Parse the response to extract the street address
data = json.parse(response.getContent());
address = data.results[0].formatted_address;
// Store the address in the "Address" field
mp = Map();
mp.put("Address",address);
update = zoho.crm.updateRecord("ARCH_Concept_Ltd",leadId.toLong(),mp);
info mp;
info update;
I'm getting the following error:
Failed to save the function
Syntax error. Expecting executeshellscript task,expression,invokeurl task or 'invokeintegration'. Found '['. Line Number: 11

The error message says it is expecting executeshellscript task,expression,invokeurl task or 'invokeintegration'..
Although it says the error is at the '[' on line 11, that is just where the interpreter finally gave up.
This line: response = http.get(api_url.toURL()); can be replaced with zoho-Deluge's invokeurl command so give that a try.

Related

Create a new Course with Google Apps Script - ClassRoom API

There is an error on line 11 stating:
Requested entity was not found. (line 11, file "Code")
line 11
createdCourse = Classroom.Courses.get('Bio10');
The function:
function createA_NewCourse() {
var courseNew,createdCourse;
courseNew = Classroom.newCourse();
courseNew.name = "10th Grade Biology";
courseNew.id = "Bio10";
Logger.log("course.name " + courseNew.name);//Verify that name was set
createdCourse = Classroom.Courses.get('Bio10');//Try to get course by ID
Logger.log(createdCourse)
}
How is a new course created in Apps Script?
As stated by #Dean Ransevycz, there should be a create() method.
Here's a sample code:
function createCourses() {
var course;
course = Classroom.newCourse();
course.name = "10th Grade Biology";
course.ownerId = "me";
//course.id = "Bio10";
course = Classroom.Courses.create(course);
Logger.log('%s (%s)', course.name, course.id);
var list = Classroom.Courses.list();
Logger.log(list);
}
You're getting an Requested entity was not found. error since you might be using the wrong course id. And I guess you can't set an ID when creating a course. (Source.)
There are specific values for the ownerId that must be used. The ownerId specifies the owner of the course. One of the valid ownerId strings is "me" which is the requesting user.
Other valid owner ID strings are:
the numeric identifier for the user
the email address of the user
The email address of the user is self explanatory. I don't know where you get the numeric identifier of the user.
Without the ownerId setting being set first, or being set to an invalid string, I was getting an error message:
The caller does not have permission

Username in WebTokenRequestResult is empty

in a Windows 10 UWP I try use WebAuthenticationCoreManager.RequestTokenAsync to get the result from a login with a Microsoft account.
I get a WebTokenRequestResult with Success. ResponseData[0] contains a WebAccount with an ID - but the UserName is empty.
The scope of the call is wl.basic - so I should get a lot of information...
I'm not sure how to retrieve extra information - and for the current test the Username would be OK.
I checked out the universal samples - and there I found a snippet which tries to do what I'm trying - an output of webTokenRequestResult.ResponseData[0].WebAccount.UserName.
By the way - the example output is also empty.
Is this a bug - or what do I (and the MS in the samples) have to do to get the users profile data (or at least the Username)?
According to the documentation (https://learn.microsoft.com/en-us/windows/uwp/security/web-account-manager), you have to make a specific REST API call to retrieve it:
var restApi = new Uri(#"https://apis.live.net/v5.0/me?access_token=" + result.ResponseData[0].Token);
using (var client = new HttpClient())
{
var infoResult = await client.GetAsync(restApi);
string content = await infoResult.Content.ReadAsStringAsync();
var jsonObject = JsonObject.Parse(content);
string id = jsonObject["id"].GetString();
string name = jsonObject["name"].GetString();
}
As to why the WebAccount property doesn't get set... shrugs
And FYI, the "id" returned here is entirely different from the WebAccount.Id property returned with the authentication request.

How to get the ItemId of a forwarded email in ExchangeWebServices Managed API

I am using the EWS Managed API to find an EmailItem and forward it to another recipient. I want to record the ItemId of the forwarded email, but I can't figure out how to find this property.
var originalMail = EmailMessage.Bind(exchangeService, originalMailId);
var fwdMessage = originalMail.CreateForward();
fwdMessage.ToRecipients.Add("foo#bar.com");
fwdMessage.BodyPrefix = new MessageBody(BodyType.HTML, html);
fwdMessage.Subject = "Testing 123";
// Send the message
fwdMessage.SendAndSaveCopy();
How can I get the ItemId of the fwdMessage email?
It seems that the ResponseMessage object doesn't expose an ID. You could try stamping a GUID in a custom extended property before sending, then searching Sent Items for the item that has that GUID.

EWS Managed - Is it possible to get full "From" details using "FindItems"?

I'm using the Exchange Web Services Managed API to search a message folder using FindItems. The code I'm using is this:
var search = new SearchFilter.ContainsSubstring(
ItemSchema.Subject,
"subject I want");
ItemView searchView = new ItemView(9999);
searchView.PropertySet = new PropertySet(
BasePropertySet.IdOnly,
ItemSchema.Subject,
ItemSchema.DateTimeReceived,
EmailMessageSchema.From);
searchView.OrderBy.Add(
ItemSchema.DateTimeReceived,
SortDirection.Descending);
searchView.Traversal = ItemTraversal.Shallow;
var searchResults = _service.FindItems(
folderToSearch.Id,
search,
searchView);
The search works fine, and the properties I've specified in the searchView.PropertySet do get returned. The problem is that it doesn't return all of the details of From.
I iterate searchResults, and cast the items to type EmailMessage or PostItem as appropriate, to access the From property, which returns an EmailAddress object. On that object, the Name property is set, but Address is null.
If I then bind the item, like:
var boundItem = Item.Bind(_service, message.Id);
var boundItemEmail = boundItem as EmailMessage;
Then boundItemEmail.From.Address is not null, it returns the senders email address.
The trouble is, binding a message can be a rather time-consuming process, compared to the much faster FindItems operation.
You should be able to use the LoadPropertiesForItems method to get the From property, it's faster than binding to individual messages.

Why can't I compute a correct HMAC signature?

I am trying to compute an HMAC signature in Google Apps Script, but the documentation isn't 100% clear on how I need to pass in the parameters, and I have been unable to get the expected output.
To determine if I am getting correct output, I am comparing the result against known-good PHP code. That code is:
$key = "a2V5"; # this is "key" base64-encoded
$value = "test";
$result = base64_encode(hash_hmac('sha512', $value, base64_decode($key), true));
My code in Google Apps Script is:
key = "a2V5"; // this is "key" base64-encoded
value = "test";
result = Utilities.base64Encode(Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, value, Utilities.base64Decode(key)));
The output I expected to receive was:
KHoPuJp/vfpbVThjaRjlN6W4MGXk/zMSaLeqoRXd4EepsPT7W4KGCPwLYyfxAFX3Y3sFjp4Nu55piQGj5t1GHA==
But what I got instead was:
mGXJ3X/nH5ZIFUAPtf1PsViY50pD3cfU7J8w2KAIEAqrAgZ3dpKcuy5V1yvH4/C5n1C9rFFsKc2JKHTwUqPscQ==
What did I screw up here?
I reviewed your code and there is one thing which caught my eye:
Utilities.base64Decode(key) method returns Byte[]
Utilities.computeHmacSignature(macAlgorithm, value, key) accepts 3 parameters. value and key are of type string.
Maybe this is the issue. Why don't you try something like the following and check results then:
key = "a2V5"; // this is "key" base64-encoded
clearKey = "key";
value = "test";
result = Utilities.base64Encode(Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, value, clearKey));
I check Google Apps Script here.