I have this code to get a list of items from shopee affiliate program. The code is quite straight forward.
import requests
import time
import hashlib
appID = APP_ID
secret = SECRET
# Set the API endpoint URL
url = "https://open-api.affiliate.shopee.com.my/graphql"
# Set the GraphQL query
body = """
{
productOfferV2(
listType:0
sortType:5
) {
nodes {
commissionRate
commission
price
productLink
offerLink
}
}
}
"""
payload = {"query": body}
timestamp = str(int(time.time()))
factor = f'{appID}{timestamp}{payload}{secret}'
signature = hashlib.sha256(factor.encode()).hexdigest()
print(factor)
# Set the request headers
headers = {
'Content-type':'application/json',
'Authorization':f'SHA256 Credential={appID},Timestamp={timestamp},Signature={signature}'
}
# Send the POST request
response = requests.post(url, json=payload, headers=headers)
# Print the response
print(response.json())
after run I get this error
{'errors': [{'message': 'error [10020]: Invalid Signature', 'extensions': {'code': 10020, 'message': 'Invalid Signature'}}]}
I follow this:
https://ibb.co/q9JRB7h https://ibb.co/th99m4F
I already check the credential
and timestamp
is correct. The only thing left is the signature
part.
I figured it out. The documentation might be lack of info but this is how i construct my payload
I hope this answer will help someone that facing the same issue