<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Job Masai on Medium]]></title>
        <description><![CDATA[Stories by Job Masai on Medium]]></description>
        <link>https://medium.com/@JobMasai?source=rss-cbc69adf2745------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*9M0cRE0xnfN4eCXY.</url>
            <title>Stories by Job Masai on Medium</title>
            <link>https://medium.com/@JobMasai?source=rss-cbc69adf2745------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 23:58:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@JobMasai/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[On building Innovation Culture among Product Teams]]></title>
            <link>https://medium.com/@JobMasai/on-building-innovation-culture-among-product-teams-9b73cac8107f?source=rss-cbc69adf2745------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b73cac8107f</guid>
            <category><![CDATA[product-development]]></category>
            <category><![CDATA[leadership]]></category>
            <category><![CDATA[product-design]]></category>
            <category><![CDATA[product-management]]></category>
            <category><![CDATA[product-strategy]]></category>
            <dc:creator><![CDATA[Job Masai]]></dc:creator>
            <pubDate>Mon, 06 May 2024 23:48:38 GMT</pubDate>
            <atom:updated>2024-05-06T23:48:38.822Z</atom:updated>
            <content:encoded><![CDATA[<h3>On Building Strong Product Teams</h3><p><em>Lessons from Maty Cagan — How to create tech products customers love.</em></p><blockquote>What comes to your mind whenever you hear about a product? :)</blockquote><blockquote>Welcome back to our first episode where we shall be looking at a few principles when it comes to building strong product teams at our current times when the world is rapidly moving fast in the age of A.I(Artificial Intelligence). I hope you enjoy the reading :)</blockquote><p>With the emergence of AI of late, it&#39;s clear that we are living at such a time where the boundaries of technology are constantly being pushed, offering possibilities that were once deemed unimaginable. With just a click, complexities that once seemed far away from our reach are now possible, thanks to the widespread integration of artificial intelligence (AI) across various sectors. Whether in education, healthcare, transportation, agriculture, or construction, AI is driving the creation of groundbreaking products that are reshaping our world daily.</p><p>In addition to such remarkable advancements, the focus remains firm on delivering innovative products that address a series of global challenges, all aimed at enhancing the lives of people worldwide. Thanks to dedicated teams and organizations working tirelessly on cutting-edge solutions, we’ve witnessed a notable increase in the success rate of new products compared to the past decade as a result of such advancements in the tech world.</p><p>Currently, product teams across different industries are diligently striving to deliver solutions that address specific pain points within their respective markets. Consequently, new products are being launched daily to meet the needs of consumers with a core focus being set on improving their day-to-day challenges. Recognizing these milestones, it’s imperative to explore some of the foundational principles that are essential for modern teams tasked with developing solutions for our consumers.</p><p>Hypothetically, every company operates as a product-focused organization in today’s landscape. With consumers having several choices, the need to create robust products that deliver delightful experiences is undeniable. It’s worth noting that the development of all products is the culmination of collaborative efforts from various teams. These teams, collectively known as “product teams,” converge to brainstorm ideas, iterate relentlessly, and ultimately deliver the final product to consumers.</p><p>With such an understanding, its clear product teams serve as indispensable assets for all organizations navigating the current digital landscape. Their pivotal role in delivering successful products cannot be overstated. However, their ability to achieve excellence becomes largely influenced by the organizational culture and the conducive environment they operate within. Without a culture that fosters innovation, all their efforts end up with the risk of being rendered ineffective, as their impact fails to resonate with leadership.</p><p>For organizations working to deliver digital products that resonate with consumers, one truth becomes clear: without a spirit of innovation, the quest for products that truly captivate consumers becomes an elusive endeavor. To address such challenges, we shall look at a few principles aimed at building a strong innovation culture of innovation within product teams.</p><p><strong>Principle no. 1: #Product Mindset culture.<br></strong>What comes to your mind when you hear of product mindset? When we talk about product mindset, it simply means that our products are delivered through a defined process that starts from understanding the problem we want to solve by clearly understanding the pain points for our users and the solutions we want to present to them. This process means we don&#39;t just wake up and decide to deliver solutions to customers, rather there is a background story behind the solution we are delivering to customers. By having a product mindset in the solutions being developed by consumers, it means we are deeply focused on the pains our customers experience as they use our products and the solutions being developed by organizations today have been fully reworked to perfectly fit the needs of our customers. A strong product team carefully focuses on making data-driven decisions backed by research instead of making decisions out of emotions.</p><p><strong>Principle no. 2 # Strong Product Teams.<br></strong>It&#39;s impossible to deliver customer-oriented products without a culture that consists of strong product teams. Having a strong product team, means organizations have an established product team that deeply understands the domain they operate in and the challenges faced in such an environment while at the same time having a consistent track record of delivering delightful products to consumers. Such efforts can only happen in an environment where organizations have a very strong culture of supporting teams in delivering delightful experiences.</p><p><strong>Principle no. 3# Strongly packed Product Managers :)<br></strong>Without a strong set of PMs, organizations can&#39;t deliver delightful products that consumers love. Organizations competing in the current digital world are required to have a strong set of PMs who can clearly articulate the needs of the consumers while at the same time working with internal teams to ensure the products being delivered to consumers are perfectly developed to meet their needs. Without strong PMs, it becomes difficult for organizations to satisfy the modern consumer as this means the products being developed lack a proper background on why they exist in the first place akin to shooting in the dark !</p><p><strong>Principle no. 4# A well defined Product Strategy.<br></strong>In general, everyone has a “strategy until they get punched in the face.” Without a well-defined product strategy, it becomes difficult for organizations to deliver strong products in the markets they operate. Organizations are encouraged to clearly understand the markets they operate in and focus on solving key defined products without trying to deliver products for everyone. While the market is big for everyone, the dynamics of our current times will highly disappoint teams that fail to identify their unique key propositions as they solve problems for the modern consumer.</p><p><strong>Principle no. 5# Customer Obssesed<br></strong>In our current times, it&#39;s difficult to deliver delightful experiences to customers without establishing a culture that passionately connects with the consumers we serve. Users have a lot of choices nowadays and they can easily tell when organizations neglect their plea to deliver products that deeply connect with them when it comes to solving their problems. Being <strong>customer-obsessed</strong> is <strong>not just about the statement in itself,</strong> it requires <strong>deep commitment </strong>towards connecting with users and understanding their problems while at the same time going above and beyond when it comes to solving their pain points. This is the only way modern organizations can differentiate themselves in the competitive world where consumers have choice and power.</p><p><strong>Principle no 6# Compelling Product Vision<br></strong>According to the dictionary definition, vision refers to “<strong>the ability to think about or plan the future with imagination or wisdom”</strong>.<br>All organizations today have a mission and vision of where they want to go and how to get there. No company today has been founded with a purpose to fail. Every organization is working tirelessly to delight its customers with compelling experiences that positively touch their lives. Strong product teams are empowered to ride on the set vision of the original idea on where the company’s direction is heading while on the side working tirelessly with cross-platform teams in ensuring they are putting efforts towards developing products with a clear focus on the market they are operating. Without product vision, organizations end up finding themselves losing to the competition as a result of failing to focus on the original plan they intended to pursue. While pivoting to new avenues is sometimes required, organizations need to build a strong culture that is guided by the original vision of what was earlier intended while on the side taking notes of emerging trends and quickly adapting to changing consumer demands.</p><p>Having illustrated some of the few principles of building a strong innovation culture among product teams, I hope you felt empowered further to carry on with the spirit of building delightful experiences for your customers as you work tirelessly to impact their lives positively.</p><p>Let me hear your thoughts below. <em>Until next time, take care! Bye Bye :)</em></p><figure><img alt="Some few principles on what it takes to building an innovation culture among product teams." src="https://cdn-images-1.medium.com/max/1024/1*2P29S_ms8QH3ScWeJmET3g.png" /><figcaption>A few principles for building innovation culture among product teams</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b73cac8107f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mpesa B2C API Integration step by step using C Sharp (C#)]]></title>
            <link>https://medium.com/@JobMasai/mpesa-b2c-api-integration-step-by-step-using-c-sharp-c-4b5a4fb8fd0e?source=rss-cbc69adf2745------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b5a4fb8fd0e</guid>
            <category><![CDATA[mpesa]]></category>
            <category><![CDATA[mpesa-integration]]></category>
            <category><![CDATA[daraja-api]]></category>
            <category><![CDATA[mpesa-api]]></category>
            <dc:creator><![CDATA[Job Masai]]></dc:creator>
            <pubDate>Sat, 14 Apr 2018 18:34:05 GMT</pubDate>
            <atom:updated>2018-04-15T21:08:12.939Z</atom:updated>
            <content:encoded><![CDATA[<p>Few months ago,we looked on how to integrate mpesa oauth api using c#.The guide looked on how to integrate mpesa oauth api as part of the api parameters required to generate token for accessing other api resources.If you did not go through the previous guide,i prefer you have a look at it here:-<a href="https://medium.com/@JobMasai/mpesa-oauth-api-integration-step-by-step-using-c-sharp-c-1201b9c480c2"> <strong><em>https://medium.com/@JobMasai/mpesa-oauth-api-integration-step-by-step-using-c-sharp-c-1201b9c480c2</em></strong></a></p><p>On this guide,we are going to look on how to integrate mpesa B2C api to help you understand how to utilize B2C api as part of your service offerings.Before integrating the api, you need to understand why you need this particular api.B2C Api enables one to move funds from one company paybill or till number to a customer registered mpesa account.</p><p>A good example is when you hear a conversation which ends with “<strong>{ — to mpesa}</strong>. This will include several words like <strong>Account to mpesa </strong>for most banks,<strong>withdraw to mpesa</strong><em> etc.</em>You can add anything on the list.All this refers to moving funds from a company paybill/till to a recipient mpesa account.Below is a small conversation between two users (John Doe and Jane Doe) to help you understand B2C.</p><p><em>John Doe:Hey Jane,i got this crazy idea of our new product.<br>Jane Doe:Ah,whats the new idea this time?.<br>John Doe:Its a new lending product we have been discussing over the last few months.<br>Jane Doe:(hmm). But the market….….<br>John Doe:No,Its going to change how people get loans over internet.<br>Jane Done.(Hmm). Well,i see .<br>John Doe:It’s going to revolutionize the lending industry…...We are going to add machine learning and artificial intelligence to disburse loans to users on our platform using mobile mobile money (silence)…and that&#39;s our secret sauce!.<br>Jane Doe:Sounds interesting!. How do we go about it?.<br>John Doe:We are going to get two paybills from safaricom to disburse loans.One for loan repayments and another for disbursements.<br>Jane Doe:Perfect deal!.Am in.<br>John Doe:Its a deal!.</em><br><em>(Two weeks later in the news)<br>*********Duo launches Nextgen lending app!. Partners with ABC Company to offer real time loans.******** (The story is on a lighter note.)</em></p><p>At this stage,i presume you have clearly identified the use case for B2C Api and C2B API.To disburse funds,you need B2C.To receive funds ,you need to have C2B API integrated on your platform.</p><p>To get started ,you need to have at-least a good mastery of the following tools/technologies:-</p><p>Visual Studio (Version of your choice,here i am using VS 2013)<br>A good understanding of C# Programming language<br>A good understanding of consuming REST api.</p><p>On your visual studio,create a new web forms project by clicking<strong> File -&gt;New Project-&gt;Visual C#-&gt;Asp.Net Web Forms Application</strong> then give it a name of your choice.</p><p>N.B.Their is no limit of the type of project you can create.You can create console,mvc app etc based on your preference as long as it can consume resource over the internet.</p><p>Once that&#39;s done,open your <strong>default.aspx.cs</strong> form which appears on your right side of your newly created project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/201/1*ETz_kdLmGYLuFJ5ixe4izw.jpeg" /></figure><p>The above screenshot represents the file we are going to work with through out the integration process.Once opened,its now time to get our hands ready for actual development.Before we write our code,we need to get the actual B2C Api endpoint we are integrating.The api endpoint can be found from the following link<a href="https://developer.safaricom.co.ke/b2c/apis/post/paymentrequest"> https://developer.safaricom.co.ke/b2c/apis/post/paymentrequest</a> .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*kVBdHbLSvVvwxmuigHBNZQ.jpeg" /></figure><p>The endpoint contains all parameters required to initiate a B2C Request from our application.Make sure you read carefully to understand the parameters and what they mean.If you don’t understand what any of each parameters mean,kindly ask questions on the the comments section below.</p><p>To get started,we need the following items:-<br><strong>OAUTH Token</strong> (This is a mandatory parameter,check my previous article on how to generate the token.)<br><strong>Initiator Name</strong> (This can be found from your developer account by following this link <a href="https://developer.safaricom.co.ke/test_credentials">https://developer.safaricom.co.ke/test_credentials</a><br><strong>Security Credential</strong> (This is also found on the following link <a href="https://developer.safaricom.co.ke/test_credentials">https://developer.safaricom.co.ke/test_credentials</a>).<br><strong>CommandID </strong>(This is necessary as you will need to specify the kind of operation you are actually attempting to do.Check it from the following link: <a href="https://developer.safaricom.co.ke/b2c/apis/post/paymentrequest">https://developer.safaricom.co.ke/b2c/apis/post/paymentrequest</a> ).</p><p>N.B.Security credential is generated by using the password provided to you on your developer password .The password provided is used to generate the security credential by pasting it on the Generate Security Credential textbox found on this link <a href="https://developer.safaricom.co.ke/test_credentials"><strong>https://developer.safaricom.co.ke/test_credentials</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g2_IXFMYAQh71gGAoNkwUQ.jpeg" /><figcaption>Test Credentials</figcaption></figure><p>The security credential is the bottom line string which we will parse as part of the request parameters when invoking the api resource.</p><p>Once we have those items ready,its now time to come back to our visual studio project we had created earlier.</p><p>On your visual studio,create a new class and give it a name MpesaRequest as shown below:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*nqy-0eX07hiLaYfe5bVGKg.jpeg" /><figcaption>Mpesa Request Class.</figcaption></figure><p>From the above class,you can see that i have decorated the properties which we will be serializing to send our request in json.From your visual studio package manager console,run this operation to install the package i.e <strong>Install-Package Newtonsoft.Json and </strong>import newtonsoft namespace in our mpesa request class by declaring the “using statement” . i.e <strong>using Newtonsoft.Json;</strong></p><p>Once that is done,we are going to create our method which will make the actual api call to safaricom b2c endpoint.For http request,i am using HttpWebRequest class.</p><p>B2C Endpoint uses <strong>Basic Authorization</strong> hence the reason we require the OAUTH token as part of our header parameters.Assumption is hereby made that you have checked my previous article on how to generate the token and that you have successfully generated the token from your developer account.</p><p>Once you have all the parameters ready with you,open your code behind section on our default.aspx.cs form and create your method as shown below:-</p><pre>private B2CResponse ProcessB2CApiRequest(MpesaRequest mpesaRequest, string b2cUrl, string token)<br> { <br> if (mpesaRequest == null)<br> {<br> return null;<br> }</pre><pre>string serializedBodyRequest = JsonConvert.SerializeObject(mpesaRequest);</pre><pre>HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(b2cUrl);</pre><pre>httpRequest.ContentType = “application/json”;</pre><pre>httpRequest.Method = “POST”;<br> httpRequest.Headers.Add(“Authorization”, “Bearer “ + token);</pre><pre>using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream()))<br> {</pre><pre>streamWriter.Write(serializedBodyRequest);<br> streamWriter.Flush();<br> streamWriter.Close();<br> }</pre><pre>try<br> {<br> HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();</pre><pre>var result = “”;<br> using (var responseStream = new StreamReader(httpResponse.GetResponseStream()))<br> {<br> result = responseStream.ReadToEnd();<br> }</pre><pre>B2CResponse b2CResponse = JsonConvert.DeserializeObject&lt;B2CResponse&gt;(result);</pre><pre>if (b2CResponse == null)<br> {<br> return null;<br> }</pre><pre> return b2CResponse;<br> }<br> catch (Exception)<br> {</pre><pre> return null;<br> }<br> }</pre><p>Once you have created the above code section,proceed to create an instance of our mpesa request class on our page load event by calling our created method as shown below:-</p><pre>         MpesaRequest mpesaRequest=new MpesaRequest();<br><br>            mpesaRequest.PartyB = &quot;{This is the test number provided on your test credentials account}&quot;;<br>            mpesaRequest.PartyA = &quot;{Also found on your test account credentials}&quot;;<br>            mpesaRequest.InitiatorName = &quot;{Also found on your test account credentials}&quot;;<br>            mpesaRequest.SecurityCredential =<br>                &quot;{Add your earlier generated security credential here}&quot;;<br>            mpesaRequest.CommandId = &quot;SalaryPayment&quot;;<br>            mpesaRequest.Amount = &quot;1000&quot;;<br>            mpesaRequest.Remarks = &quot;Testing&quot;;<br>            mpesaRequest.QueueTimeOutUrl = &quot;Your callback url where you want to receive payment response incase operation has timed out&quot;;<br>            mpesaRequest.ResultUrl = &quot;Your callback url where you want to receive your result.&quot;;<br>            mpesaRequest.Occassion = &quot;{Optional parameter}&quot;;<br><br>            string b2cUrl = &quot;https://sandbox.safaricom.co.ke/mpesa/b2c/v1/paymentrequest&quot;;<br>            string token = &quot;{This is the token you have generated from your developer test account}&quot;;</pre><p>Ensure you have internet to make the api call.The above method is the one which connects to safaricom b2c endpoint and does the processing of our request.It moves money from the paybill account we have specified (i.e Party A ) to Party B(Our intended recipient).</p><p>From your visual studio,add a <strong>breakpoint </strong>and run the default.aspx page.Once you have run it,your response should appear as below:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ysf6kXMU4jLwGhrDIm4j9g.png" /><figcaption>Mpesa B2C Response.</figcaption></figure><p>From our callback url we specified,you should receive a complete response with the details about the transaction.If you check the response,you will see the response about the transaction we processed contains a couple of details .The response posted back to our site is of type json so you will deserialize the response by creating a different class which contains all the properties as contained on the response url we specified.Below is our response as posted back from mpesa:-</p><pre>{&quot;Result&quot;:{&quot;ResultType&quot;:0,&quot;ResultCode&quot;:0,&quot;ResultDesc&quot;:&quot;The service request is processed successfully.&quot;,&quot;OriginatorConversationID&quot;:&quot;4164-2622798-2&quot;,&quot;ConversationID&quot;:&quot;AG_20180414_00007f85f308e3e3db37&quot;,&quot;TransactionID&quot;:&quot;MDE61H4CZM&quot;,&quot;ResultParameters&quot;:{&quot;ResultParameter&quot;:[{&quot;Key&quot;:&quot;TransactionReceipt&quot;,&quot;Value&quot;:&quot;MDE61H4CZM&quot;},{&quot;Key&quot;:&quot;TransactionAmount&quot;,&quot;Value&quot;:1000},{&quot;Key&quot;:&quot;B2CWorkingAccountAvailableFunds&quot;,&quot;Value&quot;:600000.00},{&quot;Key&quot;:&quot;B2CUtilityAccountAvailableFunds&quot;,&quot;Value&quot;:48967.00},{&quot;Key&quot;:&quot;TransactionCompletedDateTime&quot;,&quot;Value&quot;:&quot;14.04.2018 13:05:10&quot;},{&quot;Key&quot;:&quot;ReceiverPartyPublicName&quot;,&quot;Value&quot;:&quot;254708374149 - John Doe&quot;},{&quot;Key&quot;:&quot;B2CChargesPaidAccountAvailableFunds&quot;,&quot;Value&quot;:0.00},{&quot;Key&quot;:&quot;B2CRecipientIsRegisteredCustomer&quot;,&quot;Value&quot;:&quot;Y&quot;}]},&quot;ReferenceData&quot;:{&quot;ReferenceItem&quot;:{&quot;Key&quot;:&quot;QueueTimeoutURL&quot;,&quot;Value&quot;:&quot;https:\/\/<a href="http://internalsandbox.safaricom.co.ke/">internalsandbox.safaricom.co.ke</a>\/mpesa\/b2cresults\/v1\/submit&quot;}}}}</pre><p>As shown on the above response,our transaction was successfully processed.On live environment,this would have meant that we were able to process the request and our recipient received funds on his mpesa account.</p><p>After getting the above response,you need to deserialize the full response so that you can get the actual values and save the details on your database.</p><p>The response from mpesa is not guaranteed to be successful always based on many cases.In case your request failed,you will receive a different response which contains a description of why the request could not be processed for further analysis.Ensure that your logic caters for all scenarios to ensure you don&#39;t mark transactions as processed without actually receiving the final result on your callback url.</p><p>Up-to this far ,we have accomplished our mission of integrating B2C API on our application.Good luck as you integrate the api.</p><p>Happy coding.Our next section will cover <strong>B2B &amp;C2B Api Integration</strong></p><p>For technical support or any other inquiries,feel free to leave a comment below or reach via <a href="/service/mailto:integrations001@gmail.com"><strong><em>integrations001@gmail.com</em></strong></a></p><p><em>Merci</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b5a4fb8fd0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mpesa OAUTH API Integration Step by step using C Sharp (C#)]]></title>
            <link>https://medium.com/@JobMasai/mpesa-oauth-api-integration-step-by-step-using-c-sharp-c-1201b9c480c2?source=rss-cbc69adf2745------2</link>
            <guid isPermaLink="false">https://medium.com/p/1201b9c480c2</guid>
            <category><![CDATA[mpesa-daraja-api]]></category>
            <category><![CDATA[mpesa-api]]></category>
            <category><![CDATA[safaricom]]></category>
            <category><![CDATA[mpesa-integration]]></category>
            <category><![CDATA[mpesa-tutorial]]></category>
            <dc:creator><![CDATA[Job Masai]]></dc:creator>
            <pubDate>Sun, 05 Nov 2017 17:19:17 GMT</pubDate>
            <atom:updated>2018-06-30T10:39:04.356Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently,one of the largest Mobile Money operators in Kenya i.e Safaricom, released a faster and a simpler REST api (<a href="http://developer.safaricom.co.ke/"><strong>http://developer.safaricom.co.ke/</strong></a>) which users can quickly plug it on their applications reducing the integration nightmares which had been experienced by many partners over the past few months.</p><p>This process is now streamlined and developers/partners are now able to integrate their applications with just few setups on their applications.More possibilities exist for the new api and <em>only sky is the limit </em>on what you can achieve with the new api.</p><p>This first guide starts with the <strong>OAUTH API(</strong><a href="https://developer.safaricom.co.ke/oauth/apis/get/generate-1">https://developer.safaricom.co.ke/oauth/apis/get/generate-1)</a><strong> </strong>which as a developer you are required to generate a token which is required as part of the HTTP Header when making an API Request to other subsequent API Resources i.e B2C,B2B etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*R6IpDVTRMuFXSZqnHJF76g.jpeg" /><figcaption>OAUTH API Dash Board</figcaption></figure><p>To get started with the OAUTH API,i am using the following tools and technologies:-<br> <strong>1.Visual Studio 2013</strong><br>2.<strong>A good understanding of C#<br>3.Rest Sharp (Rest Sharp is a </strong>Simple REST and HTTP API Client for .NET which we will use to send our api request to the provided safaricom oauth endpoint.More is found on the following link: <a href="http://restsharp.org/">http://restsharp.org/</a>)<br>N.B.You can use any of your preferred method for making http request.</p><p>As part of your HTTP Request,the token you generate is valid for <strong>a period of one hour</strong>.This means that you can save the token generated in a data store somewhere where you can use it on your application .</p><p><strong>OAUTH ENDPOINT URL :</strong></p><p><a href="https://sandbox.safaricom.co.ke/oauth/v1/generate">https://sandbox.safaricom.co.ke/oauth/v1/generate</a></p><p>To get started,click visual studio and select <strong>New Project.</strong>Once you click on the New Project link,a window opens up which shows you several projects you can create.For our case,we are going to create a <strong>c# console application.</strong>On the “<strong>Templates</strong>” menu section,select <strong>“Visual C#”. </strong>On your right side,select <strong>Console Application </strong>and give it a name of your choice and click okay.</p><p>Once this is done,your project files are created and you can now get started on your development.On your newly created project,select the <strong>Program.cs</strong> file which is where we will be doing our development.</p><h3><strong>Points to note:</strong></h3><p>To prepare the token generation process,you are required to get the following from your Safaricom developer portal:-<br><strong>1.Consumer Key<br>2.Consumer Secret.<br></strong>The above two credentials will be used as part of our http header values for Basic Authorization.This means you are required to add them as part of your header request every time you are making an api call to safaricom endpoints.<br>From your developer account found here <strong>(</strong><a href="https://developer.safaricom.co.ke/user/me/apps">https://developer.safaricom.co.ke/user/me/apps</a><strong>),</strong>ensure you have an <strong>already created and approved application</strong>.If you don&#39;t have it already created,kindly create it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vXFOmK8sL-C5xNN0mL0Q1A.jpeg" /></figure><p>Once its created and approved,click on your newly created application.Upon clicking the application from your account,you will see couple of options as shown below.</p><ul><li><strong>Keys</strong></li><li><strong>Products</strong></li><li><a href="https://developer.safaricom.co.ke/user/me/apps#details0"><strong>Details</strong></a></li><li><a href="https://developer.safaricom.co.ke/user/330/app-detail/990f8f3c-64ed-4171-9247-28ce6fd299c2"><strong>Analytics</strong></a></li><li><a href="https://developer.safaricom.co.ke/user/330/apps/990f8f3c-64ed-4171-9247-28ce6fd299c2/edit-app"><strong>Edit “<em>{your created application name}</em>”</strong></a></li><li><a href="https://developer.safaricom.co.ke/user/330/apps/990f8f3c-64ed-4171-9247-28ce6fd299c2/delete"><strong>Delete “{your created application name}”</strong></a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*UQ6ZW-brkfp_i2HEbl7Wdg.jpeg" /><figcaption>App Keys</figcaption></figure><p>Our main interest is the “<strong>KEYS</strong>” option.Here you will see your application keys,both consumer key and consumer secret.Copy them somewhere as we will be using them on our application.Once all this is done,lets head back to our <strong>C# console application </strong>we created earlier.</p><p>Few things to note concerning the information provided above:-<br><em>1)We have managed to get our application consumer keys.<br>2)We have our OAUTH Api which we will be using to generate our token.<br>3)We have managed to set up a console application which we will develop our small application.<br>4)We have a brief understanding of Rest Sharp.If you have not checked it,i recommend first you check</em><strong><em> rest sharp on how make HTTP POST and HTTP GET</em></strong><em> online .</em></p><p>Once all this is done,lets get back to our visual studio application we created earlier.First thing is to install Rest Sharp on our application.From your visual studio application ,right click your <strong>project name</strong> and select<strong> Manage Nugget Packages.</strong>A window will open and from the left portion,select <strong>online option</strong>.Far right from the selected option,their is an option which reads <strong>“search online”. </strong>From the search option,enter the name <strong>“</strong>Restsharp” and the package name will be shown on your open window.Select “<strong>Install” </strong>Option and wait as Rest Sharp installs on your application.Once done, click okay and now we can see our newly installed package.To check if it has been installed,expand the references section of your solution and see if the package is listed as part of references.</p><p>After installing the package,its now the time to do our first development.On your Program.cs file,create a static method which we will call on our main method.<br>Give it a name of your choice and assign a return type of type string.I have already created my method as shown below:<em>-</em></p><pre>static string GenerateSafaricomToken(string consumerKey,string consumerSecret,string grantType)<br> <br>{</pre><pre>string token = string.Empty;<br> //demo purposes only<br> return token;<br> <br>}</pre><p>As you can see above,our method contains parameters which we will parse when sending request to the oauth api end point.Since we have our ready installed package restsharp on our application,we need to import its namespace on our program by importing the namespace like “using RestSharp;” .</p><p>After importing the namespace,we are now able to use the access the classes which have been referenced on restsharp package.On our method which we have created above,create a new instance of RestClient as shown below:</p><pre>RestClient restClient = new RestClient<br> {<br> BaseUrl = new Uri(“<a href="https://sandbox.safaricom.co.ke/">https://sandbox.safaricom.co.ke</a>&quot;),<br> Authenticator = new HttpBasicAuthenticator(consumerKey, consumerSecret)<br> };</pre><p>The authenticator has several ways to send authorization request but for safaricom we are required to send <strong><em>Basic Header Authorization.</em></strong></p><p>The next part is to construct our request body to add the http web request method we are going to use i.e GET request and also give it the actual api method for generating the token.i.e “<strong>/oauth/v1/generate” </strong>which will act as our resource url .For this ,create a new instance of RestRequest which is found in the RestSharp Package.<strong><br></strong>Below code shows how to do that using RestSharp:-</p><pre>RestRequest request = new RestRequest(“/oauth/v1/generate”, Method.GET);Below code shows how to do that using RestSharp:-<br></pre><p>Next part is to add our request parameters as required in the api documentation on safaricom developer portal as shown in the link below:-<br>(“<a href="https://developer.safaricom.co.ke/oauth/apis/get/generate-1">https://developer.safaricom.co.ke/oauth/apis/get/generate-1</a>”)</p><p>Our rest client already has this option already included on the RestRequest object above.For this we need to use the method which is found in our request object which we will add our request parameters.The following code below show us how to add the request parameters as part of our api call.</p><pre>request.AddParameter(“grant_type”, “client_credentials”, ParameterType.QueryString);<strong><em><br></em></strong><em>NB.The AddParameter is found on our rest request object we created above.</em></pre><p>Once done,the next part is our final section where we pass our object to make the api call over the internet.(<em>You need to have internet as part of this guide :)-</em>).</p><p>This is the section we compose everything and we send our request to the token generator api .This method is found on our RestClient object we created initially i.e</p><pre>RestClient restClient = new RestClient<br> {<br> BaseUrl = new Uri(“<a href="https://sandbox.safaricom.co.ke/">https://sandbox.safaricom.co.ke</a>&quot;),<br> Authenticator = new HttpBasicAuthenticator(consumerKey, consumerSecret)<br> };</pre><p>The object has a method called “Execute” which accepts an object of type <strong>RestRequest which we created earlier.i.e</strong></p><blockquote>RestRequest request = new RestRequest(“/oauth/v1/generate”, Method.GET);</blockquote><p>Below is our line of code which makes the final api request with the provided methods above:-</p><blockquote><strong>IRestResponse restResponse = restClient.Execute(request);</strong></blockquote><p>Few things to note,the above method accepts our rest request parameter which contains the method to invoke and also the http method request type .ie Get.The rest of authentication details and base url are bundled on our rest client object.The method above also returns a response of type “<strong>IRestResponse” which acts as a container of the data send back from the api.</strong></p><p>Once that is done,we can check the kind of response generated by using the restResponse object above.The content message is available by checking the “r<strong>estResponse.Content</strong>” method .This will contain the response which has been generated back by safaricom endpoint if all goes well on our API call process.The string which is returned contains a json content which you can deserialize to get the values and save them on your data store.</p><p>The code below shows how to read back the response returned back from safaricom api:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*jXPa8mVp1VogpcEca6jZaQ.jpeg" /><figcaption>Api Response</figcaption></figure><pre>if (restResponse != null)<br> {<br> token = restResponse.Content;<br> }<br> return string.Empty;</pre><p>On the above code,we are checking if our response object is null before processing the response.If its not null,we proceed to get the actual content which was returned back to us.<br>If the api request was successful,you will get the following response as token from the content method which was send back to us:_</p><pre>{<br>  &quot;access_token&quot;: &quot;hPHtU6TVSg9EP74AtMStXNWTnMgt&quot;,<br>  &quot;expires_in&quot;: &quot;3599&quot;<br>}<strong><br>Nb:The token generated changes after every hour and above is a sample of how the token was generated during the demo.</strong><em>The token has been modified for security issues.</em></pre><p>In case of wrong credentials,you will get the following response:-</p><pre>{<br>  &quot;requestId&quot;: &quot;21604-273291-1&quot;,<br>  &quot;errorCode&quot;: &quot;400.008.01&quot;,<br>  &quot;errorMessage&quot;: &quot;Invalid Authentication passed&quot;<br>}</pre><p>After all said and done,this is the full method which we have created above:-</p><pre>RestClient restClient = new RestClient<br>            {<br>                Authenticator = new HttpBasicAuthenticator(consumerKey, consumerKey),<br>                BaseUrl = new Uri(&quot;https://sandbox.safaricom.co.ke&quot;),<br><br><br>            };<br><br>            RestRequest request = new RestRequest(&quot;/oauth/v1/generate&quot;, Method.GET);<br><br>            request.AddParameter(&quot;grant_type&quot;, &quot;client_credentials&quot;, ParameterType.QueryString);<br><br><br>            IRestResponse restResponse = restClient.Execute(request);<br><br><br>            if (restResponse != null &amp;&amp; !string.IsNullOrEmpty(restResponse.Content))<br>            {<br><br><br>                return restResponse.Content;<br><br>            }<br><br>            return string.Empty;</pre><blockquote>After getting your response,you can create now a class which contains the two properties for a successful response i.e</blockquote><pre>public class TokenResponse<br> {<br> [JsonProperty(“access_token”)]<br> public string AccessCode { get; set; }<br> [JsonProperty(“expires_in”)]<br> public int ExpiryDate { get; set; }<br> }</pre><p>You can deserialize the token response by using any of your preferred method of deserialization.For my end am using NewtonSoft package(“<a href="https://www.newtonsoft.com/json">https://www.newtonsoft.com/json</a>”) to deserialize my response received.If the request was successful,your deserialized object will contain the values received from the api .If it doesn’t return a response,you can know definitely the api returned an error and you can check your response.content and see the kind of message which was received.</p><p>Below is a sample of how i have deserialized my response :-</p><pre>TokenResponse tokenResponse = JsonConvert.DeserializeObject&lt;TokenResponse&gt;(restResponse.Content);</pre><p>If all is successful,i can be sure that my “<strong>tokenResponse</strong>” will not be null and i can go ahead and save the token in my data store.</p><p>Next part we will cover B2B,B2C and C2B Integration.</p><p>For technical support or any other inquiries,feel free to leave a comment below or reach via <a href="/service/mailto:integrations001@gmail.com"><strong><em>integrations001@gmail.com</em></strong></a></p><p>Happy Coding…..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1201b9c480c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>