How to give date and time values in request body using postman

  • I have Created a Request Body in Event Object with Date and Time Details, how to give the Date and Time Values in JSON format using Postman

    { 
        "Type":"contact call",
        "WhoId":"0038E00000GWXhL",
        "Subject":"contact call created by api",
        "DurationInMinutes":"45",
        **"ActivityDateTime":  "\/Date(13082015)\/"**
    }
    

    How to Give the Activity Date time in Request body,

    can anyone guide me for the answer?

    Have you tried a standard format like ```'mm/dd/yyyy'``` ?

  • Use Pre-request script tab to save the date into a variable:

    var current_timestamp = new Date();
    postman.setEnvironmentVariable("current_timestamp", current_timestamp.toISOString());
    

    and then use it in the request body as follows:

    "ActivityDateTime": "{{current_timestamp}}"
    
  • I tried this in the workbench. It successfully created an event record. I suspect salesforce is expecting a date in a standard format instead of the date(value) format.

    { 
        "Type":"contact call",
        "WhoId":"0032a000005oqGO",
        "Subject":"contact call created by api",
        "DurationInMinutes":"45",
        "ActivityDateTime":"2018-03-29"
    }
    

    If you need to use the time along with the date, the following works as well.

    { 
        "Type":"contact call",
        "WhoId":"0032a000005oqGO",
        "Subject":"contact call created by api",
        "DurationInMinutes":"45",
        "ActivityDateTime":"2018-03-29T13:34:00.000"
    }
    
  • Just add the built-in dynamic variable {{$timestamp}} in the request body such that, the request body would look like;

    { 
      "Type":"contact call",
      "WhoId":"0032a000005oqGO",
      "Subject":"contact call created by api",
      "DurationInMinutes":"45",
      "ActivityDateTime":"{{$timestamp}}"
    }
    

    Now the request will send with the current time (exact request time) as an epoch in seconds.

    Note: If you want to convert the epoch in seconds to the current time, add three 0s at the end so as to convert it into milliseconds. There are websites to convert time into epoch and vice versa

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM