I am using the Docusign Rest API, through a gem for Rails. I have 2 recipients, and need both of them to sign the document.
It should work like this:
Generate envelope with borrower(s) info passing to the envelope.
Display embedded document for signing.
Return to custom url/action
If there is another signer, it should
reload the iframe
ask for second signers signature, with the same template that was just signed
Instead it breaks when I reloads the iframe for the 2nd signer. It generates the envelope, with my second signer with its unique ID, email etc. However when I then create the recipient view, it returns nil.
How do I get signer 1 to sign, then load it for the second signer right after, with all the custom fields filled both times?
def deliver(signing_borrower)
client = DocusignRest::Client.new
hashData = {
status: 'sent',
template_id: my_id
signers: [
{
embedded: true,
name: signing_borrower.name,
email: signing_borrower_email,
role_name: if (signing_borrower==borrower) then 'Borrower' else 'Co-borrower' end
}
]
}
generate_liabilities
hashData[:signers][0][:tabs] = if (signing_borrower==borrower) then custom_fields else co_borrower_custom_fields end
#if there is a coborrower, add that data to the form as the second signer
if co_borrower
if signing_borrower==co_borrower then opposite_of_signing_borrower = borrower else opposite_of_signing_borrower = co_borrower end
borrower2= {
name: opposite_of_signing_borrower.name,
email: signing_borrower_email(opposite_of_signing_borrower),
role_name: if (opposite_of_signing_borrower==co_borrower) then 'Co-borrower' else 'Borrower' end
}
#add second borrower to hash to generate envelope with all form fields filled
hashData[:signers] << borrower2
hashData[:signers][1][:tabs] = {
textTabs: text_tabs,
checkboxTabs: checkbox_tabs
}
end
response = client.create_envelope_from_template hashData
self.envelope_id = response["envelopeId"]
self.signing_url = DocusignRest::Client.new.get_recipient_view({
envelope_id: self.envelope_id,
name: signing_borrower.name,
email: signing_borrower_email(signing_borrower),
return_url: return_url
})
response
end
The hashData
{:status=>"sent",
:email=>
{:subject=>"Application...",
:body=>"please sign...."},
:template_id=>"XXXX-XXXX-XXXX",
:signers=>
[{:embedded=>true,
:name=>"DAVID L. TESTCASE",
:email=>"email#test.com",
:role_name=>"Borrower",
:tabs=>
{:textTabs=>
[{:tablabel=>"phone",
:name=>"phone",
:value=>"717-717-7171"}]
}
},
{:name=>"MARISOL TESTCASE",
:email=>"email2#test.com",
:role_name=>"Co-borrower",
:tabs=>
{:textTabs=>
[{:tablabel=>"phone",
:name=>"phone",
:value=>"717-717-7171"}]
}
}]}
You can accomplish what you're trying to do by making 3 API calls:
Create Envelope request, specifying both recipients as 'embedded/captive' by setting clientUserId property for each recipient.
POST Recipient View request to get the URL to launch the first signer's signing session.
POST Recipient View request to get the URL to launch the second signer's signing session.
Here's example JSON for those three calls.
1 - Create Envelope Request
POST https://{{env}}.docusign.net/restapi/{{version}}/accounts/{{acctId}}/envelopes
{
"emailSubject": "Please sign this",
"emailBlurb": "Please sign...thanks!",
"templateId": "064A7973-B7C1-41F3-A2AD-923CE8889333",
"status": "sent",
"templateRoles": [
{
"roleName": "Borrower",
"name": "John Doe",
"email": "johnsemail#outlook.com",
"recipientId": "1",
"clientUserId": "123",
"tabs":{
"textTabs":[
{
"tabLabel":"BorrowerPhone",
"value":"717-717-7171"
},
],
}
},
{
"roleName": "Co-borrower",
"name": "Jane Doe",
"email": "janesemail#outlook.com",
"recipientId": "2",
"clientUserId": "567",
"tabs":{
"textTabs":[
{
"tabLabel":"Co-borrowerPhone",
"value":"717-717-7171"
},
],
}
}
]
}
A successful response will contain the Id of the newly created Envelope.
2 - POST Recipient View (for the First Recipient)
Make this call when the first signer is ready to sign. In the request URL, {{envelopeId}} is the Envelope Id value that was returned in the response of the Create Envelope request, and information in the request body corresponds to info you submitted for the first recipient in the Create Envelope request.
POST https://{{env}}.docusign.net/restapi/{{version}}/accounts/{{acctId}}/envelopes/{{envelopeId}}/views/recipient
{
"authenticationMethod": "Email",
"clientUserId": "123",
"userName": "John Doe",
"email": "johnsemail#outlook.com",
"returnUrl": "http://www.google.com"
}
The response will contain the URL that can be used to launch the DocuSign Envelope for the first recipient.
3 - POST Recipient View (for the Second Recipient)
Make this call when it's time for the second signer to sign. In the request URL, {{envelopeId}} is the Envelope Id value that was returned in the response of the Create Envelope request, and information in the request corresponds to info you submitted for the second recipient in the Create Envelope request.
POST https://{{env}}.docusign.net/restapi/{{version}}/accounts/{{acctId}}/envelopes/{{envelopeId}}/views/recipient
{
"authenticationMethod": "Email",
"clientUserId": "567",
"userName": "Jane Doe",
"email": "janesemail#outlook.com",
"returnUrl": "http://www.google.com"
}
The response will contain the URL that can be used to launch the DocuSign Envelope for the second recipient.
I think the problem is in the JSON request body that you're building. I'm curious where you added the embedded => true property from, that's not in the API docs or examples. As far as I know that is not a valid property, but I think the DocuSign API is forgiving in that it doesn't error out when non-recognized properties are sent, it ignores them instead.
In general, when you are creating Embedded (aka "Captive") recipients you need to configure at least 3 properties for these recipients:
1. email
2. name
3. clientUserId
All of these are client configurable (i.e. you can set them to whatever you want), however whatever values you use when adding each recipient.. you need to reference the same exact values when requesting a signing URL for them.
For example, to add two embedded recipients you can send the following (partial) request body:
"signers": [
{
"name": "Sally Doe",
"email": "test_1#email.com"
"clientUserId": "1000"
},
{
"name": "John Doe",
"email": "test_2#email.com"
"clientUserId": "1001"
}
]
If you do not specify the routingOrder for your recipients then it will default to routing order = 1. And if you don't specify a recipientId, the system will generate a unique GUID for each and assign to them.
Once your envelope has been created and your recipients have been added to it, you can then request the signing URLs, but as mentioned you'll need to reference the same values for name, email, and clientUserId.
For more info you can check out the page on Embedding functionality at the DocuSign Developer Center:
http://www.docusign.com/developer-center/explore/features
Related
I'm making a function and class for it with POST method.
Since I use FastAPI, it automatically generates API docs (using OpenAPI specification and Swagger UI), where I can see the function's description or example data there.
My class and function are like below:
from pydantic import BaseModel, Field
from typing import Optional, List
#app.post("/user/item")
def func1(args1: User, args2: Item):
...
class User(BaseModel):
name: str
state: List[str]
class Config:
schema_extra = {
"example": {
"name": "Mike",
"state": ["Texas", "Arizona"]
}
}
class Item(BaseModel):
_id: int = Field(..., example=3, description="item id")
Through schema_extra and example attribute in Field, I can see the example value in Request body of function description.
It shows like
{
"args1": {
"name": "Mike",
"state": ["Texas", "Arizona"] # state user visits. <-- I'd like to add this here or in other place.
},
"args2: {
"_id": 3 <-- Here I can't description 'item id'
}
}
However, I'd like to add description or comments to example value, like # state user visits above.
I've tried to add description attribute of pydantic Field, but I think it shows only for parameters of get method.
Is there any way to do this? Any help will be appreciated.
You are trying to pass "comments" inside the actual JSON payload that will be sent to the server. Thus, such an approach wouldn't work. The way to add description to the fields is as shown below. Users/you can see the descriptions/comments, as well as the examples provided, by expanding the corresponding JSON schema of a Pydantic model (e.g., "User") under "Schemas" (at the bottom of the page) when visting OpenAPI at http://127.0.0.1:8000/docs, for instance. Or, by clicking on "Schema", next to "Example Value", above the example given in the "Request Body".
class User(BaseModel):
name: str = Field(..., description="Add user name")
state: List[str] = Field(..., description="State user visits")
class Config:
schema_extra = {
"example": {
"name": "Mike",
"state": ["Texas", "Arizona"]
}
}
Alternatively, you could use Body field in your endpoint, allowing you to add a description that is shown under the example in the "Request body". As per the documentation:
But when you use example or examples with any of the other utilities
(Query(), Body(), etc.) those examples are not added to the JSON
Schema that describes that data (not even to OpenAPI's own version of
JSON Schema), they are added directly to the path operation
declaration in OpenAPI (outside the parts of OpenAPI that use JSON
Schema).
You could add multiple examples (with their associated descriptions), as described in the documentation. Example below:
#app.post("/user/item")
async def update_item(
user: User = Body(
...,
examples={
"normal": {
"summary": "A normal example",
"description": "**name**: Add user name. **state**: State user vistis. ",
"value": {
"name": "Mike",
"state": ["Texas", "Arizona"]
},
}
}
),
):
return {"user": user}
I'm not a programmer so please forgive me. But I've spent hours and hours of research on the topic of collecting information with Twilio AutoPilot and posted that data to Airtable, which I will then have Zapier do some things with that data. I finally had a breakthrough today and am now able to post data from a call or text to Airtable. The only way I got the ending to work was to send the call or text to Studio to finish up the call. Everything seems to work from the end user standpoint, but I'm getting an error 90100 from Twilio. I'm sure I'm just missing one line of code for this to work, and I'm at the end of my rope.
{
"actions": [
{
"say": "Okay lets get you a new appointment. I just need you to answer a few questions."
},
{
"collect": {
"name": "member",
"questions": [
{
"question": "Please tell me your first name.",
"name": "name",
"type": "Twilio.FIRST_NAME"
},
{
"question": "Thanks, and what is your email address?",
"name": "email",
"type": "Twilio.EMAIL"
}
],
"on_complete": {
"redirect": "task://complete_booking"
}
}
}
]
}
Then i have another task setup to redirect to the Twilio Function. This is probably overkill, but it's what I found in research.
{
"actions": [
{
"redirect": {
"method": "POST",
"uri": "https://TWILIO_FUNCTION_URL/atable_post"
}
}
]
}
Then the function is as follows. Mind you, this is posting correctly to airtable.
exports.handler = function(context, event, callback) {
let memory = JSON.parse(event.Memory);
let name = memory.twilio.collected_data.member.answers.name.answer;
let email = memory.twilio.collected_data.member.answers.email.answer;
console.log(memory);
let member = {
name : memory.twilio.collected_data.member.answers.name.answer,
email : memory.twilio.collected_data.member.answers.email.answer,
date : Date.now()
};
var Airtable = require("airtable");
var base = new Airtable({apikey: context.AIRTABLE_API_KEY}).base("AIRTABLE_ID");
base("Members1").create(member, function(err, record) {
if (err) { console.error(err); return; }
console.log(record.getId());
callback(null, member);
});
};
The call hung up at this point, so I redirected it to a Studio Flow, which does work and the call finishes with the response I'm give it before ending the call. Again, everything is working fine, but I get the following error from twilio, and I have no idea how to resolve it.
Invalid Autopilot Actions JSON: Invalid Autopilot Action
Any help would be greatly appreciated. Thanks!
Nice work James! It looks the the issue is the redirect to your Twilio Function is not returning the expected JSON Action response to execute.
Autopilot - Redirect
https://www.twilio.com/docs/autopilot/actions/redirect
Redirecting to URLs When redirecting to a URL, Redirect will make an
HTTP callback to your application and will expect an Autopilot Actions
JSON as a response. The request will contain all the dialogue
information. This is an example of a dynamic Action since the JSON is
rendered dynamically with a URL or your own endpoint.
Can you modify the Twilio Function to return valid Action JSON to Autopilot which sets the returned data, if needed via the Remember action which you can access from Studio?
I am wondering if the /v1.0/me/sendMail has the ability to delay sending an email. In the Outlook client, you can specify that you want your email sent at a later date and time. I've snooped around to see if there is a property that can be set on the message object to indicate this.
Did anyone find a way to get this working? Of course, I could implement something in my software to handle the delayed sending, but why re-create something if it is already there.
You can achieve delayed sending of emails using extended properties. These can be set on the Graph API request payload using the "singleValueExtendedProperties" attribute.
The property to use is PidTagDeferredSendTime which has the ID 0x3FEF and type SystemTime.
The id attribute of "singleValueExtendedProperties" takes different formats depending on the property you are setting.
For the deferred send time you would use SystemTime 0x3FEF.
Example using a HTTP JSON POST Payload:
{
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "The new cafeteria is open."
},
"toRecipients": [
{
"emailAddress": {
"address": "bob#contoso.com"
}
}
],
"singleValueExtendedProperties":
[
{
"id":"SystemTime 0x3FEF",
"value":"2019-01-29T20:00:00"
}
]
}
}
Example using the Microsoft Graph API client library:
var client = /* Create and configure GraphServiceClient */;
var msg = new Message();
msg.ToRecipients = List<Recipient>();
msg.ToRecipients.Add(new Recipient() {
EmailAddress = new EmailAddress() { Address ="bob#contoso.com" }
};
msg.Subject = "Meet for lunch?";
msg.Body = new ItemBody()
{
Content = "The new cafeteria is open.",
ContentType = BodyType.Text,
};
msg.SingleValueExtendedProperties = new MessageSingleValueExtendedPropertiesCollectionPage();
msg.SingleValueExtendedProperties.Add(new SingleValueLegacyExtendedProperty()
{
Id = "SystemTime 0x3FEF",
Value = DateTime.UtcNow.AddMinutes(5).ToString("o")
});
await client.Me.SendMail(msg, true).Request().PostAsync();
https://gallery.technet.microsoft.com/office/Send-Emails-until-a-9cee20cf
You set the deferred send time extended prop when creating the item.
How Can I send a post notification to specific tag like (username: "#john") from Swift/iOS Native SDK. I have sendTag OneSignal before. I'm sending below a user with playerID. But It's not enough. Someone can login with different accounts. So same playerID will be for all of them. When I add tag line it doesn't work as I expect. How to work Player ID && username tag together.
OneSignal.sendTag("username", value: "\(username)")
If someone explain this, It would be great.
DataService.ds.REF_USERS.child(userUUID).child("playerID").observeSingleEvent(of: .value, with: { snapshot in
if let playerID = snapshot.value as? String {
OneSignal.idsAvailable({ (userId, pushToken) in
print("UserId:%#", userId ?? "")
self.showErrorAlert("Player ID Here:", msg: "\(userId!)")
if (pushToken != nil) {
OneSignal.postNotification(["contents": ["en": "#username wrote a comment: \(trimmed)"],
"include_player_ids": [playerID],
"send_after": "2017-01-10 20:10:00 GMT+0300",
"tag": ["field": "tag", "key": "username", "relation": "=", "value": "john",
])
}
})
}
})
For security reasons, OneSignal does not allow you to use tag targeting from within your app code.
OneSignal does allow you to target devices using the include_player_ids field from within your app though.
Note that OneSignal also does not allow you to combine different targeting parameters. So you may not use both include_player_ids and tags targeting together.
To send notifications based on username, use the OneSignal.sendTag method to assign the username like in your example. Next, from your server-side code, use the filters targeting parameter to send a notification to all users with that username.
For instance, here is an example of how to do this in Ruby:
params = {"app_id" => "5eb5a37e-b458-11e3-ac11-000c2940e62c",
"contents" => {"en" => "English Message"},
"filters" => [
{"field": "tag",
"key": "username",
"relation": "=",
"value": "(username)"}
]
}
uri = URI.parse('https://onesignal.com/api/v1/notifications')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.path,
'Content-Type' => 'application/json;charset=utf-8',
'Authorization' => "Basic NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj")
request.body = params.as_json.to_json
response = http.request(request)
puts response.body
You can find additional examples in the OneSignal documentation here.
Want to add a transformed object along with other response, I have used following code:
$accessToken = Authorizer::issueAccessToken();
$user = User::where('email', $request->get('username'))->with('profile')->first();
if ($user) {
$accessToken['user'] = $this->response->item($user, new UserTransformer);
}
return $accessToken;
Expected Response:
{
"access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"token_type": "Bearer",
"expires_in": 31536000,
"data": {
"id": 1,
"email": "xxxxx",
"profile": {
"data": {
"id": 1,
"first_name": "Muhammad",
"last_name": "Shakeel",
}
}
}
}
but not getting transformed object, there must be some better way to add multiple transformed objects with response. Am I missing something?
Edit
Current response returns user object without transformation and if I return only user transformed object like following, it returns correct transformed object:
return $this->response->item($user, new UserTransformer);
As discussed on the issue tracker(https://github.com/dingo/api/issues/743#issuecomment-160514245), jason lewis responded to the ticket with following:
The only way you could do this at the moment would be to reverse that. So you'd return the response item, then add in the access token data, probably as meta data.
So, something like this.
return $this->response->item($user, new UserTransformer)->setMeta($accessToken);
The response will then contain a meta data key which will contain your access token data.
I got it to work using Internal Requests. https://github.com/dingo/api/wiki/Internal-Requests
So what you can do is
Suppose you have a route that fetches transformed user object at api/users/{email_id}?access_token=...
While issuing the access_token you can do the following :
$dispatcher = app('Dingo\Api\Dispatcher');
$array = Authorizer::issueAccessToken();
$array['user'] = $dispatcher->get('api/users/'.$request->get("username").'?access_token='.$array['access_token']);
return $array;
This will return transformed data.
NOTE : You will need to have a route that fetches user data.
You will have to handle cases in /api/users/{email-id} where email-id does not exist.