2

I am using this call in AMPScript To retrieve: https://www.exacttargetapis.com/data/v1/customobjectdata/key/[Data extension key]?$filter= Name%20eq%20'Test'

To insert: https://www.exacttargetapis.com/hub/v1/dataevents/key:[Data extension key]/rowset

Body:
  [{ 
   "keys":{
          "FA_Response_ID": "1234567"
          },
    "values":{
    "Email":"[email protected]"
     "Subscriber_Key":"[email protected]",
      "TS_Status_Message":"NEW_MSG" 
          }
     }]

both calls are working in POSTMAN but not in AMPScript Getting error while insert call "JSON Deserialization Exception: Location Unknown"

2
  • 1
    You could add your non working AMPScript (without customer values etc). This would help us to figure out what is wrong in your ampscript Apr 10, 2019 at 5:40
  • @Vasudha You should make sure your using the same account which you asked the question under to make edits to it. Otherwise 2+ people need to approve your edits. See Merging Accounts Apr 10, 2019 at 13:38

1 Answer 1

1

I don't believe it's possible to include your access token with AMPscript's HTTPGet when requesting the GET route to retrieve DE rows (i.e., you'll need to momentarily step into SSJS), but here's one approach...

External Key: xyz789
┌───────────────┬──────┐
│ EmailAddress  │ User │
├───────────────┼──────┤
│ [email protected]   │ foo  │
├───────────────┼──────┤
│ [email protected] │ qux  │
└───────────────┴──────┘

...

%%[
set @creds =
'{
  "clientId": "abc123",
  "clientSecret": "456def"
}'
set @reqTokenStatus = HTTPPost(
  'https://auth.exacttargetapis.com/v1/requestToken',
  'application/json',
  @creds,
  @reqTokenResponse
)
set @accessToken = RegExMatch(
  @reqTokenResponse,
  '"accessToken"\s*?:\s*?"(.+?)"',
  1,
  'None'
)



if (@reqTokenStatus == 200) and (Length(@accessToken) > 0) then
  set @dataExtKey = 'xyz789'
  set @payload =
'[
  {
    "keys": {
      "EmailAddress": "[email protected]"
    },
    "values": {
      "User": "foo"
    }
  },
  {
    "keys": {
      "EmailAddress": "[email protected]"
    },
    "values": {
      "User": "qux"
    }
  }
]'

  set @reqInsertRowsStatus = HTTPPost(
    Concat('https://www.exacttargetapis.com/hub/v1/dataevents/key:', @dataExtKey, '/rowset'),
    'application/json',
    @payload,
    @reqInsertRowsResponse,
    'Authorization', Concat('Bearer ', @accessToken)
  )

  if (@reqInsertRowsStatus == 200) then
    Output(Concat('Rows inserted:<br>', @reqInsertRowsResponse, '<br><br>'))

    set @retrieveRowsFilter = Concat('$filter=', URLEncode("User eq 'Foo'", 0, 1))
    set @retrieveRowsRoute = Concat('https://www.exacttargetapis.com/data/v1/customobjectdata/key/', @dataExtKey, '/rowset/?', @retrieveRowsFilter)
    set @reqRetriveRowsResponse = ''
]%%
<script runat="server">
Platform.Load('Core', '1');
var accessToken = Variable.GetValue('@accessToken');
var retrieveRowsRoute = Variable.GetValue('@retrieveRowsRoute');
var headerNames = ['Authorization'];
var headerValues = [('Bearer ' + accessToken)];
var reqRetriveRowsResponse = HTTP.Get(retrieveRowsRoute, headerNames, headerValues);
Variable.SetValue('@reqRetriveRowsResponse', reqRetriveRowsResponse.Content);
</script>
%%[
    Output(Concat('Rows retrieved:<br>', @reqRetriveRowsResponse))
  endif

/* unable to complete request */

endif
]%%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .