If statement in JSon - json

I work a no-code app maker called Adalo. I am connected my app to a API that sends emails automatically. But in order for me to connect to the API, I must first "Run Test Request" which tries to send a request to the API. If I put an email into the "to" instead of "User Email" it will work perfectly. However, I currently have it set as a variable which is populated by data records. When I try to "Run Test Request", it does not work, because it does not no where to pull the data from during the test (it knows where to get the data outside the test). So what happens is the "To" email becomes "" which it says is an invalid email, so the test cannot pass. I am trying to think of a work around, because I know the code works, its just that the test wont let it work with a variable. So I wanted to know if I could some how create an if statement that said something like
if User Email == ""
then User Email = "g#gmail.com"
The syntax is wrong, but hopefully you understand what I am getting at.
Below is the current code I have. This has to be in JSON, my understand is that I cannot insert Java.
{
"sender": {
"name": "Peculiar Yogi Mail",
"email": "namaste#peculiaryogi.com"
},
"to": [{
"email": "USER EMAIL",
"name": "USER FIRST NAME"
}],
"subject": "Peculiar Yogi Class Booking Confirmation",
"htmlContent":"<html><head></head><body><p>Hello,</p><p>This is to confirm that you've successfully booked a class at Peculiar Yogi.</p><p>Class Name:</p><p>Class Instructor</p><p>Class Time:</p><p>Namaste.</p></body></html>"
}

Related

ADF V2 - Web POST method using Dynamic Content and Variable

Very short version
How do I include an ADF Variable inside a JSON POST request, in a Web Activity within ADF?
I feel like this should be a very simple string concatenation, but i can't get it to work
Detail
We have a requirement to run a query / SProc from within ADF, which will return a string containing an error message. That string is to then be passed via the Web Activity in ADF to a Logic App, in order to fire off an email, containing the error.
The setup of the logic app is copied from here:
https://www.mssqltips.com/sqlservertip/5718/azure-data-factory-pipeline-email-notification--part-1/
and then here (part 2)
https://www.mssqltips.com/sqlservertip/5962/send-notifications-from-an-azure-data-factory-pipeline--part-2/
In ADF, I used the Lookup activity, to run a query, which brings back the error (appears to work, the preview returns the correct string)
Then I use the Set Variable activity, to take the output of the lookup and store it in a variable.
Last Step is to fire off the POST using the Web Activity.
With this code (tweaked slightly to remove personal details) in my Web Activity, everything works fine and I receive an email
{
"DataFactoryName": "#{pipeline().DataFactory}",
"PipelineName": "#{pipeline().Pipeline}",
"Subject": "Pipeline finished!",
"ErrorMessage": "Everything is okey-dokey!",
"EmailTo": "me#myEmail.com"
}
But any attempt to put the contents of the Variable into the Subject part has failed.
This (for example) sends me an email with the subject literally being #variables('EmailSubject')
{
"DataFactoryName": "#{pipeline().DataFactory}",
"PipelineName": "#{pipeline().Pipeline}",
"Subject": "#variables('EmailSubject')",
"ErrorMessage": "Everything is okey-dokey!",
"EmailTo": "me#myEmail.com"
}
But I've also attempted various other solutions that result in errors or the email subject just containing the literal thing that I put in there (e.g. + #variables('EmailSubject') +).
I also tried storing the entire JSON in the Variable, and then having the Web activity use only the variable, that returned no errors, but also did not send an email.
This attempt:
{
"DataFactoryName": "#{pipeline().DataFactory}",
"PipelineName": "#{pipeline().Pipeline}",
"Subject": "#{variables('EmailSubject')}",
"ErrorMessage": "Everything is okey-dokey!",
"EmailTo": "me#myEmail.com"
}
Resulted in this input into the web activity - which actually includes the text of the error, which is a bonus ... (text = Job Duration Warning):
{
"url": "https://azureLogicAppsSiteHere",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": "{\n \"DataFactoryName\": \"DFNAMEHERE\",\n \"PipelineName\": \"pipeline1\",\n \"Subject\": \"{\"firstRow\":{\"\":\"Job Duration Warning\"},\"effectiveIntegrationRuntime\":\"DefaultIntegrationRuntime (West Europe)\",\"billingReference\":{\"activityType\":\"PipelineActivity\",\"billableDuration\":[{\"meterType\":\"AzureIR\",\"duration\":0.016666666666666666,\"unit\":\"DIUHours\"}]},\"durationInQueue\":{\"integrationRuntimeQueue\":0}}\",\n \"ErrorMessage\": \"Everything is okey-dokey!\",\n \"EmailTo\": \"me#myEmail.com\"\n}\t"
}
But then resulted in this error:
{
"errorCode": "2108",
"message": "{\"error\":{\"code\":\"InvalidRequestContent\",\"message\":\"The request content is not valid and could not be deserialized: 'After parsing a value an unexpected character was encountered: f. Path 'Subject', line 4, position 17.'.\"}}",
"failureType": "UserError",
"target": "Web1",
"details": []
}
[Edit] The PREVIEW from the Lookup Activity is the text: Job Duration Warning BUT when I debug the pipeline, it lets me see the actual Output, which is this:
{
"count": 1,
"value": [
{
"": "Job Duration Warning"
}
],
"effectiveIntegrationRuntime": "DefaultIntegrationRuntime (West Europe)",
"billingReference": {
"activityType": "PipelineActivity",
"billableDuration": [
{
"meterType": "AzureIR",
"duration": 0.016666666666666666,
"unit": "DIUHours"
}
]
},
"durationInQueue": {
"integrationRuntimeQueue": 0
}
}
So it appears that the problem is that the Lookup Output isn't what I thought it was, so the variable can't be used in the Web Activity, as it contains unsupported characters or something along those lines.
I just tested this and it worked ok:
Create a String Parameter with the value Job Duration Warning
Set the Variable value to be #pipeline().parameters.ParamSubject
Include the variable in the web activity with an # in front of it
I then receive my expected email with the right subject. I just don't know how to get the string output of my query, into a variable / parameter, so that i can use it in the web activity.
I don't know how well this applies to other people's issues, but I found a solution that has worked for me.
In the SELECT query within the Lookup Activity - name the output (in my case, I called that column 'Subject'- i.e. SELECT xyz AS Subject
In the Lookup Activity, turn on the setting 'First Row Only'
In the Set Variable Activity, use the code: #activity('Lookup1').output.firstRow.subject
(where 'Lookup1' is the name of your Lookup Activity and Subject is the name of the column you are outputting)
In the Web Activity, reference the variable as follows:
{
"DataFactoryName": "#{pipeline().DataFactory}",
"PipelineName": "#{pipeline().Pipeline}",
"Subject": "#{variables('EmailSubject')}",
"ErrorMessage": "Everything is okey-dokey!",
"EmailTo": "me#myEmail.com"
}

Integration from CRM to Team Foundation Server 2018

We have CRM where customers create tickets (change requests, incidents...).
From developer team side we have Team Foundation Server 2018.
To speed up process we would like to automatize entire thing. So, when customer create ticket, to automatic create TFS User Story.
We developed code to take, every time when ticket is created, data and put into JSON file. (will attach code in Github and share a link)
But now, I just need info, is someone have an idea, how JSON file should looks like which need to post to TFS in order to create new user story.
{
"fields": {
"System.WorkItemType": "User Story",
"System.AreaPath": "EJ2TFS",
"System.TeamProject": "EJ2TFS",
"System.IterationPath": "EJ2TFS",
"System.State": "New",
"System.Reason": "New",
"Microsoft.VSTS.Common.StateChangeDate": "2019-01-01T00:00:00Z",
"System.ChangedBy": "Doe, John <firm\\doej>",
"System.CreatedBy": "Doe, John <firm\\doej>",
"System.Title": "Sample task created by POST API",
"System.Discussion":"test1",
"Microsoft.VSTS.Common.StateChangeDate": "2019-01-31T14:00:00",
"Microsoft.VSTS.Common.Priority": 2,
"Microsoft.VSTS.Common.ValueArea": "Business"
}
}
And error is:
{
"$id": "1",
"innerException": null,
"message": "The request indicated a Content-Type of \"text/plain\" for method type \"POST\" which is not supported. Valid content types for this method are: application/json-patch+json.",
"typeName": "Microsoft.VisualStudio.Services.WebApi.VssRequestContentTypeNotSupportedException, Microsoft.VisualStudio.Services.WebApi",
"typeKey": "VssRequestContentTypeNotSupportedException",
"errorCode": 0,
"eventId": 3000
}
Looks like your payload need a makeover. I referred couple of code samples & sharing this snippet. (Pls test this, I didn’t get a chance to test it)
POST https://dev.azure.com/fabrikam/{project}/_apis/wit/workitems/$User Story?api-version=5.0
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "My first user story"
}
]
MS documentation example
GitHub sample

Chatfuel redirect_to_blocks does not work

I have a problem with my chatfuel JSON API from my node JS app.
I try to catch an error and return a message + a redirect_to_block to be able to ask the user again.
My error detection works well and if I try to display a message only it works. My JSON is :
[{"text":"Please type again"}]
But I can't add a redirect_to_blocks to this (and I even loose the text message display).
I tried those solutions (and probably some more) but I think I didn't get the JSON structure :
// Solution 1
[{ "message": { "text": "Please type again" }, "redirect_to_blocks": ["When?"] }]
// Solution 2
[{ "messages": { "text": "Please type again" }, "block_names": ["When?"], "type": "show_block", "title": "go" }]
// Solution 3
[{ "text": "Please type again" }, "redirect_to_blocks": ["When?"] }]
And here is the block I want to add (i'm not even sure the name I have to give to the JSON)
Thanks !
Julian, workaround that works for me is returning from API following JSON:
{
"set_attributes": {
"redirectBlock": <your block name>
}
}
and build structure in Chatfuel as below:
Chatfuel flow
Now you have a dispatcher that allows you to map values from API to block titles.
I had your same issues,
I created a json request in my Flow that returns this json:
{ "redirect_to_blocks": ["Block name"] }
but Chatfuel never redirects to it.
I solved it creating a new block in "Automate" pane with same name and It works.
I know that it's passed much time since your question,
but I hope it can helps future issues.

authorization_invalid_request error when preparing DocuSign envelope for tab modification

I am trying trying to create a draft envelope from a template and then modify some of the tabs in the template. I'm getting an AUTHORIZATION_INVALID_REQUEST response.
My initial request is to the following URL https://demo.docusign.net/restapi/v2/accounts/<account id>/envelopes
and the payload is as follows:
{
"status": "created",
"emailSubject": "2015-01-27T16:25:43.133-05:00 Docusign Template Request",
"emailBlurb": "email blurb",
"templateId": "<template id>",
"brandId": "<brand id>",
"templateRoles": [
{
"name": "<name>",
"email": "<email>",
"roleName": "<role>",
"clientUserId": "",
"emailNotification": {
"supportedLanguage": "en",
"emailSubject": "<subject>",
"emailBody": "special email body"
}
}
],
"allowReassign": "true",
"enableWetSign": "false",
"messageLock": "false"
}
That produces the following response:
{
"envelopeId": "<envelope id>",
"uri": "/envelopes/<envelope id>",
"statusDateTime": "2015-01-28T22:09:43.9770000Z",
"status": "created"
}
Then I send a recipient view request to the following URL:
https://demo.docusign.net/restapi/v2/envelopes/<envelope id>/views/recipient using the envelope id received in the above response.
This results in the following response:
{
"errorCode": "AUTHORIZATION_INVALID_REQUEST",
"message": "The authorization request is malformed."
}
Note that if I had set the first request above to a status of "sent" (and thus did not create a draft envelope), the second request would have been successful.
However according to DocuSign documentation (p. 163 of the API guide), the modify tabs API call "modifies one or more tabs for a recipient to a draft envelope". Accordingly to perform a tab modification I need a draft envelope, not a sent one. But when I create a draft envelope, the views/recipient call fails as above.
I can add tabs successfully to a "sent" envelope. But I would rather modify tabs and am having trouble doing that.
You're not hitting a valid DocuSign Endpoint. Where did you get the /v2/envelopes/<envelope id>/views/recipient URL from? That's not a proper URL hence the error message you are getting.
After you create the envelope if you want to modify a given recipient's tabs then you need to make the following API call:
Modify Tabs for Recipient
Note that this is a PUT call not a POST, and URI is:
/accounts/{accountId}/envelopes/{envelopeId}/recipients/{recipientId}/tabs
For example, if you wanted to modify tabs for recipient who is recipientId = 3 you would make a call similar to (notice the 3 in the URL):
PUT https://demo.docusign.net/restapi/v2/accounts/12345/envelopes/{envelopeId}/
recipients/3/tabs
X-DocuSign-Authentication: <DocuSignCredentials><Username>{name}</Username><Password>{password}</Password><IntegratorKey>{integrator_key}</IntegratorKey></DocuSignCredentials>
Accept: application/json
Content-Type: application/json
{
"approveTabs":[{
<Tab information removed>
}],
"titleTabs":[{
<Tab information removed>
}],
"signHereTabs":[{
<Tab information removed>
}]
}
I'm not sure if this qualifies as an "answer" to my question, but it does appear that the problem has somehow been resolved. I let it rest for a couple days while I attended to other matters, then yesterday afternoon suddenly it started working, with no changes on my part. The specific part that wasn't working was attempting a PUT on an envelope in order to modify the tags. That is not supposed to work unless the envelope is a draft; my envelopes have all been drafts. Wasn't working a couple days ago, and now it is. #Pete and #Dorian: you might want to try it again if you haven't already; if you're not doing anything else wrong it might work now.

How do you cancel a PayPal subscription through their api?

On this page:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECRecurringPayments
it says that it's possible to cancel a PayPal subscription using their API. Knowing the SubscriptionId can anyone give me some code example how to do this?
Many thanks.
Did you manage to find an easy solution ? I'm looking for this as well. Thanks!
Update : After searching, the "ManageRecurringPaymentsProfileStatus" is very easy to use through a simple POST request.
Make sure that your user, password or signature are not visible (in other words, do this on your server and NOT on your client via javascript or html posts).
Below a simple working example in Python. It works and I'm now using it daily.
import urllib
from google.appengine.api import urlfetch
form_fields = {
"METHOD": "ManageRecurringPaymentsProfileStatus",
"PROFILEID": "xxx", # put your subscription ID here
"ACTION": "cancel",
"USER": "xxx", # Get USER, PWD, and SIGNATURE from your Paypal's account preferences
"PWD": "xxx",
"SIGNATURE": "xxx",
"VERSION": "54.0"
}
api_url = 'https://api-3t.sandbox.paypal.com/nvp' # remove the sandbox part for production
form_data = urllib.urlencode(form_fields)
result = urlfetch.fetch(url=api_url,
payload=form_data,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded'})
The response is a string that looks like this:
TIMESTAMP=2011%2d01%2d28T14%3a47%3a45Z&CORRELATIONID=148ebe1d25566&ACK=Failure&VERSION=54%2e0&BUILD=1704252&L_ERRORCODE0=11552&L_SHORTMESSAGE0=Invalid%20profile%20ID&L_LONGMESSAGE0=The%20profile%20ID%20is%20invalid&L_SEVERITYCODE0=Error
The 'ACK' field indicates 'Failure' or 'Success'.
In answer to comments below, note that it DOES enable me to cancel the subscriptions that have been created through a dynamically created link such as :
Subscribe
Note that I do not use the flag 'modify' at all.