0

Im trying to write an apex code for a post request while using the below data this is basically for creating a room in chat tool

curl -X PUT -H 'X-ChatWorkToken: Your API token' -d
'description=group+chat+description&icon_preset=meeting&name=Website+renewal+project'
'https://api.chatwork.com/v2/rooms/{room_id)


code until now

public class groupcreate {
    public static HttpResponse makePostCallout() {
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://api.chatwork.com/v2/rooms/{5678)';
        request.setMethod('POST');
        HttpResponse response = http.send(request);
        return response;
    }        
}

need some guidance regarding this.

0

1 Answer 1

2

-H is a header to send, -d is the data to send, -X is the method to use. So:

public class groupcreate {
    public static HttpResponse makePostCallout() {
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://api.chatwork.com/v2/rooms/5678';
        request.setHeader('X-ChatWorkToken','Your API token');
        request.setBody('description=group+chat+description&icon_preset=meeting&name=Website+renewal+project');
        request.setMethod('PUT');
        HttpResponse response = http.send(request);
        return response;
    }        
}

Note: based on the documentation, I'm fairly certain the {} do not belong in the URL.

5
  • Thank you for the reply the program is executing but the result Im looking for is not successful yet i.e creating a room in chatworks is there any problem in the code?
    – Tejas
    Commented Mar 16, 2021 at 5:32
  • @Tejas To create, It looks like you need POST and https://api.chatwork.com/v2/rooms instead of a chat room ID (you don't have an ID yet, because the room is not yet created). See documentation
    – sfdcfox
    Commented Mar 16, 2021 at 11:34
  • yes i tried that but then too it doesn't seem to work. Im working on API for first time that's why I'm asking - only writing this code in a execution window and running the code will de the job or something else is also required?
    – Tejas
    Commented Mar 17, 2021 at 5:01
  • @Tejas In general, yes, that should work. You may need to contact their support directly if you're not able to figure it out.
    – sfdcfox
    Commented Mar 17, 2021 at 10:36
  • tried various things but not working yet....i will try and contact them if not working
    – Tejas
    Commented Mar 18, 2021 at 7:26

You must log in to answer this question.

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