my REST python example :
from urllib2 import HTTPError,URLError
import simplejson as json
import urllib2
REQUEST_STRING = json.dumps({ 'AdGroupIds': [775710747]})
def main():
try:
baseUri = 'https://adcenterapi.microsoft.com/Api/Advertiser/v8/CampaignManagement/CampaignManagementServiceREST.svc'
uriTemplate = '/customer/account/campaign/140039046/adGroup?$field=negativeKeywords'
formatString = '&format=json'
uri = baseUri + uriTemplate + formatString
print(uri);
print("
request
" + REQUEST_STRING);
encodedRequest = REQUEST_STRING.encode()
# Load the header values for the POST
headers = {"Content-Type": "application/json",
"Content-Length": str(len(encodedRequest)),
"CustomerAccountId": "XXXX",
"DeveloperToken" : 'XXXXXX',
"UserName" : "XXXXXX",
"Password" : "XXXXX"}
request = urllib2.Request(uri, encodedRequest, headers)
# Call the service operation and process the response. If
# the request generates a fault, urlopen raises a HTTPError
# exception that is caught below.
response = urllib2.urlopen(request)
# Get the JSON response text
body = response.read()
print("
response
" + body.decode("utf8"))
# Raised if the request fails or generates a fault. An INTERNAL_SERVER_ERROR
# error indicates a fault. HTTP error code 400 indicates that the message is
# malformed or contains invalid data.
except HTTPError , error:
print("
HTTP Error Code: " + str(error.code))
print("
fault
" + error.read().decode("utf8"))
except URLError , e:
print(e)
# Starts the main loop.
main()