Re: Merchant measurement API error when sending request

alaneng
Helper

Merchant measurement API error when sending request

Hi, I'm walking through the sample Python code for the Merchant Measurement API and ran across this error:

Exception when calling MerchantBenchmarkApi->postmerchant_benchmark: Object of type 'MerchantBenchmarkpostPayload' is not JSON serializable

 

Here's my truncated code:

 

merchant_benchmarkpost_payload = src.MerchantBenchmarkpostPayload(
request_data={
"naicsCodeList": [""],

"merchantCategoryCodeList": ["5812"],

...

 

api_response = api_instance.postmerchant_benchmark(merchant_benchmarkpost_payload)

 

The last line of code above produced the error.

 

Any tips? Thanks!

11 REPLIES 11
API_Products
Visa Developer Support Specialist

Re: Merchant measurement API error when sending request

Hi @alaneng,

 

To further investigate please submit an email to developer@visa.com and reference this forum post because additional information is needed from you for further assistance.

 

Please provide the following information in your email:

1. End Point
2. Request Header
3. Request Body
4. Response Header (include the x-correlation-id)
5. Response Body

Using SoapUI, you can find the x-correlation-id in the Raw Tab of the response header.

 

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

alaneng
Helper

Re: Merchant measurement API error when sending request

Thanks, I sent an email answering questions 1-3 but I was not able to get a response so questions 4 and 5 are unanswerable. To be clear, I am simply running the sample Python code provided by the merchant measuring API, I'm not doing anything new. Thanks for any help!
API_Products
Visa Developer Support Specialist

Re: Merchant measurement API error when sending request

Hi @alaneng,

 

An update is needed for the Python sample code which is causing the error. We are currently working to update the code. I will provide you with an update once I receive one.

 

                             




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

API_Products
Visa Developer Support Specialist

Re: Merchant measurement API error when sending request

Hi @alaneng,

 

Merchant benchmark API is working as expected on sandbox. Please find the following request response.

 

{
"requestHeader": {
"messageDateTime": "2019-05-16T22:20:17.327Z",
"requestMessageId": "6da60e1b8b024532a2e0eacb1af58581",
"businessApplicationId":""
},
"requestData": {
"naicsCodeList": [""],
"merchantCategoryCodeList": ["5812"],
"merchantCategoryGroupsCodeList": [""],
"postalCodeList": [""],
"msaList": ["7362"],
"countrySubdivisionList": [""],
"merchantCountry": "840",
"monthList": ["201706"],
"accountFundingSourceList": ["ALl"],
"eciIndicatorList": ["All"],
"platformIDList": ["All"],
"posEntryModeList": ["All"],
"cardPresentIndicator": "CARDPRESENT",
"groupList": ["STANDARD"]
}
}


Response:
{
"responseHeader": {
"requestMessageId": "6da60e1b8b024532a2e0eacb1af58581",
"messageDateTime": "2019-05-28 08:16:31.517",
"responseMessageId": "MRCHBMARK_067905a3-fe9d-43fc-8d35-c19660b94815",
"numRecordsReturned": 1
},
"responseStatus": {
"statusDescription": "Merchant Benchmark - Success",
"status": "CDI000"
},
"requestData": {
"cardPresentIndicator": "CARDPRESENT",
"merchantCountry": "840",
"groupList": ["STANDARD"],
"merchantCategoryCodeList": ["5812"],
"merchantCategoryGroupsCodeList": [""],
"monthList": ["201706"],
"msaList": ["7362"],
"postalCodeList": [""],
"naicsCodeList": [""],
"countrySubdivisionList": [""],
"accountFundingSourceList": ["ALl"],
"eciIndicatorList": ["All"],
"platformIDList": ["All"],
"posEntryModeList": ["All"]
},
"response": {"responseData": [ {
"salesTranCntGrowthMoM": "-3.3139",
"salesVolumeGrowthMoM": "-4.9995",
"salesTranCntGrowthYoY": "13.809",
"salesVolumeGrowthYoY": "15.0983",
"groupName": "standard",
"fraudChbktoSalesGrowthYoY": "-28.0456",
"nonfraudChbktoSalesGrowthYoY": "36.5908",
"fraudChbktoSalesRatio": "0.4564",
"nonfraudChbktoSalesRatio": "0.209",
"ticketGrowthMoM": "-0.0174",
"ticketGrowthYoY": "0.0113"
}]}
}

 

Please try request with necessary field and field names.

 

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

API_Products
Visa Developer Support Specialist

Re: Merchant measurement API error when sending request

Hi @alaneng,

 

Here's Python Sample Code for API Key Two-Way (Mutual) SSL for Hello World. Hope this helps!

 

# -*- coding: utf-8 -*-
# !/usr/bin/python

# https://www.programcreek.com/python/example/98764/urllib3.ProxyManager

__author__ = 'visa'

import requests
import logging
import unittest
import os
import json

import myproxy

#DEBUG = True
DEBUG = False

proxy_url = os.environ.get('HTTPS_PROXY', os.environ.get('HTTP_PROXY'))
print (proxy_url)
print ("###########")
'''
@author: visa
Sample Code for API Key � Two-Way (Mutual) SSL
https://developer.visa.com/vdpguide#get-started-overview
'''

try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1

# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

print ("START Sample Code for Two-Way (Mutual) SSL")

url = 'https://sandbox.api.visa.com/vdp/helloworld'
headers = ''
user_id = '0JT3K3STFUO9GIMN94PJ212VehNTAnNgZ2Wh_y7fSZKDHThM0'
password = 'MPCoTBdXRClfQZ1LdHc0QsetxL1'

client_certificate_pem_file_path = 'C:/Jiri/MISC/VISA/certs/mycerts/cert.pem'
key_pem_file_path = 'C:/Jiri/MISC/VISA/certs/mycerts/key_83d11ea6-a22d-4e52-b310-e0558816727d.pem'

try:
response = requests.get(url,
cert = (client_certificate_pem_file_path, key_pem_file_path),
headers = headers,
auth = (user_id, password)
)
except Exception as e:
print str(e)

if DEBUG: print (response.headers)
if DEBUG: print (response.content)

var1 = str(response.status_code)
var2 = '200'
msg = " Two-Way (Mutual) SSL test failed"
assert var1 == var2, msg

print ("END Sample Code for Two-Way (Mutual) SSL\n\n")

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

API_Products
Visa Developer Support Specialist

Re: Merchant measurement API error when sending request

Hi @alaneng,

 

Here's the Python Sample Code for Shared Secret (X-Pay-Token) for Hello World. Hope this helps!

 

Hello World

import myproxy
outside client has to comment it out

 

# -*- coding: utf-8 -*-
# !/usr/bin/python

import requests
import logging
from calendar import timegm
from datetime import datetime
from hashlib import sha256
import hmac
import sys
import unittest
import os

#import myproxy

#DEBUG = True
DEBUG = False

'''
@author: visa
Sample Code for API Key – Shared Secret (X-Pay-Token)
https://developer.visa.com/vdpguide#get-started-overview
'''

try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1

# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True


def _get_x_pay_token(shared_secret, resource_path, query_string, body):
timestamp = str(timegm(datetime.utcnow().timetuple()))
pre_hash_string = timestamp + resource_path + query_string + body
if sys.version_info < (3, 0):
hash_string = hmac.new(shared_secret,
msg=pre_hash_string,
digestmod=sha256).hexdigest()
else:
hash_string = hmac.new(str.encode(shared_secret), msg=pre_hash_string.rstrip().encode('utf-8'), digestmod=sha256).hexdigest()
return 'xv2:' + timestamp + ':' + hash_string

APIKey = 'R7J8E1IPIB33F0LC580V21RIYItEJO5zO3Zv3_FD6PqkqDF7Q'
shared_secret = '0OgIy-{e9vw-zJ1GuGTZzfb{GjwzUnjBD7PIJL/h'

query_string = "apikey="+APIKey
resource_path = 'helloworld'
body = '' # payload

print ("START API Key – Shared Secret (X-Pay-Token)")

x_pay_token = _get_x_pay_token (shared_secret, resource_path, query_string, body)
print ("x_pay_token = ", x_pay_token)

url = 'https://sandbox.api.visa.com/vdp/helloworld?apikey=' + APIKey
header = {"x-pay-token": x_pay_token}

try:
response = requests.get(url, headers=header)

except Exception as e:
print str(e)

if DEBUG: print (response.headers)
if DEBUG: print (response.content)

var1 = str(response.status_code)
var2 = '200'
msg = "X-Pay-Token test failed"
assert var1 == var2, msg

print ("END API Key – Shared Secret (X-Pay-Token)")

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

API_Products
Visa Developer Support Specialist

Re: Merchant measurement API error when sending request

Hi @alaneng,

 

After further review of the VDP Python Sample Code it appears that it is working fine. It looks like you are not passing the payload properly in src.MerchantBenchmarkpostPayload() and that there is something that is incorrect with the truncated code.

 

Can you please take a look at the test cases? It should help you to understand the right way to invoke the API.

 

Test file path: /merchant_measurement/merchant_benchmark_api/test/test_merchant_benchmark_api.py
Below you will also see the screenshot result of the test cases for the above code.

20190621 test_merchant_benchmark_api.py successful results.jpg

 

You can also download the Python Sample Code from the VDP website, if you login to your VDP account and go to “My Account” > “Dashboard” > select Project > “Sample Code” > “Download Python Code” (screenshot example provided below, if needed). This is where I got the Merchant Measurement Python Sample Code that I’ve attached to this forum post for you to conveniently access, as well.

20190621 Merchant Measurement Download Python Sample Code.jpg

 

Can you also please share any test results with us, I'd like to continue to help you out if you run into any issues along the way. Thanks!

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

API_Products
Visa Developer Support Specialist

Re: Merchant measurement API error when sending request

Hi @alaneng,

 

Can you please let me know if you're still experiencing an issue with the Python Sample Code? If so, I'd be happy to work with you and help you out.

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

API_Products
Visa Developer Support Specialist

Re: Merchant measurement API error when sending request

Hi @alaneng,

 

I haven 't heard back from you, so I'll close this query out on my end. Please do not hesitate to reach out to us if you need further assistance or have other questions.

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.