I keep getting this error every time I try to make an STK push
"requestId" => "6255-20728117-1" "errorCode" => "400.008.02" "errorMessage" => "Invalid grant type passed"
Check the url you are using and add the grant_type and ensure that the grant_type is associated with a customer_key as well as a customer_secret in the final post request e.g curl -X GET https://sandbox.safaricom.co.ke/oaut/v1/generate?grant_type=client_credentials As opposed to: curl -X GET https://sandbox.safaricom.co.ke/oauth/v1/generate
sample code snippet is as follows
consumer_key = keys.consumer_key
consumer_secret =keys.consumer_secret
api_URL = (
"https://sandbox.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials"
)
r = requests.get(api_URL, auth=HTTPBasicAuth(consumer_key, consumer_secret))
print(r.text)
You have to provide a grant_type
in your request. Check the Mpesa Api Documentation.