Friday, June 27, 2025

Postman pre-Script

Open up Postman and go to the Pre-request Script tab.  

 

Below is the skeleton that needs to be pasted into it if you don’t want to use the attached file:

 

const crypto = require('crypto-js');

const secret = ‘my-secret';

 

const body = {

    "event": "envelope-completed",   

    "data": {       

        "envelopeId": "2b6a9e15-b8ca-43f3-9e7b-e505504560ed",

        "envelopeSummary": {         

            "envelopeDocuments": [

                {

                    "documentIdGuid": "cbf2d203-12fd-4f93-9eb9-1e7e738e8206",

                    "PDFBytes": "",

                    "documentFields": [

                        {

                            "name": "DocumentRequestId",

                            "value": "1"

                        }

                    ]

                },

                {

                    "documentIdGuid": "090fe7f3-33ab-4ad9-b98a-d9d554616a1a",

                    "PDFBytes": ""

                }

            ]

        }

    }

};

 

const jsonString = JSON.stringify(body);

const hmac = crypto.HmacSHA256(jsonString, secret);

const signature = crypto.enc.Base64.stringify(hmac);

 

// Set environment variables

pm.environment.set("calculated_signature", signature);

pm.environment.set("request_body", jsonString);

 

Saturday, April 12, 2025

Get access token with JWT Grant

 1.       Request application consent (no need to copy code from redirect link localhost, code is only needed for Auth Code Grant) 
https://account-d.docusign.com/oauth/auth?Rresponse_type=code&scope=signature&client_id= 6e18b0f9-………b0ac2fc5a4d3&redirect_uri=http://localhost/
2.      Create a JWT 
To authenticate in the JWT Grant flow, you will need to create a JWT containing data on the authentication request, then exchange it for an access token  From https://jwt.io/ encode Header and Payload data 
Get “iat” from current epoch time from https://www.epochconverter.com/ , make sure this is run after step 1  Set “exp” to “iat”+6000        3) Get AccessToken from postman  POST https://account-d.docusign.com/oauth/token  Body:   assertion= {the encoded content from jwt.io}  grant_type  =urn:ietf:params:oauth:grant-type:jwt-bearer    4)Same as Auth Code Grant, call API with AccessToken 

Thursday, April 10, 2025

Get an Access Token Using Auth Code Grant

 Auth Code Grant: your app will make API calls on behalf of the user, act as them to create envelopes and perform actions in the DocuSign APIS 

Postman Collections: https://developers.docusign.com/tools/postman/ 

 

Get an Access Token Using Auth Code Grant  

https://www.youtube.com/watch?v=4cn7Mvmq0Lo  

Application: Lotus1 

Secret: 5d9609dc…6f35a 

Integration (Client ID): af5030a1-……2-debeb4de16b5 

combined:af5030a1-…-debeb4de16b5:5d9609dc…2e2d2976f35a 

 

1)From browser dev console run: btoa('af5030a1-80b4-…:5d9609dc-bd76-…2e2d2976f35a') result is below

encoded key: 'YWY1MDMwYTEtODBiNC0…=='  

 

2)Get authorization code from this link:(open the link from web browser, it expires soon) 

https://account-d.docusign.com/oauth/auth?Rresponse_type=code 

&scope=signature 

&client_id=af5030a1-…ebeb4de16b5 

&redirect_uri=http://localhost/ 

Copy code from localhost after code as authorization code  

 

3)Get AccessToken from postman  

POST https://account-d.docusign.com/oauth/token 

Header: 

Authorication: Basic{the combination of your integration key,your secret key, based64encoded} 

Body: 

code = your auth code from  the link (https://account-d.docusign.com/oauth/......) 

grant_type=authorication_code  

  

4)Get user info with accesstoken 

https://account-d.docusign.com/oauth/userinfo 

Header: 

Authorication: Bearer {AccessToken} 

 

Thursday, April 11, 2024

Dependency Injection Issue for HttpClient

DI issue,  Unable to resolve service for type 'System.String' while attempting to activate 'xxx.Client'."https://stackoverflow.com/questions/69333244/proper-way-to-di-nswag-auto-generated-client/69335191#69335191
<ItemGroup>
<OpenApiReference Include="OpenAPIs\swagger.json" CodeGenerator="NSwagCSharp"> <SourceUri>https://localhost:7268/swagger/v1/swagger.json</SourceUri>
<Options>/UseBaseUrl:false /GenerateClientInterfaces:true</Options>
 </OpenApiReference>
 </ItemGroup>

https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?source=recommendations&view=aspnetcore-7.0&tabs=visual-studio

Install-Package Swashbuckle.AspNetCore -Version 6.2.3
1)Create WebAPI with  swagger/OpenAPI
2)Create Web Application, add OpenAPI  service reference
  eg: URL:  https://localhost:7179/swagger/v1/swagger.json
3)From Web Application, create a client call the API
 public List<WeatherForecast> Forecasts { get; set; }  
 public async Task OnGet()
        {
            swaggerClient swaggerClient;
            string baseUrl = "https://localhost:7165/";
            using (var client = new HttpClient())
            {
                swaggerClient = new swaggerClient(baseUrl, client);
                Forecasts =(List < WeatherForecast >)await swaggerClient.GetWeatherForecastAsync();
            }
        }

Thursday, August 10, 2023

How to generate class from Db or create db from class

 After install Microsoft.EntityFrameworkCore, Microsoft.EntityFramwworkCore.Sqlserver, Microsoft.EntityFrameworkCore.Tools

From PM console command line
Code First
1) Add-Migration InitialCreate  (it will create a migration fold with code)
2) Update-database ( it will create a DB with data table defined)

From PM console command line drop down list, set Default Project which will  accommodate class
DB first:
scaffold-dbcontext  "Server=sqldev;Database=Timesheet;Trusted_Connection=True;TrustServerCertificate=true;MultipleActiveResultSets=true;"  Microsoft.EntityFrameworkCore.Sqlserver -outputdir Models -force

Saturday, April 08, 2023

How to make mp3 file surface in spotify local folder in IPhone

 1) Airdrop a mp3 file from Iphone to Macbook

2) Add mp3 file to Macbook music folder so music app can play it

4) Connect Iphone to Macbook 

5) Right click the song in music app and select menu "Add to device", select the connected Iphone

6) song can be played in Iphone music app

7) From spotify setting, turn on local folder, now spotify can play the song in music app

Note: IPhone can't open mp3 file directly, need to sysc from macbook or itune music app


Thursday, March 23, 2023

How to publish and host ASP.NET Core webapp in IIS

 (https://stackify.com/how-to-deploy-asp-net-core-to-iis/)

0) Install .NET Core Windows Server Hosting Bundle

   (https://dotnet.microsoft.com/en-us/download)

1) Open the web application project and publish to file

2) Copy files from publish folder to c:\inetpub\wwwroot

3) Create Application Pool from IIS Manager , choose "No Managed Code" for ".NET CLR Version"

4) Create a website pointing to files folder created in Step 2, and  choose Application Pool created in step 3



For .NET Core Web API, after build, there is an .exe file, just run it, it will start the web API Service

Blog Archive